[llvm-bugs] [Bug 43922] New: [X86] some builtins generate incorrect code for shifts with large (constant) shift counts
via llvm-bugs
llvm-bugs at lists.llvm.org
Wed Nov 6 11:16:26 PST 2019
https://bugs.llvm.org/show_bug.cgi?id=43922
Bug ID: 43922
Summary: [X86] some builtins generate incorrect code for shifts
with large (constant) shift counts
Product: libraries
Version: trunk
Hardware: PC
OS: All
Status: NEW
Severity: normal
Priority: P
Component: Backend: X86
Assignee: unassignedbugs at nondot.org
Reporter: Wolfgang_Pieb at playstation.sony.com
CC: craig.topper at gmail.com, llvm-bugs at lists.llvm.org,
llvm-dev at redking.me.uk, spatel+llvm at rotateright.com
Created attachment 22780
--> https://bugs.llvm.org/attachment.cgi?id=22780&action=edit
IR in question
The attached IR features a call to a builtin that generates a PSRAD
instruction. The shift count is large, and in such cases the instruction's
definition says that the result should be equal to the operand's sign bit (or
the sign bits of its respective elements) extended to the entire width of the
result (i.e. 0 or -1).
The instruction, however, is emitted with a shift count of 0, yielding a result
identical to the input operand.
movq .LCPI0_0(%rip), %mm0 # mm0 = 0x7AAAAAAA7AAAAAAA
psrad $0, %mm0
I do not think undefined behaviour is in play here, since I would expect that
the semantics of a builtin are directly derived from the that of the
instruction they represent, though I could be wrong about that.
The IR has been generated from the following C source:
// -----------------------------------------------------
typedef int __v2si __attribute__((__vector_size__(8)));
typedef long long __m64 __attribute__((__vector_size__(8)));
extern "C" int printf(const char *, ...);
int main()
{
__m64 id17152 = {(long long)0x7aaaaaaa7aaaaaaa};
int id17156 = 0x10000000;
__m64 id17151 = (__m64)__builtin_ia32_psradi((__v2si)id17152,
id17156);
printf("id17151 = %llx\n", id17151[0]);
}
// ------------------------------------------------------
gcc 7.4.0 prints 0 for this code.
In a late stage IR dump the PSRAD instruction shows up with the correct shift
count:
renamable $mm0 = MMX_PSRADri killed renamable $mm0(tied-def 0), 268435456
--
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/20191106/63de50e1/attachment.html>
More information about the llvm-bugs
mailing list