Quuxplusone / LLVMBugzillaTest

0 stars 0 forks source link

Dead Code Elimination Regression at -O3 (trunk vs 13.0.0) #51559

Open Quuxplusone opened 2 years ago

Quuxplusone commented 2 years ago
Bugzilla Link PR52592
Status NEW
Importance P enhancement
Reported by Theodoros Theodoridis (theodort@inf.ethz.ch)
Reported on 2021-11-23 11:05:13 -0800
Last modified on 2021-11-23 11:05:38 -0800
Version trunk
Hardware PC Linux
CC aeubanks@google.com, htmldeveloper@gmail.com, llvm-bugs@lists.llvm.org, theodort@inf.ethz.ch
Fixed by commit(s)
Attachments
Blocks
Blocked by
See also
cat case.c
void bar(void);
void foo(void);

static char b = 1;
static int c;

static int d(int e) { return e; }

int main() {
  b = 0;
  bar();
  c = d(2048);
  if (!((((0 == c || b) && 1) ^ 2)% 5))
  {
    d(0);
    foo();
  }
}

trunk cannot eliminate the call to foo but 13.0.0 can:

clang-13.0.0 -O3 -S -o /dev/stdout case.c
main:                                   # @main
    .cfi_startproc
# %bb.0:
    pushq   %rax
    .cfi_def_cfa_offset 16
    callq   bar
    xorl    %eax, %eax
    popq    %rcx
    .cfi_def_cfa_offset 8
    retq
.Lfunc_end0:

clang-trunk -O3 -S -o /dev/stdout case.c
main:                                   # @main
    .cfi_startproc
# %bb.0:
    pushq   %rax
    .cfi_def_cfa_offset 16
    movb    $1, b(%rip)
    callq   bar
    movzbl  b(%rip), %eax
    xorl    $1, %eax
    orl $2, %eax
    imull   $-858993459, %eax, %eax         # imm = 0xCCCCCCCD
    cmpl    $858993459, %eax                # imm = 0x33333333
    jbe .LBB0_1
# %bb.2:
    xorl    %eax, %eax
    popq    %rcx
    .cfi_def_cfa_offset 8
    retq
.LBB0_1:
    .cfi_def_cfa_offset 16
    callq   foo
    xorl    %eax, %eax
    popq    %rcx
    .cfi_def_cfa_offset 8
    retq
.Lfunc_end0:

clang-trunk -v
clang version 14.0.0 (https://github.com/llvm/llvm-project
38ed1db7e8740fce236d1893ff9e20cc22ef0ada)
Target: x86_64-unknown-linux-gnu
Thread model: posix

Started with https://github.com/llvm/llvm-
project/commit/e7249e4acf3cf9438d6d9e02edecebd5b622a4dc