[llvm-bugs] [Bug 48760] New: Suboptimal cmov generation
via llvm-bugs
llvm-bugs at lists.llvm.org
Fri Jan 15 08:01:30 PST 2021
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: unassignedbugs at nondot.org
Reporter: henrik at gramner.com
CC: htmldeveloper at gmail.com, llvm-bugs at lists.llvm.org
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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20210115/5ef81e89/attachment.html>
More information about the llvm-bugs
mailing list