llvm-project
llvm-project copied to clipboard
Dead Code Elimination Regression when using __builtin_unreachable (trunk vs 15)
https://godbolt.org/z/71djY498P
Given the following code:
void foo(void);
static int a, c;
static int *b = &a, *d = &c, *g = &a;
static char e, h;
static short f;
int main() {
f = 5 - c;
if (f ^ 0)
;
else {
foo();
}
*b = c >= 0;
h = *g;
char j = *d = h;
e = j << 2;
int i = e;
c = -3;
if (!(((i) >= 4) && ((i) <= 4))) {
__builtin_unreachable();
}
}
clang-trunk -O3 does not eliminate the call to foo:
main: # @main
# %bb.0:
xorl %eax, %eax
cmpb $0, c(%rip)
movl $65533, %ecx # imm = 0xFFFD
cmovel %eax, %ecx
cmpl $5, %ecx
jne .LBB0_2
# %bb.1:
pushq %rax
callq foo@PLT
addq $8, %rsp
.LBB0_2:
movb $1, c(%rip)
xorl %eax, %eax
retq
.Lfunc_end0:
clang-15.0.7 -O3 eliminates the call to foo:
main: # @main
# %bb.0:
movb $1, c(%rip)
xorl %eax, %eax
retq
.Lfunc_end0:
Bisects to 0f32a5dea0e9ef5a52865f9fd285b394d46babaf (@rotateright )