Change inferred getCast into specific getCast. Passes all tests.
authorReid Spencer <rspencer@reidspencer.com>
Tue, 12 Dec 2006 05:05:00 +0000 (05:05 +0000)
committerReid Spencer <rspencer@reidspencer.com>
Tue, 12 Dec 2006 05:05:00 +0000 (05:05 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@32469 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Analysis/ScalarEvolution.cpp
lib/Linker/LinkModules.cpp
lib/Target/CBackend/CBackend.cpp
lib/Target/CBackend/Writer.cpp
lib/Transforms/IPO/FunctionResolution.cpp
lib/Transforms/Scalar/LoopStrengthReduce.cpp
lib/Transforms/Scalar/SCCP.cpp
lib/Transforms/Utils/LowerAllocations.cpp
lib/Transforms/Utils/LowerInvoke.cpp

index 6d449d0d92b6ed0e6dd1e0e4c17eff106c4866d6..703a1c46e9a9fb9c05282a7ee5ecca6ce9c258eb 100644 (file)
@@ -1566,7 +1566,9 @@ SCEVHandle ScalarEvolutionsImpl::ComputeIterationCount(const Loop *L) {
         // comparison.
         ConstantInt *CompVal = RHSC->getValue();
         const Type *RealTy = ExitCond->getOperand(0)->getType();
-        CompVal = dyn_cast<ConstantInt>(ConstantExpr::getCast(CompVal, RealTy));
+        CompVal = dyn_cast<ConstantInt>(
+          ConstantExpr::getIntegerCast(CompVal, RealTy, 
+                                       CompVal->getType()->isSigned()));
         if (CompVal) {
           // Form the constant range.
           ConstantRange CompRange(Cond, CompVal);
@@ -1575,8 +1577,12 @@ SCEVHandle ScalarEvolutionsImpl::ComputeIterationCount(const Loop *L) {
           // range.
           if (CompRange.getLower()->getType()->isSigned()) {
             const Type *NewTy = RHSC->getValue()->getType();
-            Constant *NewL = ConstantExpr::getCast(CompRange.getLower(), NewTy);
-            Constant *NewU = ConstantExpr::getCast(CompRange.getUpper(), NewTy);
+            Constant *NewL = 
+              ConstantExpr::getIntegerCast(CompRange.getLower(), NewTy, 
+                 CompRange.getLower()->getType()->isSigned());
+            Constant *NewU = 
+              ConstantExpr::getIntegerCast(CompRange.getUpper(), NewTy,
+                 CompRange.getUpper()->getType()->isSigned());
             CompRange = ConstantRange(NewL, NewU);
           }
 
index 8f8aec1abd9f908e037862f8d981831158da222c..433dfa682d60d02c0d7472620243b029856da663 100644 (file)
@@ -508,7 +508,8 @@ static bool LinkGlobals(Module *Dest, Module *Src,
                              DGV->isConstant(), DGV->getLinkage());
         NewDGV->setAlignment(DGV->getAlignment());
         Dest->getGlobalList().insert(DGV, NewDGV);
-        DGV->replaceAllUsesWith(ConstantExpr::getCast(NewDGV, DGV->getType()));
+        DGV->replaceAllUsesWith(
+            ConstantExpr::getBitCast(NewDGV, DGV->getType()));
         DGV->eraseFromParent();
         NewDGV->setName(SGV->getName());
         DGV = NewDGV;
@@ -529,9 +530,8 @@ static bool LinkGlobals(Module *Dest, Module *Src,
         SGV->setInitializer(0);
       }
 
-      ValueMap.insert(std::make_pair(SGV,
-                                     ConstantExpr::getCast(DGV,
-                                                           SGV->getType())));
+      ValueMap.insert(
+        std::make_pair(SGV, ConstantExpr::getBitCast(DGV, SGV->getType())));
     }
   }
   return false;
@@ -807,8 +807,8 @@ static bool LinkAppendingVars(Module *M,
 
       // FIXME: This should rewrite simple/straight-forward uses such as
       // getelementptr instructions to not use the Cast!
-      G1->replaceAllUsesWith(ConstantExpr::getCast(NG, G1->getType()));
-      G2->replaceAllUsesWith(ConstantExpr::getCast(NG, G2->getType()));
+      G1->replaceAllUsesWith(ConstantExpr::getBitCast(NG, G1->getType()));
+      G2->replaceAllUsesWith(ConstantExpr::getBitCast(NG, G2->getType()));
 
       // Remove the two globals from the module now...
       M->getGlobalList().erase(G1);
index 96fc53948b32a33d5d3c4c3977d0a1128392e6b7..46c8bf1bd75a17dd01e1f997ce312fefb00b9821 100644 (file)
@@ -296,7 +296,7 @@ bool CBackendNameAllUsedStructsAndMergeFunctions::runOnModule(Module &M) {
       if (!X.second) {
         // Found a conflict, replace this global with the previous one.
         GlobalValue *OldGV = X.first->second;
-        GV->replaceAllUsesWith(ConstantExpr::getCast(OldGV, GV->getType()));
+        GV->replaceAllUsesWith(ConstantExpr::getBitCast(OldGV, GV->getType()));
         GV->eraseFromParent();
         Changed = true;
       }
@@ -312,7 +312,7 @@ bool CBackendNameAllUsedStructsAndMergeFunctions::runOnModule(Module &M) {
       if (!X.second) {
         // Found a conflict, replace this global with the previous one.
         GlobalValue *OldGV = X.first->second;
-        GV->replaceAllUsesWith(ConstantExpr::getCast(OldGV, GV->getType()));
+        GV->replaceAllUsesWith(ConstantExpr::getBitCast(OldGV, GV->getType()));
         GV->eraseFromParent();
         Changed = true;
       }
index 96fc53948b32a33d5d3c4c3977d0a1128392e6b7..46c8bf1bd75a17dd01e1f997ce312fefb00b9821 100644 (file)
@@ -296,7 +296,7 @@ bool CBackendNameAllUsedStructsAndMergeFunctions::runOnModule(Module &M) {
       if (!X.second) {
         // Found a conflict, replace this global with the previous one.
         GlobalValue *OldGV = X.first->second;
-        GV->replaceAllUsesWith(ConstantExpr::getCast(OldGV, GV->getType()));
+        GV->replaceAllUsesWith(ConstantExpr::getBitCast(OldGV, GV->getType()));
         GV->eraseFromParent();
         Changed = true;
       }
@@ -312,7 +312,7 @@ bool CBackendNameAllUsedStructsAndMergeFunctions::runOnModule(Module &M) {
       if (!X.second) {
         // Found a conflict, replace this global with the previous one.
         GlobalValue *OldGV = X.first->second;
-        GV->replaceAllUsesWith(ConstantExpr::getCast(OldGV, GV->getType()));
+        GV->replaceAllUsesWith(ConstantExpr::getBitCast(OldGV, GV->getType()));
         GV->eraseFromParent();
         Changed = true;
       }
index f6e8cf591344129b7810a47a7fcf509ff94fff71..6f1eea0276730e0685b7446d92a16552abc30232 100644 (file)
@@ -103,7 +103,7 @@ static bool ResolveFunctions(Module &M, std::vector<GlobalValue*> &Globals,
       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 @@ static bool ResolveGlobalVariables(Module &M,
 
   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.
index 66b595fd7f7462c3a2349dabb8961347246b9d01..c132aaef927e4e90fb2cb3f716e943f29965cdef 100644 (file)
@@ -200,12 +200,17 @@ FunctionPass *llvm::createLoopStrengthReducePass(const TargetLowering *TLI) {
   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;
index 5d928c145dfeac5b3a852a1e309426adfdbdbeee..4f0607ef2944daaab5f3c7e0930ba2a227606f89 100644 (file)
@@ -589,7 +589,8 @@ void SCCPSolver::visitCastInst(CastInst &I) {
   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) {
index 75a4c704c91e144436a4df60bcada384973be09a..40a4dc0d3055ed4009b9d5c86fee13baf260ddb4 100644 (file)
@@ -122,14 +122,15 @@ bool LowerAllocations::runOnBasicBlock(BasicBlock &BB) {
         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);
index dfeb8349f4aa2f9a7b286547a55932361ce88e50..4fbd43c6f4dcdcf92429fe98ee38b963b96a00cd 100644 (file)
@@ -215,8 +215,12 @@ void LowerInvoke::writeAbortMessage(Instruction *IB) {
     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();
   }