<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/63664>63664</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Dead Code Elimination Regression (trunk vs 16)
</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/aa147sEKc
Given the following code:
```C
void foo(void);
static int a, c, d, l, m, n;
static int e[][2][1] = {{}, {}, {{}, 2}, {{}, 2}, {{}, 2}};
static int *f, *i, *j = &a, *k = &c;
static int **h = &f;
static int o[][9][3] = {4, 8, 1, 4, 8, 1, 4, 8, 1, 4, 8, 1, 4,
8, 1, 4, 8, 1, 4, 8, 1, 4, 8, 1, 4};
static char p;
static char(q)(char b) {
if (!(((b) >= 1) && ((b) <= 1))) {
__builtin_unreachable();
}
return 0;
}
static int *r(int *ab) {
l = 0;
for (; l <= 2; l++) {
d = 0;
for (; d <= 2; d++) {
*ab = 1;
a = 0;
for (; a <= 2; a++) {
c = 0;
for (; c <= 2; c++) {
e[4][0][0] = 8;
*h = 0;
}
m = 6 ? e[l + 2][1][0] : 0;
if (m == 0)
n = d + o[0][a][0];
else {
char g = l;
p = g == 0 ?: 8 % g;
n = p || l;
}
if (*ab) continue;
foo();
return 0;
}
q(n);
*ab = 0;
}
}
return ab;
}
int main() {
*h = j;
int ***s[] = {&h, &h};
*h = k;
i = *h;
r(i);
}
```
clang-trunk -O2 does not eliminate the call to foo:
```asm
main: # @main
# %bb.0:
leaq c(%rip), %rax
movq %rax, i(%rip)
movq $0, f(%rip)
movl $3, c(%rip)
movl $2, a(%rip)
xorl %eax, %eax
testb %al, %al
jne .LBB0_10
# %bb.1:
movl $8, e+32(%rip)
movq $0, f(%rip)
movl $3, c(%rip)
movl $2, a(%rip)
xorl %eax, %eax
testb %al, %al
jne .LBB0_10
# %bb.2:
movq $0, f(%rip)
movl $3, c(%rip)
movl $2, a(%rip)
xorl %eax, %eax
testb %al, %al
jne .LBB0_10
# %bb.3:
movl $8, e+32(%rip)
movq $0, f(%rip)
movl $3, c(%rip)
movl $2, a(%rip)
xorl %eax, %eax
testb %al, %al
jne .LBB0_10
# %bb.4:
movl $8, e+32(%rip)
movq $0, f(%rip)
movl $3, c(%rip)
movl $2, a(%rip)
xorl %eax, %eax
testb %al, %al
jne .LBB0_10
# %bb.5:
movq $0, f(%rip)
movl $3, c(%rip)
movl $2, a(%rip)
xorl %eax, %eax
testb %al, %al
jne .LBB0_10
# %bb.6:
movl $8, e+32(%rip)
movq $0, f(%rip)
movl $3, c(%rip)
movl $2, a(%rip)
xorl %eax, %eax
testb %al, %al
jne .LBB0_10
# %bb.7:
movl $8, e+32(%rip)
movq $0, f(%rip)
movl $3, c(%rip)
movl $2, a(%rip)
xorl %eax, %eax
testb %al, %al
jne .LBB0_10
# %bb.8:
movq $0, f(%rip)
movl $3, c(%rip)
movl $2, a(%rip)
xorl %eax, %eax
testb %al, %al
jne .LBB0_10
# %bb.9:
movl $3, a(%rip)
movl $8, e+32(%rip)
movl $0, c(%rip)
xorl %eax, %eax
retq
.LBB0_10:
pushq %rax
movl $8, e+32(%rip)
callq foo@PLT
addq $8, %rsp
xorl %eax, %eax
retq
.Lfunc_end0:
```
clang-16.0.6 -O2 eliminates the call to foo:
```asm
main: # @main
# %bb.0:
leaq c(%rip), %rax
movq %rax, f(%rip)
movq %rax, i(%rip)
xorl %eax, %eax
leaq e(%rip), %rcx
.p2align 4, 0x90
.LBB0_1: # =>This Inner Loop Header: Depth=1
testq %rax, %rax
movl $8, e+32(%rip)
cmpl $0, 20(%rcx,%rax,8)
movl $8, e+32(%rip)
movl $8, e+32(%rip)
incq %rax
cmpq $3, %rax
jne .LBB0_1
# %bb.2:
movl $0, c(%rip)
movl $3, a(%rip)
movq $0, f(%rip)
xorl %eax, %eax
retq
.Lfunc_end0:
```
Bisects to 39a0677784d1b53f2d6e33af2a53e915f3f62c86 (@khei4)
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzsWN1v6ygW_2vIC2qED7ZjP-QhH83uaq-0q9F9r7CNY1oCqSG9d-avHwGpYydO097RPExVZGE-Dr_zAedwbGaM2CrO5yhZomQ9YQfb6HZuG24brivdTgpd_T5vrN0bRBcINgg2W10VWtqpbrcINn8g2DAWxTNz_98SkTUii1D_S7xwhW3Dca2l1D-E2uJSV9zh9MhQSsKzCv0XLSpca40gc00EOaLLMGUss6LEQlnMEKxw6arKVdJVO1epMWoe1EPJEsIrQskaI7rGaLb0z9qtPWu9duBjg7P1mAgIFrWnh4U4vh-DBJCy48DT60B5BQHBonmlqcdodKdoHl60p2js2GSuilz14W7g9usIl4YpG9bi_dgoguzZbT1knqZAkHtTBxEwxqLGCDIEka_dE2jovdM28m1IEaR4MLt6nQ1PD_PhoTgIaYV6OKiWs7JhheR-7ekAOsZOja7TcntoFSYdRTc73Dinz7HJLnWRfofIgE2tWy85XfppLzf4HoKlf85AXKlGgM7AqgFY9QaYV9bJi4PNzkFdYVcYnjFlA6bsBlNXynPgHlo5QCvfgeaKiwFxcApyenk22YlN52HjOl0cgH7Z-YUpRnTjuUmMYIl7EefEc_EGfjjZHiwIAvl1rZTnWXlO-qQa6yl6jQ-Xhr9tMu96W89BnmD2fmDbyef0dRplGEGCt1f5ncTdYzRbodmqj3rVqq-OfnScUisr1IH3T4YecdN-ufDSm9v5jCBTA8iTJ1zCDCDG4gMrLgOECwc7JlSQfbgR3Sl8HPA63QIIFiaE-u4Wg7QJ10ja9CPtAO5pCHe8ShbNYNjHqr7unchnF3bolpKp7Z1tD-oJ3_0PcKW5wUpbzKXYCcUs9zlAyaTEVvvdupIAMLMLI94sdPQAnRUEFKOY-AUBzA1AUhRT0mOTS86eEclLb-ykFXsf_p21kpb97Mh2-sWRHUdhhcVgwQVZTBxRfY1IBiJ6zFXeJAJHxEaJfuo2ECU8SHVsvc5bbmwR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