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

            Bug ID: 84042
           Summary: IVOPTS doesn't optimize int indexes on some PowerPC
                    code.
           Product: gcc
           Version: 8.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: meissner at gcc dot gnu.org
  Target Milestone: ---

This is a follow-on to PR target/81550.

In that bug, the following code generated more code.  That in turn caused the
test to fail that was looking for a loop to be 8 instructions or less to test
the TARGET_ASM_LOOP_ALIGN_MAX_SKIP target hook:

void f(double *a, double *b, double *c, int n) {
  int i;
  for (i=0; i < n; i++)
    a[i] = b[i] + c[i];
}

I rewrote the test to use unsigned long instead of int so that the # of
instructions is under 8, and it validates the target hook.

But we really should fix the regression.

As per PR target/81550, the original code on powerpc little endian was:

        .file   "loop_align.c"
        .abiversion 2
        .section        ".text"
        .align 2
        .p2align 4,,15
        .globl f
        .type   f, @function
f:
        cmpwi 7,6,0
        blelr 7
        addi 6,6,-1
        li 9,0
        rldicl 6,6,0,32
        addi 10,6,1
        mtctr 10
        .p2align 5,,31
.L3:
        lfdx 0,4,9
        lfdx 12,5,9
        fadd 0,0,12
        stfdx 0,3,9
        addi 9,9,8
        bdnz .L3
        blr
        .file   "loop_align.c"
        .abiversion 2
        .section        ".text"
        .align 2
        .p2align 4,,15
        .globl f
        .type   f, @function
f:
        cmpwi 7,6,0
        blelr 7
        addi 6,6,-1
        addi 9,4,-8
        rldic 6,6,3,29
        addi 5,5,-8
        add 4,4,6
        addi 3,3,-8
        .p2align 4,,15
.L3:
        lfdu 0,8(9)
        lfdu 12,8(5)
        cmpld 7,9,4
        fadd 0,0,12
        stfdu 0,8(3)
        beqlr 7
        lfdu 0,8(9)
        lfdu 12,8(5)
        cmpld 7,9,4
        fadd 0,0,12
        stfdu 0,8(3)
        bne 7,.L3
        blr

The first observation is the count down loop is no longer done (i.e. no BDNZ). 
Because it no longer is a count down loop, reorder blocks decided to clone the
block and have an early exit.  This all makes the loop to be 12 instructions,
which causes the TARGET_ASM_LOOP_ALIGN_MAX_SKIP target hook to fail.

Reply via email to