Change inferred getCast into specific getCast. Passes all tests.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@32469 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Transforms/IPO/FunctionResolution.cpp b/lib/Transforms/IPO/FunctionResolution.cpp
index f6e8cf5..6f1eea0 100644
--- a/lib/Transforms/IPO/FunctionResolution.cpp
+++ b/lib/Transforms/IPO/FunctionResolution.cpp
@@ -103,7 +103,7 @@
       if (!Old->use_empty()) {
         Value *Replacement = Concrete;
         if (Concrete->getType() != Old->getType())
-          Replacement = ConstantExpr::getCast(Concrete, Old->getType());
+          Replacement = ConstantExpr::getBitCast(Concrete, Old->getType());
         NumResolved += Old->getNumUses();
         Old->replaceAllUsesWith(Replacement);
       }
@@ -122,7 +122,7 @@
 
   for (unsigned i = 0; i != Globals.size(); ++i)
     if (Globals[i] != Concrete) {
-      Constant *Cast = ConstantExpr::getCast(Concrete, Globals[i]->getType());
+      Constant *Cast = ConstantExpr::getBitCast(Concrete,Globals[i]->getType());
       Globals[i]->replaceAllUsesWith(Cast);
 
       // Since there are no uses of Old anymore, remove it from the module.
diff --git a/lib/Transforms/Scalar/LoopStrengthReduce.cpp b/lib/Transforms/Scalar/LoopStrengthReduce.cpp
index 66b595f..c132aae 100644
--- a/lib/Transforms/Scalar/LoopStrengthReduce.cpp
+++ b/lib/Transforms/Scalar/LoopStrengthReduce.cpp
@@ -200,12 +200,17 @@
   return new LoopStrengthReduce(TLI);
 }
 
-/// getCastedVersionOf - Return the specified value casted to uintptr_t.
+/// getCastedVersionOf - Return the specified value casted to uintptr_t. This
+/// assumes that the Value* V is of integer or pointer type only.
 ///
 Value *LoopStrengthReduce::getCastedVersionOf(Value *V) {
   if (V->getType() == UIntPtrTy) return V;
   if (Constant *CB = dyn_cast<Constant>(V))
-    return ConstantExpr::getCast(CB, UIntPtrTy);
+    if (CB->getType()->isInteger())
+      return ConstantExpr::getIntegerCast(CB, UIntPtrTy, 
+                                          CB->getType()->isSigned());
+    else
+      return ConstantExpr::getPtrToInt(CB, UIntPtrTy);
 
   Value *&New = CastedPointers[V];
   if (New) return New;
diff --git a/lib/Transforms/Scalar/SCCP.cpp b/lib/Transforms/Scalar/SCCP.cpp
index 5d928c1..4f0607e 100644
--- a/lib/Transforms/Scalar/SCCP.cpp
+++ b/lib/Transforms/Scalar/SCCP.cpp
@@ -589,7 +589,8 @@
   if (VState.isOverdefined())          // Inherit overdefinedness of operand
     markOverdefined(&I);
   else if (VState.isConstant())        // Propagate constant value
-    markConstant(&I, ConstantExpr::getCast(VState.getConstant(), I.getType()));
+    markConstant(&I, ConstantExpr::getCast(I.getOpcode(), 
+                                           VState.getConstant(), I.getType()));
 }
 
 void SCCPSolver::visitSelectInst(SelectInst &I) {
diff --git a/lib/Transforms/Utils/LowerAllocations.cpp b/lib/Transforms/Utils/LowerAllocations.cpp
index 75a4c70..40a4dc0 100644
--- a/lib/Transforms/Utils/LowerAllocations.cpp
+++ b/lib/Transforms/Utils/LowerAllocations.cpp
@@ -122,14 +122,15 @@
         MallocArg = ConstantInt::get(Type::ULongTy, TD.getTypeSize(AllocTy));
       else
         MallocArg = ConstantExpr::getSizeOf(AllocTy);
-      MallocArg = ConstantExpr::getCast(cast<Constant>(MallocArg), IntPtrTy);
+      MallocArg = ConstantExpr::getIntegerCast(cast<Constant>(MallocArg), 
+                                               IntPtrTy, true /*SExt*/);
 
       if (MI->isArrayAllocation()) {
         if (isa<ConstantInt>(MallocArg) &&
             cast<ConstantInt>(MallocArg)->getZExtValue() == 1) {
           MallocArg = MI->getOperand(0);         // Operand * 1 = Operand
         } else if (Constant *CO = dyn_cast<Constant>(MI->getOperand(0))) {
-          CO = ConstantExpr::getCast(CO, IntPtrTy);
+          CO = ConstantExpr::getIntegerCast(CO, IntPtrTy, true /*SExt*/);
           MallocArg = ConstantExpr::getMul(CO, cast<Constant>(MallocArg));
         } else {
           Value *Scale = MI->getOperand(0);
diff --git a/lib/Transforms/Utils/LowerInvoke.cpp b/lib/Transforms/Utils/LowerInvoke.cpp
index dfeb834..4fbd43c 100644
--- a/lib/Transforms/Utils/LowerInvoke.cpp
+++ b/lib/Transforms/Utils/LowerInvoke.cpp
@@ -215,8 +215,12 @@
     unsigned NumArgs = FT->getNumParams();
     for (unsigned i = 0; i != 3; ++i)
       if (i < NumArgs && FT->getParamType(i) != Args[i]->getType())
-        Args[i] = ConstantExpr::getCast(cast<Constant>(Args[i]),
-                                        FT->getParamType(i));
+        if (Args[i]->getType()->isInteger())
+          Args[i] = ConstantExpr::getIntegerCast(cast<Constant>(Args[i]),
+                                                 FT->getParamType(i), true);
+        else
+          Args[i] = ConstantExpr::getBitCast(cast<Constant>(Args[i]),
+                                             FT->getParamType(i));
 
     (new CallInst(WriteFn, Args, "", IB))->setTailCall();
   }