Teach loop-reduce to see into nested loops, to pull out immediate values
authorChris Lattner <sabre@nondot.org>
Wed, 3 Aug 2005 23:44:42 +0000 (23:44 +0000)
committerChris Lattner <sabre@nondot.org>
Wed, 3 Aug 2005 23:44:42 +0000 (23:44 +0000)
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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@22639 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/Scalar/LoopStrengthReduce.cpp

index ddce7511042416f3f8ae905cdad1735387aefd6d..9a9b0c2aeca5b3e680948baab5ed8d3985cc4fc4 100644 (file)
@@ -483,8 +483,7 @@ static SCEVHandle GetImmediateValues(SCEVHandle Val, bool isAddress) {
   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 @@ static SCEVHandle GetImmediateValues(SCEVHandle Val, bool isAddress) {
             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());