[llvm-bugs] [Bug 42189] New: Avoid copy to reg before cmp
via llvm-bugs
llvm-bugs at lists.llvm.org
Fri Jun 7 12:11:18 PDT 2019
https://bugs.llvm.org/show_bug.cgi?id=42189
Bug ID: 42189
Summary: Avoid copy to reg before cmp
Product: libraries
Version: trunk
Hardware: PC
OS: Linux
Status: NEW
Severity: enhancement
Priority: P
Component: Backend: X86
Assignee: unassignedbugs at nondot.org
Reporter: david.bolvansky at gmail.com
CC: craig.topper at gmail.com, llvm-bugs at lists.llvm.org,
llvm-dev at redking.me.uk, spatel+llvm at rotateright.com
int g();
int f();
int shortmax(short c)
{
if (c == 32767)
return g();
return f();
}
Clang:
shortmax(short):
movzx eax, di
cmp eax, 32767
jne .LBB0_2
jmp g()
.LBB0_2:
jmp f()
But shouldn't we just use cmp di, 32767?
And I am just looking what -Os produces, and this is really interesting...
shortmax(short):
movzx eax, di
cmp eax, 32767
jne f() // neat
jmp g()
So for this pattern
if (x) call fn1();
else call fn2();
Possibly -O2/O3 should do this tranformation too?
Maybe ideal code (what -O3 should produce) for my example is:
shortmax(short):
cmp di, 32767
jne f()
jmp g()
?
--
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/20190607/bf7b3b7f/attachment.html>
More information about the llvm-bugs
mailing list