[llvm-bugs] [Bug 28968] New: [x86] missed chance to turn select (cmov) into logic ops
via llvm-bugs
llvm-bugs at lists.llvm.org
Sat Aug 13 09:16:29 PDT 2016
https://llvm.org/bugs/show_bug.cgi?id=28968
Bug ID: 28968
Summary: [x86] missed chance to turn select (cmov) into logic
ops
Product: libraries
Version: trunk
Hardware: PC
OS: All
Status: NEW
Severity: normal
Priority: P
Component: Backend: X86
Assignee: unassignedbugs at nondot.org
Reporter: spatel+llvm at rotateright.com
CC: llvm-bugs at lists.llvm.org
Classification: Unclassified
Forking this off of bug 28964.
Notice that:
int goo(int x) {
if (x == 1)
x = 1;
else
x = -1;
return x;
}
Could be rewritten as:
int hoo(int x) {
if (x != 1)
x = -1;
return x;
}
Or as IR:
define i32 @hoo(i32 %x) {
%cmp = icmp ne i32 %x, 1
%sel = select i1 %cmp, i32 -1, i32 1
ret i32 %sel
}
$ ./llc -o - cmpsel.ll
cmpl $1, %edi
movl $-1, %eax
cmovel %edi, %eax
retq
According to godbolt ( https://godbolt.org/g/TSTeIo ), gcc learned to avoid a
cmov on this at v6.1:
foo(int):
xorl %eax, %eax
cmpl $1, %edi
setne %al
negl %eax
orl $1, %eax
ret
Note that gcc does this at -O2 but not -O1 or -Os.
Filing this as an x86 bug for now, but it might be useful for other targets
too.
--
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/20160813/1841cb51/attachment-0001.html>
More information about the llvm-bugs
mailing list