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

            Bug ID: 110918
           Summary: [14 Regression] Dead Code Elimination Regression at
                    -O3 since r14-2331-g018e7f16408
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: scherrer.sv at gmail dot com
  Target Milestone: ---

static char b = 53;
static unsigned c;
void foo(void);
static int(a)(int d, int e) { return (d ^ e) < 0 ? d : d - e; }
int main() {
  {
    int f = 2;
    c = b;
    b = 0;
    for (; c <= 6;) {
      if (f >= 2)
        f = 0;
      for (; f >= -9; f = a(f, 8))
        if (!(f >= -8 && f <= 0))
          foo();
    }
  }
}

gcc-87b0749cfb9 (trunk) -O3 cannot eliminate the call to foo but
gcc-releases/gcc-13.1.0 -O3 can.
-----------------------------------------------------------------------
gcc-87b0749cfb9406790b108208b466cf507ae3c431 -O3 case.c -S -o case.s
--------- OUTPUT ---------
main:
.LFB1:
        .cfi_startproc
        movsbl  b(%rip), %eax
        pushq   %rbx
        .cfi_def_cfa_offset 16
        .cfi_offset 3, -16
        xorl    %ebx, %ebx
        movb    $0, b(%rip)
        movl    %eax, c(%rip)
        cmpl    $6, %eax
        ja      .L11
        .p2align 4,,10
        .p2align 3
.L2:
        leal    8(%rbx), %eax
        cmpl    $8, %eax
        ja      .L16
.L3:
        cmpl    $-8, %ebx
        je      .L5
        cmpl    $-1, %ebx
        jl      .L6
        movl    $-8, %ebx
        leal    8(%rbx), %eax
        cmpl    $8, %eax
        jbe     .L3
.L16:
        call    foo
        subl    $8, %ebx
        jmp     .L2
.L5:
        jmp     .L5
        .p2align 4,,10
        .p2align 3
.L6:
        cmpl    $6, c(%rip)
        ja      .L11
.L8:
        jmp     .L8
        .p2align 4,,10
        .p2align 3
.L11:
        xorl    %eax, %eax
        popq    %rbx
        .cfi_def_cfa_offset 8
        ret
---------- END OUTPUT ---------

-----------------------------------------------------------------------
gcc-2b98cc24d6af0432a74f6dad1c722ce21c1f7458 -O3 case.c -S -o case.s
--------- OUTPUT ---------
main:
.LFB1:
        .cfi_startproc
        movsbl  b(%rip), %edx
        xorl    %eax, %eax
        movb    $0, b(%rip)
        movl    %edx, c(%rip)
        cmpl    $6, %edx
        ja      .L8
        .p2align 4,,10
        .p2align 3
.L2:
        testl   %eax, %eax
        js      .L3
        subl    $8, %eax
        cmpl    $-9, %eax
        jge     .L2
        cmpl    $6, c(%rip)
        ja      .L8
.L6:
        jmp     .L6
.L3:
        jmp     .L3
        .p2align 4,,10
        .p2align 3
.L8:
        xorl    %eax, %eax
        ret
---------- END OUTPUT ---------

-----------------------------------------------------------------------
Bisects to r14-2331-g018e7f16408

Reply via email to