| Issue |
52965
|
| Summary |
Dead Code Elimination Regression at -Os (trunk vs. 13.0.0)
|
| Labels |
new issue
|
| Assignees |
|
| Reporter |
Quarub
|
`cat case.c`
```c
char b;
static int c = 1, e, f = 7, g;
short h, i;
void foo(void);
char(a)(char j, char k) { return k == 0 ? j : j / k; }
void(d)();
int main() {
c = a(0, 0);
for (; h < 1; ++h) {
f = 8 <= e;
g = i = c;
if (c) {
b = e = f |= b;
f &= d && g;
}
if (!a(1, f))
foo();
}
}
```
`clang-550ea385abc2805fd3e0a539bf55bc82edb5c13e (trunk) -Os` can not eliminate `foo` but `clang-llvmorg-13.0.0 -Os` can.
`clang-550ea385abc2805fd3e0a539bf55bc82edb5c13e (trunk) -Os -S -o /dev/stdout case.c`
<details ><summary>Output</summary><p>
```asm
.text
.file "case.c"
.globl a # -- Begin function a
.type a,@function
a: # @a
.cfi_startproc
# %bb.0:
movl %edi, %eax
testb %sil, %sil
je .LBB0_2
# %bb.1:
movsbl %al, %eax
movsbl %sil, %ecx
# kill: def $ax killed $ax killed $eax
cwtd
idivw %cx
# kill: def $ax killed $ax def $eax
.LBB0_2:
# kill: def $al killed $al killed $eax
retq
.Lfunc_end0:
.size a, .Lfunc_end0-a
.cfi_endproc
# -- End function
.globl main # -- Begin function main
.type main,@function
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
movb $1, c(%rip)
movzwl h(%rip), %eax
testw %ax, %ax
jg .LBB1_7
# %bb.1:
xorl %ecx, %ecx
movl e(%rip), %edx
movb $1, %bpl
.LBB1_2: # =>This Inner Loop Header: Depth=1
xorl %esi, %esi
cmpl $8, %edx
setge %bl
movw %cx, i(%rip)
testl %ecx, %ecx
je .LBB1_4
# %bb.3: # in Loop: Header=BB1_2 Depth=1
movb %bl, %sil
movsbl b(%rip), %edx
orl %esi, %edx
movl %edx, e(%rip)
movb %dl, b(%rip)
.LBB1_4: # in Loop: Header=BB1_2 Depth=1
testb %bpl, %bpl
jne .LBB1_6
# %bb.5: # in Loop: Header=BB1_2 Depth=1
callq foo
movl e(%rip), %edx
movzbl c(%rip), %ecx
xorl $1, %ecx
movzwl h(%rip), %eax
.LBB1_6: # in Loop: Header=BB1_2 Depth=1
movzwl %ax, %esi
incl %eax
movw %ax, h(%rip)
# kill: def $ax killed $ax killed $eax def $rax
cmpl $32766, %esi # imm = 0x7FFE
ja .LBB1_2
.LBB1_7:
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
.Lfunc_end1:
.size main, .Lfunc_end1-main
.cfi_endproc
# -- End function
.type c,@object # @c
.local c
.comm c,1,4
.type h,@object # @h
.bss
.globl h
.p2align 1
h:
.short 0 # 0x0
.size h, 2
.type e,@object # @e
.local e
.comm e,4,4
.type i,@object # @i
.globl i
.p2align 1
i:
.short 0 # 0x0
.size i, 2
.type b,@object # @b
.globl b
b:
.byte 0 # 0x0
.size b, 1
.ident "clang version 14.0.0 (https://github.com/llvm/llvm-project.git 550ea385abc2805fd3e0a539bf55bc82edb5c13e)"
.section ".note.GNU-stack","",@progbits
.addrsig
```
</p></details>
`clang-llvmorg-13.0.0 -Os -S -o /dev/stdout case.c`
<details ><summary>Output</summary><p>
```asm
.text
.file "case.c"
.globl a # -- Begin function a
.type a,@function
a: # @a
.cfi_startproc
# %bb.0:
movl %edi, %eax
testb %sil, %sil
je .LBB0_2
# %bb.1:
movsbl %al, %eax
movsbl %sil, %ecx
# kill: def $ax killed $ax killed $eax
cwtd
idivw %cx
# kill: def $ax killed $ax def $eax
.LBB0_2:
# kill: def $al killed $al killed $eax
retq
.Lfunc_end0:
.size a, .Lfunc_end0-a
.cfi_endproc
# -- End function
.globl main # -- Begin function main
.type main,@function
main: # @main
.cfi_startproc
# %bb.0:
movb $1, c(%rip)
movzwl h(%rip), %eax
testw %ax, %ax
jg .LBB1_6
# %bb.1:
movl e(%rip), %edx
movzbl c(%rip), %r8d
xorl $1, %r8d
xorl %ecx, %ecx
.LBB1_2: # =>This Inner Loop Header: Depth=1
movl %ecx, %r9d
testl %ecx, %ecx
je .LBB1_4
# %bb.3: # in Loop: Header=BB1_2 Depth=1
xorl %ecx, %ecx
cmpl $8, %edx
setge %cl
movsbl b(%rip), %edx
orl %ecx, %edx
movl %edx, e(%rip)
movb %dl, b(%rip)
.LBB1_4: # in Loop: Header=BB1_2 Depth=1
leal 1(%rax), %edi
movzwl %ax, %esi
movl %edi, %eax
movl %r8d, %ecx
cmpl $32766, %esi # imm = 0x7FFE
ja .LBB1_2
# %bb.5:
movw %r9w, i(%rip)
movw %di, h(%rip)
.LBB1_6:
xorl %eax, %eax
retq
.Lfunc_end1:
.size main, .Lfunc_end1-main
.cfi_endproc
# -- End function
.type c,@object # @c
.local c
.comm c,1,4
.type h,@object # @h
.bss
.globl h
.p2align 1
h:
.short 0 # 0x0
.size h, 2
.type e,@object # @e
.local e
.comm e,4,4
.type i,@object # @i
.globl i
.p2align 1
i:
.short 0 # 0x0
.size i, 2
.type b,@object # @b
.globl b
b:
.byte 0 # 0x0
.size b, 1
.ident "clang version 13.0.0 (https://github.com/llvm/llvm-project.git d7b669b3a30345cfcdb2fde2af6f48aa4b94845d)"
.section ".note.GNU-stack","",@progbits
.addrsig
```
</p></details>
`clang-550ea385abc2805fd3e0a539bf55bc82edb5c13e -v`
<details ><summary>Output</summary><p>
```
clang version 14.0.0 (https://github.com/llvm/llvm-project.git 550ea385abc2805fd3e0a539bf55bc82edb5c13e)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /zdata/compiler_cache/clang-550ea385abc2805fd3e0a539bf55bc82edb5c13e/bin
Found candidate GCC installation: /usr/lib/gcc/x86_64-pc-linux-gnu/11.1.0
Found candidate GCC installation: /usr/lib64/gcc/x86_64-pc-linux-gnu/11.1.0
Selected GCC installation: /usr/lib64/gcc/x86_64-pc-linux-gnu/11.1.0
Candidate multilib: .;@m64
Candidate multilib: 32;@m32
Selected multilib: .;@m64
```
</p></details>
`clang-ed403e4cb2e5c9c61d2fbb44bae03c5603290bf1 -v`
<details ><summary>Output</summary><p>
```
clang version 13.0.0 (https://github.com/llvm/llvm-project.git d7b669b3a30345cfcdb2fde2af6f48aa4b94845d)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /zdata/compiler_cache/clang-ed403e4cb2e5c9c61d2fbb44bae03c5603290bf1/bin
Found candidate GCC installation: /usr/lib/gcc/x86_64-pc-linux-gnu/11.1.0
Found candidate GCC installation: /usr/lib64/gcc/x86_64-pc-linux-gnu/11.1.0
Selected GCC installation: /usr/lib64/gcc/x86_64-pc-linux-gnu/11.1.0
Candidate multilib: .;@m64
Candidate multilib: 32;@m32
Selected multilib: .;@m64
```
</p></details>
### Bisection
Started with 07333810caee48e94587891191a970be8a117fcf
`clang-07333810caee48e94587891191a970be8a117fcf -Os -S -o /dev/stdout case.c`
<details ><summary>Output</summary><p>
```asm
.text
.file "case.c"
.globl a # -- Begin function a
.type a,@function
a: # @a
.cfi_startproc
# %bb.0:
movl %edi, %eax
testb %sil, %sil
je .LBB0_2
# %bb.1:
movsbl %al, %eax
movsbl %sil, %ecx
# kill: def $ax killed $ax killed $eax
cwtd
idivw %cx
# kill: def $ax killed $ax def $eax
.LBB0_2:
# kill: def $al killed $al killed $eax
retq
.Lfunc_end0:
.size a, .Lfunc_end0-a
.cfi_endproc
# -- End function
.globl main # -- Begin function main
.type main,@function
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
movb $1, c(%rip)
movzwl h(%rip), %eax
testw %ax, %ax
jg .LBB1_7
# %bb.1:
xorl %ecx, %ecx
movl e(%rip), %edx
movb $1, %bpl
.LBB1_2: # =>This Inner Loop Header: Depth=1
xorl %esi, %esi
cmpl $8, %edx
setge %bl
movw %cx, i(%rip)
testl %ecx, %ecx
je .LBB1_4
# %bb.3: # in Loop: Header=BB1_2 Depth=1
movb %bl, %sil
movsbl b(%rip), %edx
orl %esi, %edx
movl %edx, e(%rip)
movb %dl, b(%rip)
.LBB1_4: # in Loop: Header=BB1_2 Depth=1
testb %bpl, %bpl
jne .LBB1_6
# %bb.5: # in Loop: Header=BB1_2 Depth=1
callq foo
movl e(%rip), %edx
movzbl c(%rip), %ecx
xorl $1, %ecx
movzwl h(%rip), %eax
.LBB1_6: # in Loop: Header=BB1_2 Depth=1
movzwl %ax, %esi
incl %eax
movw %ax, h(%rip)
# kill: def $ax killed $ax killed $eax def $rax
cmpl $32766, %esi # imm = 0x7FFE
ja .LBB1_2
.LBB1_7:
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
.Lfunc_end1:
.size main, .Lfunc_end1-main
.cfi_endproc
# -- End function
.type c,@object # @c
.local c
.comm c,1,4
.type h,@object # @h
.bss
.globl h
.p2align 1
h:
.short 0 # 0x0
.size h, 2
.type e,@object # @e
.local e
.comm e,4,4
.type i,@object # @i
.globl i
.p2align 1
i:
.short 0 # 0x0
.size i, 2
.type b,@object # @b
.globl b
b:
.byte 0 # 0x0
.size b, 1
.ident "clang version 14.0.0 (https://github.com/llvm/llvm-project.git 07333810caee48e94587891191a970be8a117fcf)"
.section ".note.GNU-stack","",@progbits
.addrsig
```
</p></details>
Previous commit: 8ec0f221843c51096cf3e7a479e780be371388a8
`clang-8ec0f221843c51096cf3e7a479e780be371388a8 -Os -S -o /dev/stdout case.c`
<details ><summary>Output</summary><p>
```asm
.text
.file "case.c"
.globl a # -- Begin function a
.type a,@function
a: # @a
.cfi_startproc
# %bb.0:
movl %edi, %eax
testb %sil, %sil
je .LBB0_2
# %bb.1:
movsbl %al, %eax
movsbl %sil, %ecx
# kill: def $ax killed $ax killed $eax
cwtd
idivw %cx
# kill: def $ax killed $ax def $eax
.LBB0_2:
# kill: def $al killed $al killed $eax
retq
.Lfunc_end0:
.size a, .Lfunc_end0-a
.cfi_endproc
# -- End function
.globl main # -- Begin function main
.type main,@function
main: # @main
.cfi_startproc
# %bb.0:
movzwl h(%rip), %eax
testw %ax, %ax
jg .LBB1_3
.LBB1_1: # =>This Inner Loop Header: Depth=1
# kill: def $ax killed $ax killed $eax def $rax
movzwl %ax, %ecx
incl %eax
cmpl $32766, %ecx # imm = 0x7FFE
ja .LBB1_1
# %bb.2:
movw $0, i(%rip)
movw %ax, h(%rip)
.LBB1_3:
xorl %eax, %eax
retq
.Lfunc_end1:
.size main, .Lfunc_end1-main
.cfi_endproc
# -- End function
.type h,@object # @h
.bss
.globl h
.p2align 1
h:
.short 0 # 0x0
.size h, 2
.type i,@object # @i
.globl i
.p2align 1
i:
.short 0 # 0x0
.size i, 2
.type b,@object # @b
.globl b
b:
.byte 0 # 0x0
.size b, 1
.ident "clang version 14.0.0 (https://github.com/llvm/llvm-project.git 8ec0f221843c51096cf3e7a479e780be371388a8)"
.section ".note.GNU-stack","",@progbits
.addrsig
```
</p></details>
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs