[llvm-bugs] [Bug 31557] New: Missed induction variable optimization

via llvm-bugs llvm-bugs at lists.llvm.org
Thu Jan 5 15:41:28 PST 2017


https://llvm.org/bugs/show_bug.cgi?id=31557

            Bug ID: 31557
           Summary: Missed induction variable optimization
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: Scalar Optimizations
          Assignee: unassignedbugs at nondot.org
          Reporter: carrot at google.com
                CC: llvm-bugs at lists.llvm.org
    Classification: Unclassified

Compile the following code with options

--target=powerpc64le-grtev4-linux-gnu -m64 -O2 -mvsx -mcpu=power8 

extern void bar(int);

void foo(const int* p, int n) {
    for (int j = 0; j < n; ++j) {
      int k = p[j];
      bar(k);
    }
}


I got:

        clrldi   30, 4, 32
        addi 4, 3, -4
        .p2align        5
.LBB0_2:                                # %for.body
                                        # =>This Inner Loop Header: Depth=1
        lwa 3, 4(4)
        addi 29, 4, 4
        bl _Z3bari
        nop
        addi 30, 30, -1                
        mr 4, 29
        cmpldi   30, 0
        bne      0, .LBB0_2


Var j is an induction variable, it is only used to index an array, so it can be
optimized away, like following

        clrldi   30, 4, 32
        sldi     30, 30, 2              // *
        add      30, 30, 4              // *
        addi 4, 3, -4
        .p2align        5
.LBB0_2:                                # %for.body
                                        # =>This Inner Loop Header: Depth=1
        lwa 3, 4(4)
        addi 29, 4, 4
        bl _Z3bari
        nop
//        addi 30, 30, -1               
        mr 4, 29
        cmpld    30, 29                 // *
        bne      0, .LBB0_2

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20170105/09042071/attachment.html>


More information about the llvm-bugs mailing list