[llvm-commits] CVS: llvm/lib/Transforms/IPO/GlobalOpt.cpp IndMemRemoval.cpp InlineSimple.cpp LowerSetJmp.cpp RaiseAllocations.cpp SimplifyLibCalls.cpp

Reid Spencer reid at x10sys.com
Sun Nov 26 17:06:24 PST 2006



Changes in directory llvm/lib/Transforms/IPO:

GlobalOpt.cpp updated: 1.72 -> 1.73
IndMemRemoval.cpp updated: 1.5 -> 1.6
InlineSimple.cpp updated: 1.75 -> 1.76
LowerSetJmp.cpp updated: 1.31 -> 1.32
RaiseAllocations.cpp updated: 1.30 -> 1.31
SimplifyLibCalls.cpp updated: 1.72 -> 1.73
---
Log message:

For PR950: http://llvm.org/PR950 :
The long awaited CAST patch. This introduces 12 new instructions into LLVM
to replace the cast instruction. Corresponding changes throughout LLVM are
provided. This passes llvm-test, llvm/test, and SPEC CPUINT2000 with the
exception of 175.vpr which fails only on a slight floating point output
difference.


---
Diffs of the changes:  (+68 -53)

 GlobalOpt.cpp        |    4 +-
 IndMemRemoval.cpp    |    3 +
 InlineSimple.cpp     |    9 +----
 LowerSetJmp.cpp      |    6 ++-
 RaiseAllocations.cpp |   12 ++++---
 SimplifyLibCalls.cpp |   87 +++++++++++++++++++++++++++++----------------------
 6 files changed, 68 insertions(+), 53 deletions(-)


Index: llvm/lib/Transforms/IPO/GlobalOpt.cpp
diff -u llvm/lib/Transforms/IPO/GlobalOpt.cpp:1.72 llvm/lib/Transforms/IPO/GlobalOpt.cpp:1.73
--- llvm/lib/Transforms/IPO/GlobalOpt.cpp:1.72	Sun Nov 26 04:02:32 2006
+++ llvm/lib/Transforms/IPO/GlobalOpt.cpp	Sun Nov 26 19:05:10 2006
@@ -329,7 +329,7 @@
         if (Init)
           SubInit = ConstantFoldLoadThroughGEPConstantExpr(Init, CE);
         Changed |= CleanupConstantGlobalUsers(CE, SubInit);
-      } else if (CE->getOpcode() == Instruction::Cast &&
+      } else if (CE->getOpcode() == Instruction::BitCast && 
                  isa<PointerType>(CE->getType())) {
         // Pointer cast, delete any stores and memsets to the global.
         Changed |= CleanupConstantGlobalUsers(CE, 0);
@@ -1174,7 +1174,7 @@
       LoadInst *NLI = new LoadInst(NewGV, Name+".b", LI);
       Value *NSI;
       if (IsOneZero)
-        NSI = new CastInst(NLI, LI->getType(), Name, LI);
+        NSI = CastInst::createInferredCast(NLI, LI->getType(), Name, LI);
       else
         NSI = new SelectInst(NLI, OtherVal, InitVal, Name, LI);
       LI->replaceAllUsesWith(NSI);


Index: llvm/lib/Transforms/IPO/IndMemRemoval.cpp
diff -u llvm/lib/Transforms/IPO/IndMemRemoval.cpp:1.5 llvm/lib/Transforms/IPO/IndMemRemoval.cpp:1.6
--- llvm/lib/Transforms/IPO/IndMemRemoval.cpp:1.5	Sun Nov 26 04:02:32 2006
+++ llvm/lib/Transforms/IPO/IndMemRemoval.cpp	Sun Nov 26 19:05:10 2006
@@ -74,7 +74,8 @@
 				  GlobalValue::LinkOnceLinkage, 
 				  "malloc_llvm_bounce", &M);
       BasicBlock* bb = new BasicBlock("entry",FN);
