[llvm-commits] [llvm] r134268 - in /llvm/trunk: lib/Analysis/IVUsers.cpp test/CodeGen/X86/lsr-nonaffine.ll

Francois Pichet pichet2000 at gmail.com
Fri Jul 1 20:17:18 PDT 2011


On Fri, Jul 1, 2011 at 6:05 PM, Dan Gohman <gohman at apple.com> wrote:
> Author: djg
> Date: Fri Jul  1 17:05:19 2011
> New Revision: 134268
>
> URL: http://llvm.org/viewvc/llvm-project?rev=134268&view=rev
> Log:
> 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.
>
> Modified:
>    llvm/trunk/lib/Analysis/IVUsers.cpp
>    llvm/trunk/test/CodeGen/X86/lsr-nonaffine.ll
>
> Modified: llvm/trunk/lib/Analysis/IVUsers.cpp
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/IVUsers.cpp?rev=134268&r1=134267&r2=134268&view=diff
> ==============================================================================
> --- llvm/trunk/lib/Analysis/IVUsers.cpp (original)
> +++ llvm/trunk/lib/Analysis/IVUsers.cpp Fri Jul  1 17:05:19 2011
> @@ -46,17 +46,20 @@
>  /// used by the given expression, within the context of analyzing the
>  /// given loop.
>  static bool isInteresting(const SCEV *S, const Instruction *I, const Loop *L,
> -                          ScalarEvolution *SE) {
> +                          ScalarEvolution *SE, LoopInfo *LI) {
>   // An addrec is interesting if it's affine or if it has an interesting start.
>   if (const SCEVAddRecExpr *AR = dyn_cast<SCEVAddRecExpr>(S)) {
> -    // Keep things simple. Don't touch loop-variant strides.
> +    // Keep things simple. Don't touch loop-variant strides unless they're
> +    // only used outside the loop and we can simplify them.
>     if (AR->getLoop() == L)
> -      return AR->isAffine() || !L->contains(I);
> +      return AR->isAffine() ||
> +             (!L->contains(I) &&
> +              SE->getSCEVAtScope(AR, LI->getLoopFor(I->getParent())) != AR);
>     // Otherwise recurse to see if the start value is interesting, and that
>     // the step value is not interesting, since we don't yet know how to
>     // do effective SCEV expansions for addrecs with interesting steps.
> -    return isInteresting(AR->getStart(), I, L, SE) &&
> -          !isInteresting(AR->getStepRecurrence(*SE), I, L, SE);
> +    return isInteresting(AR->getStart(), I, L, SE, LI) &&
> +          !isInteresting(AR->getStepRecurrence(*SE), I, L, SE, LI);
>   }
>
>   // An add is interesting if exactly one of its operands is interesting.
> @@ -64,7 +67,7 @@
>     bool AnyInterestingYet = false;
>     for (SCEVAddExpr::op_iterator OI = Add->op_begin(), OE = Add->op_end();
>          OI != OE; ++OI)
> -      if (isInteresting(*OI, I, L, SE)) {
> +      if (isInteresting(*OI, I, L, SE, LI)) {
>         if (AnyInterestingYet)
>           return false;
>         AnyInterestingYet = true;
> @@ -98,7 +101,7 @@
>
>   // If we've come to an uninteresting expression, stop the traversal and
>   // call this a user.
> -  if (!isInteresting(ISE, I, L, SE))
> +  if (!isInteresting(ISE, I, L, SE, LI))
>     return false;
>
>   SmallPtrSet<Instruction *, 4> UniqueUsers;
>
> Modified: llvm/trunk/test/CodeGen/X86/lsr-nonaffine.ll
> URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/lsr-nonaffine.ll?rev=134268&r1=134267&r2=134268&view=diff
> ==============================================================================
> --- llvm/trunk/test/CodeGen/X86/lsr-nonaffine.ll (original)
> +++ llvm/trunk/test/CodeGen/X86/lsr-nonaffine.ll Fri Jul  1 17:05:19 2011
> @@ -1,23 +1,30 @@
> -; RUN: llc -march=x86-64 < %s | FileCheck %s
> +; RUN: llc -asm-verbose=false -march=x86-64 -o - < %s | FileCheck %s
>
> -; LSR should compute the correct starting values for this loop. Note that
> -; it's not necessarily LSR's job to compute loop exit expressions; that's
> -; indvars' job.
> -; CHECK: movl  $12
> -; CHECK: movl  $42
> +; LSR should leave non-affine expressions alone because it currently
> +; doesn't know how to do anything with them, and when it tries, it
> +; gets SCEVExpander's current expansion for them, which is suboptimal.
>
> -define i32 @real_symmetric_eigen(i32 %n) nounwind {
> -while.body127:                                    ; preds = %while.cond122
> -  br label %while.cond141
> +; CHECK:        xorl %eax, %eax
> +; CHECK-NEXT:   align
> +; CHECK-NEXT: BB0_1:
> +; CHECK-NEXT:   movq  %rax, (%rdx)
> +; CHECK-NEXT:   addq  %rsi, %rax
> +; CHECK-NEXT:   cmpq  %rdi, %rax
> +; CHECK-NEXT:   jl
> +; CHECK-NEXT:   imulq %rax, %rax
> +; CHECK-NEXT:   ret

This fails under MSVC:
The output is instead:
foo:
        xorl    %eax, %eax
        .align  16, 0x90
.LBB0_1:
        movq    %rax, (%r8)
        addq    %rdx, %rax
        cmpq    %rcx, %rax
        jl      .LBB0_1
        imulq   %rax, %rax
        ret

Any idea?




More information about the llvm-commits mailing list