[llvm-commits] CVS: llvm/lib/Analysis/BasicAliasAnalysis.cpp ConstantRange.cpp ScalarEvolution.cpp ScalarEvolutionExpander.cpp

Reid Spencer reid at x10sys.com
Tue Dec 12 15:36:32 PST 2006



Changes in directory llvm/lib/Analysis:

BasicAliasAnalysis.cpp updated: 1.93 -> 1.94
ConstantRange.cpp updated: 1.21 -> 1.22
ScalarEvolution.cpp updated: 1.71 -> 1.72
ScalarEvolutionExpander.cpp updated: 1.8 -> 1.9
---
Log message:

Replace inferred getCast(V,Ty) calls with more strict variants.
Rename getZeroExtend and getSignExtend to getZExt and getSExt to match
the the casting mnemonics in the rest of LLVM.


---
Diffs of the changes:  (+42 -21)

 BasicAliasAnalysis.cpp      |    8 ++++----
 ConstantRange.cpp           |    8 ++++----
 ScalarEvolution.cpp         |   21 ++++++++++++---------
 ScalarEvolutionExpander.cpp |   26 ++++++++++++++++++++++----
 4 files changed, 42 insertions(+), 21 deletions(-)


Index: llvm/lib/Analysis/BasicAliasAnalysis.cpp
diff -u llvm/lib/Analysis/BasicAliasAnalysis.cpp:1.93 llvm/lib/Analysis/BasicAliasAnalysis.cpp:1.94
--- llvm/lib/Analysis/BasicAliasAnalysis.cpp:1.93	Wed Dec  6 19:30:31 2006
+++ llvm/lib/Analysis/BasicAliasAnalysis.cpp	Tue Dec 12 17:36:14 2006
@@ -459,11 +459,11 @@
     if (Constant *C2 = dyn_cast<Constant>(V2)) {
       // Sign extend the constants to long types, if necessary
       if (C1->getType()->getPrimitiveSizeInBits() < 64)
-        C1 = ConstantExpr::getSignExtend(C1, Type::LongTy);
+        C1 = ConstantExpr::getSExt(C1, Type::LongTy);
       else if (C1->getType() == Type::ULongTy)
         C1 = ConstantExpr::getBitCast(C1, Type::LongTy);
       if (C2->getType()->getPrimitiveSizeInBits() < 64)
-        C2 = ConstantExpr::getSignExtend(C2, Type::LongTy);
+        C2 = ConstantExpr::getSExt(C2, Type::LongTy);
       else if (C2->getType() == Type::ULongTy)
         C2 = ConstantExpr::getBitCast(C2, Type::LongTy);
       return C1 == C2;
@@ -555,11 +555,11 @@
           if (G1OC->getType() != G2OC->getType()) {
             // Sign extend both operands to long.
             if (G1OC->getType()->getPrimitiveSizeInBits() < 64)
-              G1OC = ConstantExpr::getSignExtend(G1OC, Type::LongTy);
+              G1OC = ConstantExpr::getSExt(G1OC, Type::LongTy);
             else if (G1OC->getType() == Type::ULongTy)
               G1OC = ConstantExpr::getBitCast(G1OC, Type::LongTy);
             if (G2OC->getType()->getPrimitiveSizeInBits() < 64)
-              G2OC = ConstantExpr::getSignExtend(G2OC, Type::LongTy);
+              G2OC = ConstantExpr::getSExt(G2OC, Type::LongTy);
             else if (G2OC->getType() == Type::ULongTy)
               G2OC = ConstantExpr::getBitCast(G2OC, Type::LongTy);
             GEP1Ops[FirstConstantOper] = G1OC;


Index: llvm/lib/Analysis/ConstantRange.cpp
diff -u llvm/lib/Analysis/ConstantRange.cpp:1.21 llvm/lib/Analysis/ConstantRange.cpp:1.22
--- llvm/lib/Analysis/ConstantRange.cpp:1.21	Wed Dec  6 19:30:31 2006
+++ llvm/lib/Analysis/ConstantRange.cpp	Tue Dec 12 17:36:14 2006
@@ -340,8 +340,8 @@
   Constant *Lower = getLower();
   Constant *Upper = getUpper();
 
-  return ConstantRange(ConstantExpr::getCast(Instruction::ZExt, Lower, Ty),
-                       ConstantExpr::getCast(Instruction::ZExt, Upper, Ty));
+  return ConstantRange(ConstantExpr::getZExt(Lower, Ty),
+                       ConstantExpr::getZExt(Upper, Ty));
 }
 
 /// truncate - Return a new range in the specified integer type, which must be
@@ -356,8 +356,8 @@
     return ConstantRange(getType());
 
   return ConstantRange(
-      ConstantExpr::getCast(Instruction::Trunc, getLower(), Ty),
-      ConstantExpr::getCast(Instruction::Trunc, getUpper(), Ty));
+      ConstantExpr::getTrunc(getLower(), Ty),
+      ConstantExpr::getTrunc(getUpper(), Ty));
 }
 
 


