https://bugs.llvm.org/show_bug.cgi?id=48760
Bug ID: 48760
Summary: Suboptimal cmov generation
Product: new-bugs
Version: trunk
Hardware: PC
OS: All
Status: NEW
Severity: enhancement
Priority: P
Component: new bugs
Assignee: [email protected]
Reporter: [email protected]
CC: [email protected], [email protected]
LLVM prefers to generate cmov instructions with as many flag dependencies as
possible, which is suboptimal. It should be doing the opposite.
For example, both of those functions are semantically identical:
unsigned a(unsigned x) { return x > 3 ? x : 0; }
unsigned b(unsigned x) { return x >= 4 ? x : 0; }
They both generate identical code:
xor eax, eax
cmp edi, 3
cmova eax, edi
ret
The better code would be:
xor eax, eax
cmp edi, 4
cmovae eax, edi
ret
cmovae has a dependency on CF whereas cmova has dependencies on both CF and ZF.
Many (most?) x86 CPUs will execute cmov instructions with a single flag
dependency in a single µop, but splits them into two µops if there are multiple
flag dependencies.
--
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