Chris,

I'm wondering if you could look at this patch to LoopStrengthReduce.cpp.
It's the third (last change set) I'm asking about.  

I've converted the stride comparisons to use APInt. It seems unlikely
that strides will be > 64 bits. Is this overkill?

Reid.
Index: lib/Transforms/Scalar/LoopStrengthReduce.cpp
===================================================================
RCS file: /var/cvs/llvm/llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp,v
retrieving revision 1.109
diff -t -d -u -p -5 -r1.109 LoopStrengthReduce.cpp
--- lib/Transforms/Scalar/LoopStrengthReduce.cpp	10 Feb 2007 19:55:17 -0000	1.109
+++ lib/Transforms/Scalar/LoopStrengthReduce.cpp	1 Mar 2007 22:38:57 -0000
@@ -867,11 +867,11 @@ RemoveCommonExpressionsFromUseBases(std:
 
 /// isZero - returns true if the scalar evolution expression is zero.
 ///
 static bool isZero(SCEVHandle &V) {
   if (SCEVConstant *SC = dyn_cast<SCEVConstant>(V))
-    return SC->getValue()->getZExtValue() == 0;
+    return SC->getValue()->isNullValue();
   return false;
 }
 
 
 /// CheckForIVReuse - Returns the multiple if the stride is the multiple
@@ -881,30 +881,31 @@ static bool isZero(SCEVHandle &V) {
 unsigned LoopStrengthReduce::CheckForIVReuse(const SCEVHandle &Stride,
                                              IVExpr &IV, const Type *Ty) {
   if (!TLI) return 0;
 
   if (SCEVConstant *SC = dyn_cast<SCEVConstant>(Stride)) {
-    int64_t SInt = SC->getValue()->getSExtValue();
-    if (SInt == 1) return 0;
+    const APInt &SInt = SC->getValue()->getValue();
+    if (SInt == 1) 
+      return 0;
 
     for (TargetLowering::legal_am_scale_iterator
            I = TLI->legal_am_scale_begin(), E = TLI->legal_am_scale_end();
          I != E; ++I) {
-      unsigned Scale = *I;
-      if (unsigned(abs(SInt)) < Scale || (SInt % Scale) != 0)
+      APInt Scale(SInt.getBitWidth(), *I);
+      if (SInt.abs().ult(Scale) || SInt.srem(Scale) != 0)
         continue;
       std::map<SCEVHandle, IVsOfOneStride>::iterator SI =
-        IVsByStride.find(SCEVUnknown::getIntegerSCEV(SInt/Scale, UIntPtrTy));
+        IVsByStride.find(SCEVUnknown::getIntegerSCEV(SInt.sdiv(Scale)));
       if (SI == IVsByStride.end())
         continue;
       for (std::vector<IVExpr>::iterator II = SI->second.IVs.begin(),
              IE = SI->second.IVs.end(); II != IE; ++II)
         // FIXME: Only handle base == 0 for now.
         // Only reuse previous IV if it would not require a type conversion.
         if (isZero(II->Base) && II->Base->getType() == Ty) {
           IV = *II;
-          return Scale;
+          return Scale.getZExtValue();
         }
     }
   }
 
   return 0;
@@ -1255,18 +1256,21 @@ namespace {
   struct StrideCompare {
     bool operator()(const SCEVHandle &LHS, const SCEVHandle &RHS) {
       SCEVConstant *LHSC = dyn_cast<SCEVConstant>(LHS);
       SCEVConstant *RHSC = dyn_cast<SCEVConstant>(RHS);
       if (LHSC && RHSC) {
-        int64_t  LV = LHSC->getValue()->getSExtValue();
-        int64_t  RV = RHSC->getValue()->getSExtValue();
-        uint64_t ALV = (LV < 0) ? -LV : LV;
-        uint64_t ARV = (RV < 0) ? -RV : RV;
+        APInt LV(LHSC->getValue()->getValue());
+        APInt RV(RHSC->getValue()->getValue());
+        uint32_t MaxWidth = std::max(LV.getBitWidth(), RV.getBitWidth());
+        LV.sextOrTrunc(MaxWidth);
+        RV.sextOrTrunc(MaxWidth);
+        APInt ALV(LV.abs());
+        APInt ARV(RV.abs());
         if (ALV == ARV)
-          return LV > RV;
+          return LV.sgt(RV);
         else
-          return ALV < ARV;
+          return ALV.ult(ARV);
       }
       return (LHSC && !RHSC);
     }
   };
 }
_______________________________________________
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits

Reply via email to