Issue 56046
Summary Dead Code Elimination Regression at -O3 (trunk vs. 14.0.4)
Labels new issue
Assignees
Reporter thetheodor
    ```c
static short a;
static int b;

void foo(void);
void bar9_(void);
int main() {
    char c;
    b = a = 23;
    for (; b <= 1;)
        a = 1;
    bar9_();
    c = a >= 18 || 2 > 2 >> a ? 1 : 1 << a;
    if (c == 0)
        foo();
}
```
`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	%rax
	.cfi_def_cfa_offset 16
	movb	$1, a(%rip)
	callq	bar9_@PLT
	xorl	%eax, %eax
	cmpb	$0, a(%rip)
	movl	$23, %ecx
	cmovel	%eax, %ecx
	movl	$2, %eax
	shrl	%cl, %eax
	addl	$-8, %ecx
	cmpw	$9, %cx
	ja	.LBB0_3
# %bb.1:
	cmpl	$2, %eax
	jb	.LBB0_3
# %bb.2:
	callq	foo@PLT
.LBB0_3:
	xorl	%eax, %eax
	popq	%rcx
	.cfi_def_cfa_offset 8
	retq
.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:
	pushq	%rax
	.cfi_def_cfa_offset 16
	movb	$1, a(%rip)
	callq	bar9_
	xorl	%eax, %eax
	popq	%rcx
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end0:
	.size	main, .Lfunc_end0-main
```
</p></details>

------------------------------------------------

### Bisection
Bisected to: c0e06c7448a2dd16796e210a66de68f269363e31
Committed by: @nikic
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to