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

Reid Spencer reid at x10sys.com
Sat Dec 30 21:48:59 PST 2006



Changes in directory llvm/lib/Analysis:

BasicAliasAnalysis.cpp updated: 1.95 -> 1.96
ConstantFolding.cpp updated: 1.7 -> 1.8
ScalarEvolution.cpp updated: 1.77 -> 1.78
---
Log message:

For PR950: http://llvm.org/PR950 :
This patch replaces signed integer types with signless ones:
1. [US]Byte -> Int8
2. [U]Short -> Int16
3. [U]Int   -> Int32
4. [U]Long  -> Int64.
5. Removal of isSigned, isUnsigned, getSignedVersion, getUnsignedVersion
   and other methods related to signedness. In a few places this warranted
   identifying the signedness information from other sources.



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

 BasicAliasAnalysis.cpp |   32 ++++++++++------------------
 ConstantFolding.cpp    |    1 
 ScalarEvolution.cpp    |   56 +++++++------------------------------------------
 3 files changed, 21 insertions(+), 68 deletions(-)


Index: llvm/lib/Analysis/BasicAliasAnalysis.cpp
diff -u llvm/lib/Analysis/BasicAliasAnalysis.cpp:1.95 llvm/lib/Analysis/BasicAliasAnalysis.cpp:1.96
--- llvm/lib/Analysis/BasicAliasAnalysis.cpp:1.95	Sat Dec 23 00:05:40 2006
+++ llvm/lib/Analysis/BasicAliasAnalysis.cpp	Sat Dec 30 23:48:39 2006
@@ -269,7 +269,7 @@
   if (V1 == V2) return MustAlias;
 
   if ((!isa<PointerType>(V1->getType()) || !isa<PointerType>(V2->getType())) &&
-      V1->getType() != Type::LongTy && V2->getType() != Type::LongTy)
+      V1->getType() != Type::Int64Ty && V2->getType() != Type::Int64Ty)
     return NoAlias;  // Scalars cannot alias each other
 
   // Strip off cast instructions...
@@ -458,14 +458,10 @@
   if (Constant *C1 = dyn_cast<Constant>(V1))
     if (Constant *C2 = dyn_cast<Constant>(V2)) {
       // Sign extend the constants to long types, if necessary
-      if (C1->getType()->getPrimitiveSizeInBits() < 64)
-        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::getSExt(C2, Type::LongTy);
-      else if (C2->getType() == Type::ULongTy)
-        C2 = ConstantExpr::getBitCast(C2, Type::LongTy);
+      if (C1->getType() != Type::Int64Ty)
+        C1 = ConstantExpr::getSExt(C1, Type::Int64Ty);
+      if (C2->getType() != Type::Int64Ty) 
+        C2 = ConstantExpr::getSExt(C2, Type::Int64Ty);
       return C1 == C2;
     }
   return false;
@@ -554,14 +550,10 @@
         if (Constant *G2OC = dyn_cast<ConstantInt>(const_cast<Value*>(G2Oper))){
           if (G1OC->getType() != G2OC->getType()) {
             // Sign extend both operands to long.
-            if (G1OC->getType()->getPrimitiveSizeInBits() < 64)
-              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::getSExt(G2OC, Type::LongTy);
-            else if (G2OC->getType() == Type::ULongTy)
-              G2OC = ConstantExpr::getBitCast(G2OC, Type::LongTy);
+            if (G1OC->getType() != Type::Int64Ty)
+              G1OC = ConstantExpr::getSExt(G1OC, Type::Int64Ty);
+            if (G2OC->getType() != Type::Int64Ty) 
+              G2OC = ConstantExpr::getSExt(G2OC, Type::Int64Ty);
             GEP1Ops[FirstConstantOper] = G1OC;
             GEP2Ops[FirstConstantOper] = G2OC;
           }
@@ -661,7 +653,7 @@
   const Type *ZeroIdxTy = GEPPointerTy;
   for (unsigned i = 0; i != FirstConstantOper; ++i) {
     if (!isa<StructType>(ZeroIdxTy))
-      GEP1Ops[i] = GEP2Ops[i] = Constant::getNullValue(Type::UIntTy);
+      GEP1Ops[i] = GEP2Ops[i] = Constant::getNullValue(Type::Int32Ty);
 
     if (const CompositeType *CT = dyn_cast<CompositeType>(ZeroIdxTy))
       ZeroIdxTy = CT->getTypeAtIndex(GEP1Ops[i]);
@@ -702,9 +694,9 @@
           // value possible.
           //
           if (const ArrayType *AT = dyn_cast<ArrayType>(BasePtr1Ty))
-            GEP1Ops[i] = ConstantInt::get(Type::LongTy, AT->getNumElements()-1);
+            GEP1Ops[i] = ConstantInt::get(Type::Int64Ty, AT->getNumElements()-1);
           else if (const PackedType *PT = dyn_cast<PackedType>(BasePtr1Ty))
-            GEP1Ops[i] = ConstantInt::get(Type::LongTy, PT->getNumElements()-1);
+            GEP1Ops[i] = ConstantInt::get(Type::Int64Ty, PT->getNumElements()-1);
 
         }
       }


