| Issue |
56048
|
| Summary |
Dead Code Elimination Regression at -O3 (trunk vs. 14.0.4)
|
| Labels |
|
| Assignees |
|
| Reporter |
thetheodor
|
```c
static short c, d;
void foo();
char a();
static long e(short f) { return f & (f - 1) ? 0 : f - 1; }
int main() {
for (int h = 1; h; h = e(h))
for (; d < 1; d += 1) {
c = h;
if (c + 1 == h) {
foo();
h == 1 || a();
}
}
}
```
`llvm-4c2bccfda3892ae13e97b6bfdbc99ec8cf5d095d (trunk) -O3` can not eliminate `foo` but `llvm-llvmorg-14.0.4 -O3` can.
Target: `x86_64-unknown-linux-gnu`
------------------------------------------------
`llvm-4c2bccfda3892ae13e97b6bfdbc99ec8cf5d095d (trunk) -O3 [-emit-llvm] -S -o /dev/stdout case.c`
<details ><summary>Reduced assembly</summary><p>
```asm
main: # @main
.cfi_startproc
# %bb.0:
pushq %rbp
.cfi_def_cfa_offset 16
pushq %rbx
.cfi_def_cfa_offset 24
pushq %rax
.cfi_def_cfa_offset 32
.cfi_offset %rbx, -24
.cfi_offset %rbp, -16
movzwl d(%rip), %eax
testw %ax, %ax
jle .LBB0_1
.LBB0_10:
xorl %eax, %eax
addq $8, %rsp
.cfi_def_cfa_offset 24
popq %rbx
.cfi_def_cfa_offset 16
popq %rbp
.cfi_def_cfa_offset 8
retq
.LBB0_1:
.cfi_def_cfa_offset 32
movl $1, %ecx
xorl %ebp, %ebp
jmp .LBB0_2
.p2align 4, 0x90
.LBB0_9: # in Loop: Header=BB0_2 Depth=1
leal -1(%rbx), %ecx
testl %ecx, %ebx
cmovnel %ebp, %ecx
testl %ecx, %ecx
je .LBB0_10
.LBB0_2: # =>This Loop Header: Depth=1
# Child Loop BB0_7 Depth 2
# Child Loop BB0_6 Depth 2
# Child Loop BB0_5 Depth 2
movswl %cx, %ebx
testw %ax, %ax
jg .LBB0_9
# %bb.3: # in Loop: Header=BB0_2 Depth=1
leal 1(%rbx), %edx
cmpl %ecx, %edx
jne .LBB0_7
# %bb.4: # in Loop: Header=BB0_2 Depth=1
cmpl $1, %ecx
jne .LBB0_6
.p2align 4, 0x90
.LBB0_5: # Parent Loop BB0_2 Depth=1
# => This Inner Loop Header: Depth=2
xorl %eax, %eax
callq foo@PLT
movzwl d(%rip), %ecx
leal 1(%rcx), %eax
movw %ax, d(%rip)
cmpl $32766, %ecx # imm = 0x7FFE
ja .LBB0_5
jmp .LBB0_9
.p2align 4, 0x90
.LBB0_7: # Parent Loop BB0_2 Depth=1
# => This Inner Loop Header: Depth=2
# kill: def $ax killed $ax killed $eax def $rax
movzwl %ax, %ecx
incl %eax
cmpl $32766, %ecx # imm = 0x7FFE
ja .LBB0_7
# %bb.8: # in Loop: Header=BB0_2 Depth=1
movw %ax, d(%rip)
movw $1, %ax
jmp .LBB0_9
.p2align 4, 0x90
.LBB0_6: # Parent Loop BB0_2 Depth=1
# => This Inner Loop Header: Depth=2
xorl %eax, %eax
callq foo@PLT
xorl %eax, %eax
callq a@PLT
movzwl d(%rip), %ecx
leal 1(%rcx), %eax
movw %ax, d(%rip)
cmpl $32766, %ecx # imm = 0x7FFE
ja .LBB0_6
jmp .LBB0_9
.Lfunc_end0:
.size main, .Lfunc_end0-main
```
</p></details>
------------------------------------------------
`llvm-llvmorg-14.0.4 -O3 [-emit-llvm] -S -o /dev/stdout case.c`
<details ><summary>Reduced assembly</summary><p>
```asm
main: # @main
.cfi_startproc
# %bb.0:
movzwl d(%rip), %eax
testw %ax, %ax
jle .LBB0_1
# %bb.3:
xorl %eax, %eax
retq
.p2align 4, 0x90
.LBB0_1: # =>This Inner Loop Header: Depth=1
# kill: def $ax killed $ax killed $eax def $rax
movzwl %ax, %ecx
addl $1, %eax
cmpl $32766, %ecx # imm = 0x7FFE
ja .LBB0_1
# %bb.2:
movw %ax, d(%rip)
xorl %eax, %eax
retq
.Lfunc_end0:
.size main, .Lfunc_end0-main
```
</p></details>
------------------------------------------------
### Bisection
Bisected to: 6001bfcedc3102b45878b7883c241b45863d7e2c
Committed by: @nikic
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs