https://gcc.gnu.org/bugzilla/show_bug.cgi?id=118213

            Bug ID: 118213
           Summary: IVOPT causes superfluous IVs
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: fxue at os dot amperecomputing.com
  Target Milestone: ---

See the case,

  int foo(char *a, char *b, int s, int n)
  {
     while (++s != n) {
       if (a[s] != b[s])
         break;
     }
     return s;
  }

Originally, memory accesses to "a[]" and "b[]" own a same IV, while after
IVOPT, two IVs are generated for each access respectively, difference between
the IVs is 1. This would cause some superfluous IV-related computation in both
loop prolog and body. On aarch64, we would get below suboptimal code-gen:

.LFB0:
        .cfi_startproc
        add     w2, w2, 1
        mov     x6, x0
        sub     x1, x1, #1
        sxtw    x0, w2
        b       .L2
        .p2align 2,,3
.L3:
        ldrb    w5, [x6, x0]   #base: x6 = a,     index: x0 
        ldrb    w4, [x1, x2]   #base: x1 = b - 1, index: x2 = x0 + 1 
        cmp     w5, w4
        bne     .L6
        mov     x0, x2
.L2:
        add     x2, x0, 1
        cmp     w3, w0
        bne     .L3
.L6:
        ret
  • [Bug tree-optimization/118... fxue at os dot amperecomputing.com via Gcc-bugs

Reply via email to