Index: llvm/lib/Analysis/ConstantFolding.cpp
diff -u llvm/lib/Analysis/ConstantFolding.cpp:1.7 llvm/lib/Analysis/ConstantFolding.cpp:1.8
--- llvm/lib/Analysis/ConstantFolding.cpp:1.7	Fri Dec  1 20:22:01 2006
+++ llvm/lib/Analysis/ConstantFolding.cpp	Sat Dec 30 23:48:39 2006
@@ -164,7 +164,6 @@
           break;
       }
     } else if (ConstantInt *Op = dyn_cast<ConstantInt>(Operands[0])) {
-      assert(Op->getType()->isUnsigned() && "bswap args must be unsigned");
       uint64_t V = Op->getZExtValue();
       if (Name == "llvm.bswap.i16")
         return ConstantInt::get(Ty, ByteSwap_16(V));


Index: llvm/lib/Analysis/ScalarEvolution.cpp
diff -u llvm/lib/Analysis/ScalarEvolution.cpp:1.77 llvm/lib/Analysis/ScalarEvolution.cpp:1.78
--- llvm/lib/Analysis/ScalarEvolution.cpp:1.77	Sat Dec 23 00:05:40 2006
+++ llvm/lib/Analysis/ScalarEvolution.cpp	Sat Dec 30 23:48:39 2006
@@ -123,7 +123,6 @@
 ConstantRange SCEV::getValueRange() const {
   const Type *Ty = getType();
   assert(Ty->isInteger() && "Can't get range for a non-integer SCEV!");
-  Ty = Ty->getUnsignedVersion();
   // Default to a full range if no better information is available.
   return ConstantRange(getType());
 }
@@ -172,14 +171,6 @@
 }
 
 SCEVHandle SCEVConstant::get(ConstantInt *V) {
-  // Make sure that SCEVConstant instances are all unsigned.
-  // FIXME:Signless. This entire if statement can be removed when integer types
-  // are signless. There won't be a need to bitcast then.
-  if (V->getType()->isSigned()) {
-    const Type *NewTy = V->getType()->getUnsignedVersion();
-    V = cast<ConstantInt>(ConstantExpr::getBitCast(V, NewTy));
-  }
-
   SCEVConstant *&R = (*SCEVConstants)[V];
   if (R == 0) R = new SCEVConstant(V);
   return R;
@@ -310,9 +301,7 @@
 }
 
 const Type *SCEVSDivExpr::getType() const {
-  const Type *Ty = LHS->getType();
-  if (Ty->isUnsigned()) Ty = Ty->getSignedVersion();
-  return Ty;
+  return LHS->getType();
 }
 
 // SCEVAddRecExprs - Only allow the creation of one SCEVAddRecExpr for any
@@ -505,7 +494,7 @@
     uint64_t Result = 1;
     for (; NumSteps; --NumSteps)
       Result *= Val-(NumSteps-1);
-    Constant *Res = ConstantInt::get(Type::ULongTy, Result);
+    Constant *Res = ConstantInt::get(Type::Int64Ty, Result);
     return SCEVUnknown::get(ConstantExpr::getTruncOrBitCast(Res, V->getType()));
   }
 
@@ -1427,15 +1416,13 @@
     case Instruction::Trunc:
       // We don't handle trunc to bool yet.
       if (I->getType()->isInteger())
-        return SCEVTruncateExpr::get(getSCEV(I->getOperand(0)), 
-                                     I->getType()->getUnsignedVersion());
+        return SCEVTruncateExpr::get(getSCEV(I->getOperand(0)), I->getType());
       break;
 
     case Instruction::ZExt:
       // We don't handle zext from bool yet.
       if (I->getOperand(0)->getType()->isInteger())
-        return SCEVZeroExtendExpr::get(getSCEV(I->getOperand(0)), 
-                                       I->getType()->getUnsignedVersion());
+        return SCEVZeroExtendExpr::get(getSCEV(I->getOperand(0)), I->getType());
       break;
 
     case Instruction::BitCast:
@@ -1572,21 +1559,8 @@
           // Form the constant range.
           ConstantRange CompRange(Cond, CompVal);
 
-          // Now that we have it, if it's signed, convert it to an unsigned
-          // range.
-          // FIXME:Signless. This entire if statement can go away when 
-          // integers are signless.  ConstantRange is already signless.
-          if (CompRange.getLower()->getType()->isSigned()) {
-            const Type *NewTy = RHSC->getValue()->getType();
-            Constant *NewL = ConstantExpr::getBitCast(CompRange.getLower(), 
-                                                      NewTy);
-            Constant *NewU = ConstantExpr::getBitCast(CompRange.getUpper(), 
-                                                      NewTy);
-            CompRange = ConstantRange(NewL, NewU);
-          }
-
           SCEVHandle Ret = AddRec->getNumIterationsInRange(CompRange, 
-              ICmpInst::isSignedPredicate(Cond));
+              false /*Always treat as unsigned range*/);
           if (!isa<SCEVCouldNotCompute>(Ret)) return Ret;
         }
       }
@@ -1723,7 +1697,7 @@
   unsigned MaxSteps = MaxBruteForceIterations;
   for (unsigned IterationNum = 0; IterationNum != MaxSteps; ++IterationNum) {
     ConstantInt *ItCst =
-      ConstantInt::get(IdxExpr->getType()->getUnsignedVersion(), IterationNum);
+      ConstantInt::get(IdxExpr->getType(), IterationNum);
     ConstantInt *Val = EvaluateConstantChrecAtConstant(IdxExpr, ItCst);
 
     // Form the GEP offset.
@@ -1946,7 +1920,7 @@
     if (CondVal->getValue() == ExitWhen) {
       ConstantEvolutionLoopExitValue[PN] = PHIVal;
       ++NumBruteForceTripCountsComputed;
-      return SCEVConstant::get(ConstantInt::get(Type::UIntTy, IterationNum));
+      return SCEVConstant::get(ConstantInt::get(Type::Int32Ty, IterationNum));
     }
 
     // Compute the value of the PHI node for the next iteration.
@@ -2129,10 +2103,7 @@
   SqrtTerm = ConstantExpr::getSub(ConstantExpr::getMul(B, B), SqrtTerm);
 
   // Compute floor(sqrt(B^2-4ac))
-  ConstantInt *SqrtVal =
-    cast<ConstantInt>(ConstantExpr::getBitCast(SqrtTerm,
-                                   SqrtTerm->getType()->getUnsignedVersion()));
-  uint64_t SqrtValV = SqrtVal->getZExtValue();
+  uint64_t SqrtValV = cast<ConstantInt>(SqrtTerm)->getZExtValue();
   uint64_t SqrtValV2 = (uint64_t)sqrt((double)SqrtValV);
   // The square root might not be precise for arbitrary 64-bit integer
   // values.  Do some sanity checks to ensure it's correct.
@@ -2142,20 +2113,13 @@
     return std::make_pair(CNC, CNC);
   }
 
-  SqrtVal = ConstantInt::get(Type::ULongTy, SqrtValV2);
+  ConstantInt *SqrtVal = ConstantInt::get(Type::Int64Ty, SqrtValV2);
   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.
-  // FIXME:Signedness. These casts can all go away once integer types are
-  // signless.
-  const Type *SignedTy = NegB->getType()->getSignedVersion();
-  NegB = ConstantExpr::getBitCast(NegB, SignedTy);
-  TwoA = ConstantExpr::getBitCast(TwoA, SignedTy);
-  SqrtTerm = ConstantExpr::getBitCast(SqrtTerm, SignedTy);
-
   Constant *Solution1 =
     ConstantExpr::getSDiv(ConstantExpr::getAdd(NegB, SqrtTerm), TwoA);
   Constant *Solution2 =
@@ -2222,7 +2186,6 @@
            << "  sol#2: " << *R2 << "\n";
 #endif
       // Pick the smallest positive root value.
-      assert(R1->getType()->isUnsigned()&&"Didn't canonicalize to unsigned?");
       if (ConstantBool *CB =
           dyn_cast<ConstantBool>(ConstantExpr::getICmp(ICmpInst::ICMP_ULT, 
                                    R1->getValue(), R2->getValue()))) {
@@ -2448,7 +2411,6 @@
     SCEVConstant *R2 = dyn_cast<SCEVConstant>(Roots.second);
     if (R1) {
       // Pick the smallest positive root value.
-      assert(R1->getType()->isUnsigned() && "Didn't canonicalize to unsigned?");
       if (ConstantBool *CB =
           dyn_cast<ConstantBool>(ConstantExpr::getICmp(ICmpInst::ICMP_ULT, 
                                    R1->getValue(), R2->getValue()))) {






More information about the llvm-commits mailing list