[llvm-bugs] [Bug 42696] New: Missed optimization for (n << 1) ? X : Y
via llvm-bugs
llvm-bugs at lists.llvm.org
Sat Jul 20 04:11:05 PDT 2019
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: unassignedbugs at nondot.org
Reporter: david.bolvansky at gmail.com
CC: llvm-bugs at lists.llvm.org
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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20190720/6f862183/attachment.html>
More information about the llvm-bugs
mailing list