[llvm-bugs] [Bug 39968] New: [x86-64] Suboptimal codegen for (!x) as opposed to (0 == x)
via llvm-bugs
llvm-bugs at lists.llvm.org
Tue Dec 11 22:27:49 PST 2018
https://bugs.llvm.org/show_bug.cgi?id=39968
Bug ID: 39968
Summary: [x86-64] Suboptimal codegen for (!x) as opposed to (0
== x)
Product: new-bugs
Version: trunk
Hardware: PC
OS: All
Status: NEW
Severity: enhancement
Priority: P
Component: new bugs
Assignee: unassignedbugs at nondot.org
Reporter: arthur.j.odwyer at gmail.com
CC: htmldeveloper at gmail.com, llvm-bugs at lists.llvm.org
https://godbolt.org/z/Z2afe8
#include <stdint.h>
struct u128 { uint64_t x, y; };
u128 shl2(uint64_t rdi, uint64_t rdx, int n)
{
if (n & 64) rdx = rdi;
#if WORSE
if (!(n & 64)) rdi = 0;
#else
if (0 == (n & 64)) rdi = 0;
#endif
return {rdi,rdx};
}
Without -DWORSE, Clang generates perfect codegen.
andl $64, %edx
xorl %eax, %eax
cmovneq %rdi, %rsi
cmovneq %rdi, %rax
movq %rsi, %rdx
retq
But with -DWORSE, Clang generates a dead-store "shr" instruction:
andl $64, %edx
xorl %eax, %eax
shrl $6, %edx // USELESS INSTRUCTION!
cmovneq %rdi, %rsi
cmovneq %rdi, %rax
movq %rsi, %rdx
retq
This is surprising, given that the only difference is using (0 == x) versus
(!x). I would expect these to have equivalent codegen.
--
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/20181212/80f8d70e/attachment.html>
More information about the llvm-bugs
mailing list