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: unassignedb...@nondot.org Reporter: spatel+l...@rotateright.com CC: llvm-bugs@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.
_______________________________________________ llvm-bugs mailing list llvm-bugs@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs