[llvm-bugs] [Bug 25476] New: __builtin_assume pessimization
via llvm-bugs
llvm-bugs at lists.llvm.org
Tue Nov 10 09:09:57 PST 2015
https://llvm.org/bugs/show_bug.cgi?id=25476
Bug ID: 25476
Summary: __builtin_assume pessimization
Product: libraries
Version: 3.7
Hardware: PC
OS: Linux
Status: NEW
Severity: normal
Priority: P
Component: Backend: X86
Assignee: unassignedbugs at nondot.org
Reporter: matt at godbolt.org
CC: llvm-bugs at lists.llvm.org
Classification: Unclassified
Consider the code: [c.f. https://goo.gl/7VB27y ]
--
enum class Side { Bid, Ask };
struct Foo { int a; int b; };
int test(Side side, const Foo &foo) {
if (side == Side::Bid) return foo.a;
return foo.b;
}
int test_with_unreachable(Side side, const Foo &foo) {
if (side == Side::Bid) return foo.a;
if (side == Side::Ask) return foo.b;
__builtin_unreachable();
}
int test_with_assume(Side side, const Foo &foo) {
__builtin_assume(side == Side::Bid || side == Side::Ask);
if (side == Side::Bid) return foo.a;
return foo.b;
}
int test_with_assume2(Side side, const Foo &foo) {
if (side == Side::Bid) return foo.a;
__builtin_assume(side == Side::Ask);
return foo.b;
}
--
One might expect the generated code to basically be the same, but the _assume2
case generates a branch instead of the conditional moves emitted elsewhere.
e.g.
--
test(Side, Foo const&): # @test(Side, Foo const&)
lea rax, [rsi + 4]
test edi, edi
cmove rax, rsi
mov eax, dword ptr [rax]
ret
--
vs
--
test_with_assume2(Side, Foo const&): # @test_with_assume2(Side, Foo
const&)
test edi, edi
je .LBB3_2
add rsi, 4
.LBB3_2:
mov eax, dword ptr [rsi]
ret
--
This would appear to be a pessimization.
Arguably given the __builtin_assumption that the Side is either 0 or 1, one
might hope the following code could be generated:
--
mov eax, dword ptr [rsi+edx*4]
ret
--
GCC has a similar bug with __builtin_unreachable
(https://gcc.gnu.org/bugzilla/show_bug.cgi?id=68274)
--
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/20151110/fecff595/attachment-0001.html>
More information about the llvm-bugs
mailing list