[llvm-bugs] [Bug 26913] New: [AArch64] Loop counter duplicated during strength reduction for some 1-based loops

via llvm-bugs llvm-bugs at lists.llvm.org
Fri Mar 11 08:45:22 PST 2016


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

            Bug ID: 26913
           Summary: [AArch64] Loop counter duplicated during strength
                    reduction for some 1-based loops
           Product: libraries
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: Scalar Optimizations
          Assignee: unassignedbugs at nondot.org
          Reporter: chris at diamand.org
                CC: llvm-bugs at lists.llvm.org, mcrosier at codeaurora.org
    Classification: Unclassified

In some cases, the LoopStrengthReduce pass will duplicate the loop counter
unnecessarily. One example of this is the SingleSource/Benchmarks/Stanford/Perm
test.

For example, the following has its loop counter duplicated:

volatile int permarray[12];

void minimal_permute1(int n) {
    int k;
    for (k = n - 1; k >= 1; k--) {
        minimal_permute1(n - 1);
        permarray[k] = k;
    }
}

The generated loop body is:

.LBB0_2:                                // %for.body
                                        // =>This Inner Loop Header: Depth=1
    mov     w0, w19
    sub    x23, x22, #1            // =1
    bl    minimal_permute1
    add    x8, x21, x22, lsl #2
    cmp        x23, #1         // =1
    mov     x22, x23
    stur    w20, [x8, #-4]
    sub    w20, w20, #1            // =1
    b.gt    .LBB0_2

x23 and w20 are both holding the same value, but x23 is used as a 64-bit loop
counter, and w20 is the value stored in the array.

However, if I substitute k -> k + 1, to get the following equivalent loop:

void minimal_permute0(int n) {
    int k;
    for (k = n - 2; k >= 0; k--) {
        minimal_permute0(n - 1);
        permarray[k + 1] = k + 1;
    }
}

Only one loop counter is used:

.LBB0_2:                                // %for.body
                                        // =>This Inner Loop Header: Depth=1
    mov     w0, w19
    bl    minimal_permute0
    str    w20, [x21, x20, lsl #2]
    sub    x20, x20, #1            // =1
    cmp        x20, #0         // =0
    b.gt    .LBB0_2

This is caused by something in LoopStrengthReduce (verified with llc
-disable-lsr). I believe it's linked to having a 32-bit loop counter on a
64-bit arch.

This only happens when targeting AArch64. X86 and ARM are not affected.

-- 
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/20160311/ac7d2996/attachment.html>


More information about the llvm-bugs mailing list