https://bugs.llvm.org/show_bug.cgi?id=42696
Bug ID: 42696
Summary: Missed optimization for (n << 1) ? X : Y
Product: libraries
Version: trunk
Hardware: PC
OS: Linux
Status: NEW
Severity: enhancement
Priority: P
Component: Scalar Optimizations
Assignee: [email protected]
Reporter: [email protected]
CC: [email protected]
int test(int n)
{
return (2*n) ? n << 1 : 0;
}
int test2(int n)
{
return (n << 1) ? 2*n : 0;
}
Clang -O3 trunk:
test(int): # @test(int)
lea eax, [rdi + rdi]
ret
test2(int): # @test2(int)
lea eax, [rdi + rdi]
mov ecx, edi
and ecx, 2147483647
test ecx, ecx
cmove eax, ecx
ret
GCC -O3 trunk:
test(int):
lea eax, [rdi+rdi]
ret
test2(int):
lea eax, [rdi+rdi]
ret
Also, GCC's add should be better than TEST with imm?
int test2(int n)
{
return (n << 1) ? 1 : 0;
}
Clang:
test2(int): # @test2(int)
xor eax, eax
test edi, 2147483647
setne al
ret
GCC:
test3(int):
xor eax, eax
add edi, edi
setne al
ret
--
You are receiving this mail because:
You are on the CC list for the bug._______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs