[llvm-commits] CVS: llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp

Chris Lattner lattner at cs.uiuc.edu
Wed Aug 3 16:44:53 PDT 2005



Changes in directory llvm/lib/Transforms/Scalar:

LoopStrengthReduce.cpp updated: 1.26 -> 1.27
---
Log message:

Teach loop-reduce to see into nested loops, to pull out immediate values
pushed down by SCEV.

In a nested loop case, this allows us to emit this:

        lis r3, ha16(L_A$non_lazy_ptr)
        lwz r3, lo16(L_A$non_lazy_ptr)(r3)
        add r2, r2, r3
        li r3, 1
.LBB_foo_2:     ; no_exit.1
        lfd f0, 8(r2)        ;; Uses offset of 8 instead of 0
        stfd f0, 0(r2)
        addi r4, r3, 1
        addi r2, r2, 8
        cmpwi cr0, r3, 100
        or r3, r4, r4
        bne .LBB_foo_2  ; no_exit.1

instead of this:

        lis r3, ha16(L_A$non_lazy_ptr)
        lwz r3, lo16(L_A$non_lazy_ptr)(r3)
        add r2, r2, r3
        addi r3, r3, 8
        li r4, 1
.LBB_foo_2:     ; no_exit.1
        lfd f0, 0(r3)
        stfd f0, 0(r2)
        addi r5, r4, 1
        addi r2, r2, 8
        addi r3, r3, 8
        cmpwi cr0, r4, 100
        or r4, r5, r5
        bne .LBB_foo_2  ; no_exit.1



---
Diffs of the changes:  (+4 -2)

 LoopStrengthReduce.cpp |    6 ++++--
 1 files changed, 4 insertions(+), 2 deletions(-)


Index: llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp
diff -u llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp:1.26 llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp:1.27
--- llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp:1.26	Wed Aug  3 18:30:08 2005
+++ llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp	Wed Aug  3 18:44:42 2005
@@ -483,8 +483,7 @@
   if (isTargetConstant(Val))
     return Val;
 
-  SCEVAddExpr *SAE = dyn_cast<SCEVAddExpr>(Val);
-  if (SAE) {
+  if (SCEVAddExpr *SAE = dyn_cast<SCEVAddExpr>(Val)) {
     unsigned i = 0;
     for (; i != SAE->getNumOperands(); ++i)
       if (isTargetConstant(SAE->getOperand(i))) {
@@ -497,6 +496,9 @@
             ImmVal = SCEVAddExpr::get(ImmVal, SAE->getOperand(i));
         return ImmVal;
       }
+  } else if (SCEVAddRecExpr *SARE = dyn_cast<SCEVAddRecExpr>(Val)) {
+    // Try to pull immediates out of the start value of nested addrec's.
+    return GetImmediateValues(SARE->getStart(), isAddress);
   }
 
   return SCEVUnknown::getIntegerSCEV(0, Val->getType());






More information about the llvm-commits mailing list