[llvm-bugs] [Bug 52078] New: Dead Code Elimination Regression at -O3 (trunk vs 13.0.0)

via llvm-bugs llvm-bugs at lists.llvm.org
Tue Oct 5 05:36:05 PDT 2021


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

            Bug ID: 52078
           Summary: Dead Code Elimination Regression at -O3  (trunk vs
                    13.0.0)
           Product: new-bugs
           Version: trunk
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: enhancement
          Priority: P
         Component: new bugs
          Assignee: unassignedbugs at nondot.org
          Reporter: theodoros.theodoridis at inf.ethz.ch
                CC: htmldeveloper at gmail.com, llvm-bugs at lists.llvm.org

cat case.c   
static int b = -1, e = 1;
static short c, d;
void foo(void);
short a(unsigned short f, int g) { return f >> g; }
int main() {
  c++;
  d = a(4294967295 + (c > 0), 1);
  e ^= (short)(d * 3) / (unsigned)b;
  if (!e)
    foo();
}

trunk can no longer eliminate foo and it generates more complicated code:

clang-13 -v 
clang version 13.0.0 (https://github.com/llvm/llvm-project.git
d7b669b3a30345cfcdb2fde2af6f48aa4b94845d)
Target: x86_64-unknown-linux-gnu

clang-13 -S case.c -O3 -o /dev/stdout   
...
main:                                   # @main
        .cfi_startproc
# %bb.0:
        addw    $1, c(%rip)
        xorl    %eax, %eax
        retq

clang-trunk -v      
clang version 14.0.0 (https://github.com/llvm/llvm-project.git
424733c12aacc227a28114deba72061153f8dff2)
Target: x86_64-unknown-linux-gnu

clang-trunk -S case.c -O3 -o /dev/stdout 
...
main:                                   # @main
        .cfi_startproc
# %bb.0:
        pushq   %rax
        .cfi_def_cfa_offset 16
        movzwl  c(%rip), %eax
        leal    1(%rax), %ecx
        movw    %cx, c(%rip)
        xorl    %ecx, %ecx
        cmpl    $32767, %eax                    # imm = 0x7FFF
        adcl    $-1, %ecx
        movzwl  %cx, %eax
        shrl    %eax
        leal    (%rax,%rax,2), %eax
        xorl    %ecx, %ecx
        cmpw    $-1, %ax
        sete    %cl
        xorl    %ecx, e(%rip)
        je      .LBB1_1
# %bb.2:
        xorl    %eax, %eax
        popq    %rcx
        .cfi_def_cfa_offset 8
        retq
.LBB1_1:
        .cfi_def_cfa_offset 16
        callq   foo
        xorl    %eax, %eax
        popq    %rcx
        .cfi_def_cfa_offset 8
        retq

commit cfb6dfcbd13b417f83d8adca69b60ba4254b4233 introduced this regression

-- 
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/20211005/601620bf/attachment.html>


More information about the llvm-bugs mailing list