Index: llvm/lib/Analysis/ScalarEvolution.cpp
diff -u llvm/lib/Analysis/ScalarEvolution.cpp:1.71 llvm/lib/Analysis/ScalarEvolution.cpp:1.72
--- llvm/lib/Analysis/ScalarEvolution.cpp:1.71	Tue Dec 12 03:17:50 2006
+++ llvm/lib/Analysis/ScalarEvolution.cpp	Tue Dec 12 17:36:14 2006
@@ -584,7 +584,7 @@
 SCEVHandle SCEVZeroExtendExpr::get(const SCEVHandle &Op, const Type *Ty) {
   if (SCEVConstant *SC = dyn_cast<SCEVConstant>(Op))
     return SCEVUnknown::get(
-        ConstantExpr::getZeroExtend(SC->getValue(), Ty));
+        ConstantExpr::getZExt(SC->getValue(), Ty));
 
   // FIXME: If the input value is a chrec scev, and we can prove that the value
   // did not overflow the old, smaller, value, we can zero extend all of the
@@ -2000,11 +2000,14 @@
           } else {
             SCEVHandle OpV = getSCEVAtScope(getSCEV(Op), L);
             if (SCEVConstant *SC = dyn_cast<SCEVConstant>(OpV))
-              Operands.push_back(ConstantExpr::getCast(SC->getValue(),
-                                                       Op->getType()));
+              Operands.push_back(ConstantExpr::getIntegerCast(SC->getValue(), 
+                                                              Op->getType(), 
+                                                              false));
             else if (SCEVUnknown *SU = dyn_cast<SCEVUnknown>(OpV)) {
               if (Constant *C = dyn_cast<Constant>(SU->getValue()))
-                Operands.push_back(ConstantExpr::getCast(C, Op->getType()));
+                Operands.push_back(ConstantExpr::getIntegerCast(C, 
+                                                                Op->getType(), 
+                                                                false));
               else
                 return V;
             } else {
@@ -2122,7 +2125,7 @@
 
   // Compute floor(sqrt(B^2-4ac))
   ConstantInt *SqrtVal =
-    cast<ConstantInt>(ConstantExpr::getCast(SqrtTerm,
+    cast<ConstantInt>(ConstantExpr::getBitCast(SqrtTerm,
                                    SqrtTerm->getType()->getUnsignedVersion()));
   uint64_t SqrtValV = SqrtVal->getZExtValue();
   uint64_t SqrtValV2 = (uint64_t)sqrt((double)SqrtValV);
@@ -2135,16 +2138,16 @@
   }
 
   SqrtVal = ConstantInt::get(Type::ULongTy, SqrtValV2);
-  SqrtTerm = ConstantExpr::getCast(SqrtVal, SqrtTerm->getType());
+  SqrtTerm = ConstantExpr::getTruncOrBitCast(SqrtVal, SqrtTerm->getType());
 
   Constant *NegB = ConstantExpr::getNeg(B);
   Constant *TwoA = ConstantExpr::getMul(A, Two);
 
   // The divisions must be performed as signed divisions.
   const Type *SignedTy = NegB->getType()->getSignedVersion();
-  NegB = ConstantExpr::getCast(NegB, SignedTy);
-  TwoA = ConstantExpr::getCast(TwoA, SignedTy);
-  SqrtTerm = ConstantExpr::getCast(SqrtTerm, SignedTy);
+  NegB = ConstantExpr::getBitCast(NegB, SignedTy);
+  TwoA = ConstantExpr::getBitCast(TwoA, SignedTy);
+  SqrtTerm = ConstantExpr::getBitCast(SqrtTerm, SignedTy);
 
   Constant *Solution1 =
     ConstantExpr::getSDiv(ConstantExpr::getAdd(NegB, SqrtTerm), TwoA);


Index: llvm/lib/Analysis/ScalarEvolutionExpander.cpp
diff -u llvm/lib/Analysis/ScalarEvolutionExpander.cpp:1.8 llvm/lib/Analysis/ScalarEvolutionExpander.cpp:1.9
--- llvm/lib/Analysis/ScalarEvolutionExpander.cpp:1.8	Wed Dec  6 19:30:31 2006
+++ llvm/lib/Analysis/ScalarEvolutionExpander.cpp	Tue Dec 12 17:36:14 2006
@@ -20,9 +20,27 @@
 /// InsertCastOfTo - Insert a cast of V to the specified type, doing what
 /// we can to share the casts.
 Value *SCEVExpander::InsertCastOfTo(Value *V, const Type *Ty) {
+  // Compute the Cast opcode to use
+  Instruction::CastOps opcode = Instruction::BitCast;
+  if (Ty->isIntegral()) {
+    if (V->getType()->getTypeID() == Type::PointerTyID)
+      opcode = Instruction::PtrToInt;
+    else {
+      unsigned SrcBits = V->getType()->getPrimitiveSizeInBits();
+      unsigned DstBits = Ty->getPrimitiveSizeInBits();
+      opcode = (SrcBits > DstBits ? Instruction::Trunc : 
+                (SrcBits == DstBits ? Instruction::BitCast :
+                 (V->getType()->isSigned() ? Instruction::SExt : 
+                  Instruction::ZExt)));
+    }
+  } else if (Ty->isFloatingPoint())
+    opcode = Instruction::UIToFP;
+  else if (Ty->getTypeID() == Type::PointerTyID && V->getType()->isIntegral())
+    opcode = Instruction::IntToPtr;
+
   // FIXME: keep track of the cast instruction.
   if (Constant *C = dyn_cast<Constant>(V))
-    return ConstantExpr::getCast(C, Ty);
+    return ConstantExpr::getCast(opcode, C, Ty);
   
   if (Argument *A = dyn_cast<Argument>(V)) {
     // Check to see if there is already a cast!
@@ -38,8 +56,8 @@
           return CI;
         }
     }
-    return CastInst::createInferredCast(
-        V, Ty, V->getName(), A->getParent()->getEntryBlock().begin());
+    return CastInst::create(opcode, V, Ty, V->getName(), 
+                            A->getParent()->getEntryBlock().begin());
   }
     
   Instruction *I = cast<Instruction>(V);
@@ -64,7 +82,7 @@
   if (InvokeInst *II = dyn_cast<InvokeInst>(I))
     IP = II->getNormalDest()->begin();
   while (isa<PHINode>(IP)) ++IP;
-  return CastInst::createInferredCast(V, Ty, V->getName(), IP);
+  return CastInst::create(opcode, V, Ty, V->getName(), IP);
 }
 
 Value *SCEVExpander::visitMulExpr(SCEVMulExpr *S) {






More information about the llvm-commits mailing list