Closed
Description
https://godbolt.org/z/rxPnbEnoT
void fn();
void test(unsigned *d) {
int is_negative = *d & 0x80000000;
if (!is_negative && *d & 0x7fffffff) {
fn();
}
}
GCC recognizes this pattern and folds it to comparison
test:
mov eax, DWORD PTR [rdi]
test eax, eax
jg .L4
ret
.L4:
xor eax, eax
jmp fn
However, LLVM 18 main fails to optimize it:
test:
mov eax, dword ptr [rdi]
test eax, eax
js .LBB0_2
and eax, 2147483647
je .LBB0_2
xor eax, eax
jmp fn@PLT
.LBB0_2:
ret