-      Instruction* c = new CastInst(FN->arg_begin(), Type::UIntTy, "c", bb);
+      Instruction* c = 
+        CastInst::createInferredCast(FN->arg_begin(), Type::UIntTy, "c", bb);
       Instruction* a = new MallocInst(Type::SByteTy, c, "m", bb);
       new ReturnInst(a, bb);
       ++NumBounce;


Index: llvm/lib/Transforms/IPO/InlineSimple.cpp
diff -u llvm/lib/Transforms/IPO/InlineSimple.cpp:1.75 llvm/lib/Transforms/IPO/InlineSimple.cpp:1.76
--- llvm/lib/Transforms/IPO/InlineSimple.cpp:1.75	Thu Nov  2 14:25:50 2006
+++ llvm/lib/Transforms/IPO/InlineSimple.cpp	Sun Nov 26 19:05:10 2006
@@ -141,14 +141,11 @@
          II != E; ++II) {
       if (isa<DbgInfoIntrinsic>(II)) continue;  // Debug intrinsics don't count.
       
-      // Noop casts don't count.
+      // Noop casts, including ptr <-> int,  don't count.
       if (const CastInst *CI = dyn_cast<CastInst>(II)) {
-        const Type *OpTy = CI->getOperand(0)->getType();
-        if (CI->getType()->isLosslesslyConvertibleTo(OpTy))
+        if (CI->isLosslessCast() || isa<IntToPtrInst>(CI) || 
+            isa<PtrToIntInst>(CI))
           continue;
-        if ((isa<PointerType>(CI->getType()) && OpTy->isInteger()) ||
-            (isa<PointerType>(OpTy) && CI->getType()->isInteger()))
-          continue;  // ptr <-> int is *probably* noop cast.
       } else if (const GetElementPtrInst *GEPI =
                          dyn_cast<GetElementPtrInst>(II)) {
         // If a GEP has all constant indices, it will probably be folded with


Index: llvm/lib/Transforms/IPO/LowerSetJmp.cpp
diff -u llvm/lib/Transforms/IPO/LowerSetJmp.cpp:1.31 llvm/lib/Transforms/IPO/LowerSetJmp.cpp:1.32
--- llvm/lib/Transforms/IPO/LowerSetJmp.cpp:1.31	Thu Nov  2 14:25:50 2006
+++ llvm/lib/Transforms/IPO/LowerSetJmp.cpp	Sun Nov 26 19:05:10 2006
@@ -259,7 +259,8 @@
   // same parameters as "longjmp", except that the buffer is cast to a
   // char*. It returns "void", so it doesn't need to replace any of
   // Inst's uses and doesn't get a name.
-  CastInst* CI = new CastInst(Inst->getOperand(1), SBPTy, "LJBuf", Inst);
+  CastInst* CI = 
+    new BitCastInst(Inst->getOperand(1), SBPTy, "LJBuf", Inst);
   new CallInst(ThrowLongJmp, make_vector<Value*>(CI, Inst->getOperand(2), 0),
                "", Inst);
 
@@ -375,7 +376,8 @@
 
   // Add this setjmp to the setjmp map.
   const Type* SBPTy = PointerType::get(Type::SByteTy);
-  CastInst* BufPtr = new CastInst(Inst->getOperand(1), SBPTy, "SBJmpBuf", Inst);
+  CastInst* BufPtr = 
+    new BitCastInst(Inst->getOperand(1), SBPTy, "SBJmpBuf", Inst);
   new CallInst(AddSJToMap,
                make_vector<Value*>(GetSetJmpMap(Func), BufPtr,
                                    ConstantInt::get(Type::UIntTy,


Index: llvm/lib/Transforms/IPO/RaiseAllocations.cpp
diff -u llvm/lib/Transforms/IPO/RaiseAllocations.cpp:1.30 llvm/lib/Transforms/IPO/RaiseAllocations.cpp:1.31
--- llvm/lib/Transforms/IPO/RaiseAllocations.cpp:1.30	Sun Aug 27 17:42:52 2006
+++ llvm/lib/Transforms/IPO/RaiseAllocations.cpp	Sun Nov 26 19:05:10 2006
@@ -140,7 +140,9 @@
           // If no prototype was provided for malloc, we may need to cast the
           // source size.
           if (Source->getType() != Type::UIntTy)
-            Source = new CastInst(Source, Type::UIntTy, "MallocAmtCast", I);
+            Source = 
+              CastInst::createInferredCast(Source, Type::UIntTy,
+                                           "MallocAmtCast", I);
 
           std::string Name(I->getName()); I->setName("");
           MallocInst *MI = new MallocInst(Type::SByteTy, Source, Name, I);
@@ -160,7 +162,7 @@
         Users.insert(Users.end(), GV->use_begin(), GV->use_end());
         EqPointers.push_back(GV);
       } else if (ConstantExpr *CE = dyn_cast<ConstantExpr>(U)) {
-        if (CE->getOpcode() == Instruction::Cast) {
+        if (CE->isCast()) {
           Users.insert(Users.end(), CE->use_begin(), CE->use_end());
           EqPointers.push_back(CE);
         }
@@ -191,8 +193,8 @@
           //
           Value *Source = *CS.arg_begin();
           if (!isa<PointerType>(Source->getType()))
-            Source = new CastInst(Source, PointerType::get(Type::SByteTy),
-                                  "FreePtrCast", I);
+            Source = CastInst::createInferredCast(
+                Source, PointerType::get(Type::SByteTy), "FreePtrCast", I);
           new FreeInst(Source, I);
 
           // If the old instruction was an invoke, add an unconditional branch
@@ -211,7 +213,7 @@
         Users.insert(Users.end(), GV->use_begin(), GV->use_end());
         EqPointers.push_back(GV);
       } else if (ConstantExpr *CE = dyn_cast<ConstantExpr>(U)) {
-        if (CE->getOpcode() == Instruction::Cast) {
+        if (CE->isCast()) {
           Users.insert(Users.end(), CE->use_begin(), CE->use_end());
           EqPointers.push_back(CE);
         }


Index: llvm/lib/Transforms/IPO/SimplifyLibCalls.cpp
diff -u llvm/lib/Transforms/IPO/SimplifyLibCalls.cpp:1.72 llvm/lib/Transforms/IPO/SimplifyLibCalls.cpp:1.73
--- llvm/lib/Transforms/IPO/SimplifyLibCalls.cpp:1.72	Thu Nov  2 14:25:50 2006
+++ llvm/lib/Transforms/IPO/SimplifyLibCalls.cpp	Sun Nov 26 19:05:10 2006
@@ -650,7 +650,8 @@
         LoadInst* load =
           new LoadInst(CastToCStr(s2,*ci), ci->getName()+".load",ci);
         CastInst* cast =
-          new CastInst(load,Type::IntTy,ci->getName()+".int",ci);
+          CastInst::create(Instruction::SExt, load, Type::IntTy, 
+                           ci->getName()+".int", ci);
         ci->replaceAllUsesWith(cast);
         ci->eraseFromParent();
         return true;
@@ -667,7 +668,8 @@
         LoadInst* load =
           new LoadInst(CastToCStr(s1,*ci),ci->getName()+".val",ci);
         CastInst* cast =
-          new CastInst(load,Type::IntTy,ci->getName()+".int",ci);
+          CastInst::create(Instruction::SExt, load, Type::IntTy, 
+                           ci->getName()+".int", ci);
         ci->replaceAllUsesWith(cast);
         ci->eraseFromParent();
         return true;
@@ -741,7 +743,8 @@
         // strncmp("",x) -> *x
         LoadInst* load = new LoadInst(s1,ci->getName()+".load",ci);
         CastInst* cast =
-          new CastInst(load,Type::IntTy,ci->getName()+".int",ci);
+          CastInst::create(Instruction::SExt, load, Type::IntTy, 
+                           ci->getName()+".int", ci);
         ci->replaceAllUsesWith(cast);
         ci->eraseFromParent();
         return true;
@@ -757,7 +760,8 @@
         // strncmp(x,"") -> *x
         LoadInst* load = new LoadInst(s2,ci->getName()+".val",ci);
         CastInst* cast =
-          new CastInst(load,Type::IntTy,ci->getName()+".int",ci);
+          CastInst::create(Instruction::SExt, load, Type::IntTy, 
+                           ci->getName()+".int", ci);
         ci->replaceAllUsesWith(cast);
         ci->eraseFromParent();
         return true;
@@ -997,13 +1001,15 @@
     case 1: {
       // memcmp(S1,S2,1) -> *(ubyte*)S1 - *(ubyte*)S2
       const Type *UCharPtr = PointerType::get(Type::UByteTy);
-      CastInst *Op1Cast = new CastInst(LHS, UCharPtr, LHS->getName(), CI);
-      CastInst *Op2Cast = new CastInst(RHS, UCharPtr, RHS->getName(), CI);
+      CastInst *Op1Cast = CastInst::create(
+          Instruction::BitCast, LHS, UCharPtr, LHS->getName(), CI);
+      CastInst *Op2Cast = CastInst::create(
+          Instruction::BitCast, RHS, UCharPtr, RHS->getName(), CI);
       Value *S1V = new LoadInst(Op1Cast, LHS->getName()+".val", CI);
       Value *S2V = new LoadInst(Op2Cast, RHS->getName()+".val", CI);
       Value *RV = BinaryOperator::createSub(S1V, S2V, CI->getName()+".diff",CI);
       if (RV->getType() != CI->getType())
-        RV = new CastInst(RV, CI->getType(), RV->getName(), CI);
+        RV = CastInst::createInferredCast(RV, CI->getType(), RV->getName(), CI);
       CI->replaceAllUsesWith(RV);
       CI->eraseFromParent();
       return true;
@@ -1014,8 +1020,10 @@
       
         // memcmp(S1,S2,2) -> S1[0]-S2[0] | S1[1]-S2[1] iff only ==/!= 0 matters
         const Type *UCharPtr = PointerType::get(Type::UByteTy);
-        CastInst *Op1Cast = new CastInst(LHS, UCharPtr, LHS->getName(), CI);
-        CastInst *Op2Cast = new CastInst(RHS, UCharPtr, RHS->getName(), CI);
+        CastInst *Op1Cast = CastInst::create(
+            Instruction::BitCast, LHS, UCharPtr, LHS->getName(), CI);
+        CastInst *Op2Cast = CastInst::create(
+            Instruction::BitCast, RHS, UCharPtr, RHS->getName(), CI);
         Value *S1V1 = new LoadInst(Op1Cast, LHS->getName()+".val1", CI);
         Value *S2V1 = new LoadInst(Op2Cast, RHS->getName()+".val1", CI);
         Value *D1 = BinaryOperator::createSub(S1V1, S2V1,
@@ -1029,7 +1037,8 @@
                                               CI->getName()+".d1", CI);
         Value *Or = BinaryOperator::createOr(D1, D2, CI->getName()+".res", CI);
         if (Or->getType() != CI->getType())
-          Or = new CastInst(Or, CI->getType(), Or->getName(), CI);
+          Or = CastInst::createInferredCast(Or, CI->getType(), Or->getName(), 
+                                            CI);
         CI->replaceAllUsesWith(Or);
         CI->eraseFromParent();
         return true;
@@ -1101,10 +1110,10 @@
     }
 
     // Cast source and dest to the right sized primitive and then load/store
-    CastInst* SrcCast =
-      new CastInst(src,PointerType::get(castType),src->getName()+".cast",ci);
-    CastInst* DestCast =
-      new CastInst(dest,PointerType::get(castType),dest->getName()+".cast",ci);
+    CastInst* SrcCast = CastInst::create(Instruction::BitCast,
+        src, PointerType::get(castType), src->getName()+".cast", ci);
+    CastInst* DestCast = CastInst::create(Instruction::BitCast,
+        dest, PointerType::get(castType),dest->getName()+".cast", ci);
     LoadInst* LI = new LoadInst(SrcCast,SrcCast->getName()+".val",ci);
     new StoreInst(LI, DestCast, ci);
     ci->eraseFromParent();
@@ -1213,8 +1222,8 @@
     }
 
     // Cast dest to the right sized primitive and then load/store
-    CastInst* DestCast =
-      new CastInst(dest,PointerType::get(castType),dest->getName()+".cast",ci);
+    CastInst* DestCast = CastInst::createInferredCast(
+        dest, PointerType::get(castType), dest->getName()+".cast", ci);
     new StoreInst(ConstantInt::get(castType,fill_value),DestCast, ci);
     ci->eraseFromParent();
     return true;
@@ -1356,8 +1365,8 @@
         Function* putchar_func = SLC.get_putchar();
         if (!putchar_func)
           return false;
-        CastInst* cast = new CastInst(ci->getOperand(2), Type::IntTy,
-                                      CI->getName()+".int", ci);
+        CastInst* cast = CastInst::createInferredCast(
+            ci->getOperand(2), Type::IntTy, CI->getName()+".int", ci);
         new CallInst(putchar_func, cast, "", ci);
         ci->replaceAllUsesWith(ConstantInt::get(Type::IntTy, 1));
         break;
@@ -1490,8 +1499,8 @@
         Function* fputc_func = SLC.get_fputc(FILEptr_type);
         if (!fputc_func)
           return false;
-        CastInst* cast = new CastInst(ci->getOperand(3), Type::IntTy,
-                                      CI->getName()+".int", ci);
+        CastInst* cast = CastInst::createInferredCast(
+            ci->getOperand(3), Type::IntTy, CI->getName()+".int", ci);
         new CallInst(fputc_func,cast,ci->getOperand(1),"",ci);
         ci->replaceAllUsesWith(ConstantInt::get(Type::IntTy,1));
         break;
@@ -1597,7 +1606,8 @@
                                             ConstantInt::get(Len->getType(), 1),
                                               Len->getName()+"1", ci);
       if (Len1->getType() != SLC.getIntPtrType())
-        Len1 = new CastInst(Len1, SLC.getIntPtrType(), Len1->getName(), ci);
+        Len1 = CastInst::createInferredCast(
+            Len1, SLC.getIntPtrType(), Len1->getName(), ci);
       std::vector<Value*> args;
       args.push_back(CastToCStr(ci->getOperand(1), *ci));
       args.push_back(CastToCStr(ci->getOperand(3), *ci));
@@ -1608,7 +1618,8 @@
       // The strlen result is the unincremented number of bytes in the string.
       if (!ci->use_empty()) {
         if (Len->getType() != ci->getType())
-          Len = new CastInst(Len, ci->getType(), Len->getName(), ci);
+          Len = CastInst::createInferredCast(
+              Len, ci->getType(), Len->getName(), ci);
         ci->replaceAllUsesWith(Len);
       }
       ci->eraseFromParent();
@@ -1616,7 +1627,8 @@
     }
     case 'c': {
       // sprintf(dest,"%c",chr) -> store chr, dest
-      CastInst* cast = new CastInst(ci->getOperand(3),Type::SByteTy,"char",ci);
+      CastInst* cast = CastInst::createInferredCast(
+          ci->getOperand(3), Type::SByteTy, "char", ci);
       new StoreInst(cast, ci->getOperand(1), ci);
       GetElementPtrInst* gep = new GetElementPtrInst(ci->getOperand(1),
         ConstantInt::get(Type::UIntTy,1),ci->getOperand(1)->getName()+".end",
@@ -1672,8 +1684,8 @@
           return false;
         LoadInst* loadi = new LoadInst(ci->getOperand(1),
           ci->getOperand(1)->getName()+".byte",ci);
-        CastInst* casti = new CastInst(loadi,Type::IntTy,
-          loadi->getName()+".int",ci);
+        CastInst* casti = CastInst::createInferredCast(
+            loadi, Type::IntTy, loadi->getName()+".int", ci);
         new CallInst(fputc_func,casti,ci->getOperand(2),"",ci);
         break;
       }
@@ -1726,18 +1738,16 @@
     }
 
     // isdigit(c)   -> (unsigned)c - '0' <= 9
-    CastInst* cast =
-      new CastInst(ci->getOperand(1),Type::UIntTy,
-        ci->getOperand(1)->getName()+".uint",ci);
+    CastInst* cast = CastInst::createInferredCast(ci->getOperand(1),
+        Type::UIntTy, ci->getOperand(1)->getName()+".uint", ci);
     BinaryOperator* sub_inst = BinaryOperator::createSub(cast,
         ConstantInt::get(Type::UIntTy,0x30),
         ci->getOperand(1)->getName()+".sub",ci);
     SetCondInst* setcond_inst = new SetCondInst(Instruction::SetLE,sub_inst,
         ConstantInt::get(Type::UIntTy,9),
         ci->getOperand(1)->getName()+".cmp",ci);
-    CastInst* c2 =
-      new CastInst(setcond_inst,Type::IntTy,
-        ci->getOperand(1)->getName()+".isdigit",ci);
+    CastInst* c2 = CastInst::createInferredCast(
+        setcond_inst, Type::IntTy, ci->getOperand(1)->getName()+".isdigit", ci);
     ci->replaceAllUsesWith(c2);
     ci->eraseFromParent();
     return true;
@@ -1759,12 +1769,14 @@
     // isascii(c)   -> (unsigned)c < 128
     Value *V = CI->getOperand(1);
     if (V->getType()->isSigned())
-      V = new CastInst(V, V->getType()->getUnsignedVersion(), V->getName(), CI);
+      V = CastInst::createInferredCast(V, V->getType()->getUnsignedVersion(), 
+                                       V->getName(), CI);
     Value *Cmp = BinaryOperator::createSetLT(V, ConstantInt::get(V->getType(),
                                                                   128),
                                              V->getName()+".isascii", CI);
     if (Cmp->getType() != CI->getType())
-      Cmp = new CastInst(Cmp, CI->getType(), Cmp->getName(), CI);
+      Cmp = CastInst::createInferredCast(
+          Cmp, CI->getType(), Cmp->getName(), CI);
     CI->replaceAllUsesWith(Cmp);
     CI->eraseFromParent();
     return true;
@@ -1858,9 +1870,10 @@
     
     Function *F = SLC.getModule()->getOrInsertFunction(CTTZName, ArgType,
                                                        ArgType, NULL);
-    Value *V = new CastInst(TheCall->getOperand(1), ArgType, "tmp", TheCall);
+    Value *V = CastInst::createInferredCast(
+        TheCall->getOperand(1), ArgType, "tmp", TheCall);
     Value *V2 = new CallInst(F, V, "tmp", TheCall);
-    V2 = new CastInst(V2, Type::IntTy, "tmp", TheCall);
+    V2 = CastInst::createInferredCast(V2, Type::IntTy, "tmp", TheCall);
     V2 = BinaryOperator::createAdd(V2, ConstantInt::get(Type::IntTy, 1),
                                    "tmp", TheCall);
     Value *Cond = 
@@ -1920,7 +1933,7 @@
       if (Cast->getOperand(0)->getType() == Type::FloatTy) {
         Value *New = new CallInst((SLC.*FP)(), Cast->getOperand(0),
                                   CI->getName(), CI);
-        New = new CastInst(New, Type::DoubleTy, CI->getName(), CI);
+        New = new FPExtInst(New, Type::DoubleTy, CI->getName(), CI);
         CI->replaceAllUsesWith(New);
         CI->eraseFromParent();
         if (Cast->use_empty())
@@ -2105,7 +2118,7 @@
 Value *CastToCStr(Value *V, Instruction &IP) {
   const Type *SBPTy = PointerType::get(Type::SByteTy);
   if (V->getType() != SBPTy)
-    return new CastInst(V, SBPTy, V->getName(), &IP);
+    return CastInst::createInferredCast(V, SBPTy, V->getName(), &IP);
   return V;
 }
 






More information about the llvm-commits mailing list