[llvm-bugs] [Bug 33578] New: Optimization introduces error when right shifting by integer width.
via llvm-bugs
llvm-bugs at lists.llvm.org
Fri Jun 23 15:55:36 PDT 2017
https://bugs.llvm.org/show_bug.cgi?id=33578
Bug ID: 33578
Summary: Optimization introduces error when right shifting by
integer width.
Product: clang
Version: 3.9
Hardware: PC
OS: All
Status: NEW
Severity: normal
Priority: P
Component: C++11
Assignee: unassignedclangbugs at nondot.org
Reporter: d.horne at danielhorne.co.uk
CC: dgregor at apple.com, llvm-bugs at lists.llvm.org
I have the following inline, to simulate a rotl instruction:
static uint64_t rotateLeft(uint64_t x, int n)
{
return ((x << n) | (x >> (64 - n)));
}
It produces the expected results on MSVC, GCC, and clang++ with optimisation
switched off, but somehow produces 4294967295 in the n=0 case with -O3
optimisations. The results for n>0 look ok.
I then made the following tests:
printf(" 6 << 0 = %u \n", 6<<0);
printf(" 6 >> (64-0) = %u \n", 6>>(64-0));
printf(" 6 >> 64 = %u \n", 6>>64);
printf("((6 << 0) | (6 >> (64 - 0))) = %u \n", ((6 << 0) | (6 >> (64 -
0))));
printf(" rotateLeft(6,0) = %u \n", rotateLeft(6,0));
which produced:
6 << 0 = 6
6 >> (64-0) = 24579104
6 >> 64 = 24579104
((6 << 0) | (6 >> (64 - 0))) = 4294967295
indicating the problem shows up when right shifting by 64..
According to the c++11 spec, right shifts should produce "the integral part of
the quotient of E1 / 2^E2", which in this case is zero, leading me to consider
this a compliance bug.
--
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/20170623/7ca8cc07/attachment.html>
More information about the llvm-bugs
mailing list