For PR950:
This patch converts the old SHR instruction into two instructions,
AShr (Arithmetic) and LShr (Logical). The Shr instructions now are not
dependent on the sign of their operands.

llvm-svn: 31542
diff --git a/llvm/lib/VMCore/Constants.cpp b/llvm/lib/VMCore/Constants.cpp
index bcfd387..ee855ca 100644
--- a/llvm/lib/VMCore/Constants.cpp
+++ b/llvm/lib/VMCore/Constants.cpp
@@ -498,20 +498,11 @@
 Constant *ConstantExpr::getShl(Constant *C1, Constant *C2) {
   return get(Instruction::Shl, C1, C2);
 }
-Constant *ConstantExpr::getShr(Constant *C1, Constant *C2) {
-  return get(Instruction::Shr, C1, C2);
+Constant *ConstantExpr::getLShr(Constant *C1, Constant *C2) {
+  return get(Instruction::LShr, C1, C2);
 }
-
-Constant *ConstantExpr::getUShr(Constant *C1, Constant *C2) {
-  if (C1->getType()->isUnsigned()) return getShr(C1, C2);
-  return getCast(getShr(getCast(C1,
-                    C1->getType()->getUnsignedVersion()), C2), C1->getType());
-}
-
-Constant *ConstantExpr::getSShr(Constant *C1, Constant *C2) {
-  if (C1->getType()->isSigned()) return getShr(C1, C2);
-  return getCast(getShr(getCast(C1,
-                        C1->getType()->getSignedVersion()), C2), C1->getType());
+Constant *ConstantExpr::getAShr(Constant *C1, Constant *C2) {
+  return get(Instruction::AShr, C1, C2);
 }
 
 /// getWithOperandReplaced - Return a constant expression identical to this
@@ -1330,7 +1321,9 @@
         return new UnaryConstantExpr(Instruction::Cast, V.second[0], Ty);
       if ((V.first >= Instruction::BinaryOpsBegin &&
            V.first < Instruction::BinaryOpsEnd) ||
-          V.first == Instruction::Shl || V.first == Instruction::Shr)
+          V.first == Instruction::Shl           || 
+          V.first == Instruction::LShr          ||
+          V.first == Instruction::AShr)
         return new BinaryConstantExpr(V.first, V.second[0], V.second[1]);
       if (V.first == Instruction::Select)
         return new SelectConstantExpr(V.second[0], V.second[1], V.second[2]);
@@ -1364,7 +1357,8 @@
                                         OldC->getOperand(2));
         break;
       case Instruction::Shl:
-      case Instruction::Shr:
+      case Instruction::LShr:
+      case Instruction::AShr:
         New = ConstantExpr::getShiftTy(NewTy, OldC->getOpcode(),
                                      OldC->getOperand(0), OldC->getOperand(1));
         break;
@@ -1453,7 +1447,8 @@
 
 Constant *ConstantExpr::getTy(const Type *ReqTy, unsigned Opcode,
                               Constant *C1, Constant *C2) {
-  if (Opcode == Instruction::Shl || Opcode == Instruction::Shr)
+  if (Opcode == Instruction::Shl || Opcode == Instruction::LShr ||
+      Opcode == Instruction::AShr)
     return getShiftTy(ReqTy, Opcode, C1, C2);
   // Check the operands for consistency first
   assert(Opcode >= Instruction::BinaryOpsBegin &&
@@ -1521,9 +1516,10 @@
     assert(C1->getType() == C2->getType() && "Op types should be identical!");
     break;
   case Instruction::Shl:
-  case Instruction::Shr:
+  case Instruction::LShr:
+  case Instruction::AShr:
     assert(C2->getType() == Type::UByteTy && "Shift should be by ubyte!");
-    assert((C1->getType()->isInteger() || isa<PackedType>(C1->getType())) &&
+    assert(C1->getType()->isInteger() &&
            "Tried to create a shift operation on a non-integer type!");
     break;
   default:
@@ -1558,8 +1554,9 @@
 Constant *ConstantExpr::getShiftTy(const Type *ReqTy, unsigned Opcode,
                                    Constant *C1, Constant *C2) {
   // Check the operands for consistency first
-  assert((Opcode == Instruction::Shl ||
-          Opcode == Instruction::Shr) &&
+  assert((Opcode == Instruction::Shl   ||
+          Opcode == Instruction::LShr  ||
+          Opcode == Instruction::AShr) &&
          "Invalid opcode in binary constant expression");
   assert(C1->getType()->isIntegral() && C2->getType() == Type::UByteTy &&
          "Invalid operand types for Shift constant expr!");