<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/63666>63666</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Dead Code Elimination Regression (trunk vs 15)
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
thetheodor
</td>
</tr>
</table>
<pre>
https://godbolt.org/z/ad5Gq5f68
Given the following code:
```C
void foo(void);
static int c, g;
static int **d;
static int ***e = &d;
static int ****f = &e;
static char h;
static int *i = &c;
void __assert_fail(char *, char *, int, char *);
static char(a)(char b) {
if (!(((b) >= -1) && ((b) <= 0))) {
__builtin_unreachable();
}
return 0;
}
int main() {
int ****j = &e;
for (; h <= 6; h++) {
{
*e = &i;
for (;;) {
****f = ~0;
if (d)
;
else {
foo();
__assert_fail("", "", 3, __PRETTY_FUNCTION__);
}
break;
}
}
if (h) a(****f);
}
a(g);
0 == &j;
}
```
clang-trunk -O3 does not eliminate the call to foo:
```asm
main: # @main
# %bb.0:
movzbl h(%rip), %eax
cmpb $6, %al
jg .LBB0_6
# %bb.1:
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
pushq %rax
leaq d(%rip), %r15
leaq i(%rip), %r12
leaq .L.str(%rip), %rbx
leaq .L__PRETTY_FUNCTION__.main(%rip), %r14
movq %r15, %rcx
jmp .LBB0_2
.p2align 4, 0x90
.LBB0_4: # in Loop: Header=BB0_2 Depth=1
testb %al, %al
cmovneq %r15, %rcx
incb %al
movb %al, h(%rip)
cmpb $7, %al
jge .LBB0_5
.LBB0_2: # =>This Inner Loop Header: Depth=1
movq %r12, d(%rip)
movq i(%rip), %rdx
movl $-1, (%rdx)
cmpq $0, d(%rip)
jne .LBB0_4
# %bb.3: # in Loop: Header=BB0_2 Depth=1
callq foo@PLT
movq %rbx, %rdi
movq %rbx, %rsi
movl $3, %edx
movq %r14, %rcx
callq __assert_fail@PLT
movzbl h(%rip), %eax
movq %r15, %rcx
jmp .LBB0_4
.LBB0_5:
addq $8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
.LBB0_6:
xorl %eax, %eax
retq
.Lfunc_end0:
```
clang-15.0.7 -O3 eliminates the call to foo:
```asm
main: # @main
# %bb.0:
movzbl h(%rip), %ecx
cmpb $6, %cl
jg .LBB0_7
# %bb.1:
movb $1, %dl
subb %cl, %dl
movl %ecx, %eax
testb $1, %dl
je .LBB0_3
# %bb.2:
leaq i(%rip), %rax
movq %rax, d(%rip)
movq i(%rip), %rax
movl $-1, (%rax)
leal 1(%rcx), %eax
movb %al, h(%rip)
.LBB0_3:
cmpb $6, %cl
je .LBB0_7
# %bb.4:
movq i(%rip), %rcx
leaq i(%rip), %rdx
.p2align 4, 0x90
.LBB0_5: # =>This Inner Loop Header: Depth=1
movq %rdx, d(%rip)
movl $-1, (%rcx)
movq %rdx, d(%rip)
movl $-1, (%rcx)
addb $2, %al
cmpb $7, %al
jl .LBB0_5
# %bb.6:
movb %al, h(%rip)
.LBB0_7:
xorl %eax, %eax
retq
.Lfunc_end0:
```
Bisects to 01ec0ff2dcf5528b0e6728e5693b583e4e6f83f1 (@nikic)
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzMWFuPm7oW_jXOizXImEvgIQ-5THoqjdqqmvNwniJjTHDq4BQ705w-7N--ZUOAgJNptfeWdoQYWGt5eV0-f2sSohTfV4wtQLQC0WZGzrqU9UKXTJdM5rKeZTL__6LU-qRAsAR4C_B2L_NMCu3Jeg_w9ifAW5JHH75HRZwAtAFo2dw_8DdWQV0yWEgh5A9e7SGVOTN-BmYgRs21bt7fJM9hISXAiXkEOAXBqlEpTTSnkFcaUoDXcO_SALwEeJnfVwG8ZBAEGwhw_NgM4GVxtWRjS1qSGpZ31vPrMtoZ2Lx2O6IUq_WuIFwAnFgndqc1HD7zSt-KJkUwKoATYlStnwzgFIJ5awchhLyAACcA-_ZursYmeDbhPfn2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