llvm.org GIT mirror
Teach IVUsers to stop at non-affine expressions unless they are both outside the loop and reducible. This more completely hides them from LSR, which isn't usually able to do anything meaningful with non-affine expressions anyway, and this consequently hides them from SCEVExpander, which is acutely unprepared for non-affine expressions. Replace test/CodeGen/X86/lsr-nonaffine.ll with a new test that tests the new behavior. This works around the bug in PR10117 / rdar://problem/9633149, and is generally an improvement besides. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@134268 91177308-0d34-0410-b5e6-96231b3b80d8 Dan Gohman 8 years ago
2 changed file(s) with 35 addition(s) and 25 deletion(s).
 45 45 /// used by the given expression, within the context of analyzing the 46 46 /// given loop. 47 47 static bool isInteresting(const SCEV *S, const Instruction *I, const Loop *L, 48 ScalarEvolution *SE) {⏎ 48 ScalarEvolution *SE, LoopInfo *LI) {⏎ 49 49 // An addrec is interesting if it's affine or if it has an interesting start. 50 50 if (const SCEVAddRecExpr *AR = dyn_cast(S)) { 51 // Keep things simple. Don't touch loop-variant strides.⏎ 51 // Keep things simple. Don't touch loop-variant strides unless they're⏎ 52 // only used outside the loop and we can simplify them. 52 53 if (AR->getLoop() == L) 53 return AR->isAffine() || !L->contains(I);⏎ 54 return AR->isAffine() ||⏎ 55 (!L->contains(I) && 56 SE->getSCEVAtScope(AR, LI->getLoopFor(I->getParent())) != AR); 54 57 // Otherwise recurse to see if the start value is interesting, and that 55 58 // the step value is not interesting, since we don't yet know how to 56 59 // do effective SCEV expansions for addrecs with interesting steps. 57 return isInteresting(AR->getStart(), I, L, SE) && 58 !isInteresting(AR->getStepRecurrence(*SE), I, L, SE);⏎ 60 return isInteresting(AR->getStart(), I, L, SE, LI) &&⏎ 61 !isInteresting(AR->getStepRecurrence(*SE), I, L, SE, LI); 59 62 } 60 63 61 64 // An add is interesting if exactly one of its operands is interesting. 63 66 bool AnyInterestingYet = false; 64 67 for (SCEVAddExpr::op_iterator OI = Add->op_begin(), OE = Add->op_end(); 65 68 OI != OE; ++OI) 66 if (isInteresting(*OI, I, L, SE)) {⏎ 69 if (isInteresting(*OI, I, L, SE, LI)) {⏎ 67 70 if (AnyInterestingYet) 68 71 return false; 69 72 AnyInterestingYet = true; 97 100 98 101 // If we've come to an uninteresting expression, stop the traversal and 99 102 // call this a user. 100 if (!isInteresting(ISE, I, L, SE))⏎ 103 if (!isInteresting(ISE, I, L, SE, LI))⏎ 101 104 return false; 102 105 103 106 SmallPtrSet UniqueUsers;
 None ; RUN: llc -march=x86-64 < %s | FileCheck %s⏎ 0 ; RUN: llc -asm-verbose=false -march=x86-64 -o - < %s | FileCheck %s⏎ 1 1 2 ; LSR should compute the correct starting values for this loop. Note that 3 ; it's not necessarily LSR's job to compute loop exit expressions; that's 4 ; indvars' job. 5 ; CHECK: movl \$12 6 ; CHECK: movl \$42⏎ 2 ; LSR should leave non-affine expressions alone because it currently⏎ 3 ; doesn't know how to do anything with them, and when it tries, it 4 ; gets SCEVExpander's current expansion for them, which is suboptimal. 7 5 8 define i32 @real_symmetric_eigen(i32 %n) nounwind { 9 while.body127: ; preds = %while.cond122 10 br label %while.cond141⏎ 6 ; CHECK: xorl %eax, %eax⏎ 7 ; CHECK-NEXT: align 8 ; CHECK-NEXT: BB0_1: 9 ; CHECK-NEXT: movq %rax, (%rdx) 10 ; CHECK-NEXT: addq %rsi, %rax 11 ; CHECK-NEXT: cmpq %rdi, %rax 12 ; CHECK-NEXT: jl 13 ; CHECK-NEXT: imulq %rax, %rax 14 ; CHECK-NEXT: ret 15 define i64 @foo(i64 %n, i64 %s, i64* %p) nounwind { 16 entry: 17 br label %loop 11 18 12 while.cond141: ; preds = %while.cond141, %while.body127 13 %0 = phi i32 [ 7, %while.body127 ], [ %indvar.next67, %while.cond141 ] ; [#uses=3] 14 %indvar.next67 = add i32 %0, 1 ; [#uses=1] 15 %t = icmp slt i32 %indvar.next67, %n 16 br i1 %t, label %if.then171, label %while.cond141⏎ 19 loop:⏎ 20 %i = phi i64 [ 0, %entry ], [ %i.next, %loop ] 21 volatile store i64 %i, i64* %p 22 %i.next = add i64 %i, %s 23 %c = icmp slt i64 %i.next, %n 24 br i1 %c, label %loop, label %exit 17 25 18 if.then171: ; preds = %while.cond141 19 %mul150 = mul i32 %0, %0 ; [#uses=1] 20 %add174 = add i32 %mul150, %0 ; [#uses=1] 21 ret i32 %add174⏎ 26 exit:⏎ 27 %mul = mul i64 %i.next, %i.next 28 ret i64 %mul 22 29 }