[llvm-bugs] [Bug 31773] New: Unsigned Saturation + Truncation at -02 -mavx is giving incorrect runtime results
via llvm-bugs
llvm-bugs at lists.llvm.org
Thu Jan 26 10:45:16 PST 2017
https://llvm.org/bugs/show_bug.cgi?id=31773
Bug ID: 31773
Summary: Unsigned Saturation + Truncation at -02 -mavx is
giving incorrect runtime results
Product: libraries
Version: trunk
Hardware: PC
OS: Linux
Status: NEW
Severity: normal
Priority: P
Component: Backend: X86
Assignee: unassignedbugs at nondot.org
Reporter: charles_li at playstation.sony.com
CC: llvm-bugs at lists.llvm.org
Classification: Unclassified
We discovered this bug on PlayStation 4.
This bug is reproducible on other X86 targets with flag –mavx
This bug started with revision 291670.
$ svn log -r 291670
------------------------------------------------------------------------
r291670 | delena | 2017-01-11 04:59:32 -0800 (Wed, 11 Jan 2017)
X86 CodeGen: Optimized pattern for truncate with unsigned saturation.
DAG patterns optimization: truncate + unsigned saturation supported by VPMOVUS*
instructions in AVX-512.
And VPACKUS* instructions on SEE* targets.
Differential Revision: https://reviews.llvm.org/D28216
------------------------------------------------------------------------
Here is a test case.
$ cat t.cpp
/*******************************************************/
extern "C" int printf(const char * , ...);
union myType
{
unsigned short ushort_array[32];
unsigned char uchar_array[64];
myType() { // Constructor
unsigned short val = 1;
for( int i = 0; i < 32 ; i++ ) {
ushort_array[i] = val;
val = val * 7 % 0xFFFFu; // pseudo RNG
}
}
};
int main() {
myType src;
myType dest;
for (int i = 0; i < 32; i++) { // saturate to 0xFF then truncate
dest.uchar_array[i] = static_cast<unsigned char>(
(src.ushort_array[i] < static_cast<unsigned short>(0xFFu)) ?
src.ushort_array[i] : static_cast<unsigned short>(0xFFu));
}
printf("Index , Source , Target\n");
for (int j = 0; j < 32; j++) {
printf("%d , %hx , %hhx \n", j, src.ushort_array[j], dest.uchar_array[j]);
}
return 0;
}
/*******************************************************/
Compile this test at –O2 -mavx
$ clang t.cpp -O2 –mavx -o t.elf
Here is the runtime output
$ ./t.elf
Index , Source , Target
0 , 1 , 1
1 , 7 , 7
2 , 31 , 31
3 , 157 , ff
4 , 961 , ff
5 , 41a7 , ff
6 , cb92 , 0
7 , 9103 , 0
8 , f718 , 0
9 , c1ae , 0
10 , 4bc7 , ff
11 , 1273 , ff
12 , 8125 , 0
13 , 8806 , 0
14 , b82d , 0
15 , 940 , ff
16 , 40c0 , ff
17 , c541 , 0
18 , 64cc , ff
19 , c196 , 0
20 , 4b1f , ff
21 , ddb , ff
22 , 60fd , ff
23 , a6ed , 0
24 , 907f , 0
25 , f37c , 0
26 , a86a , 0
27 , 9aea , 0
28 , 3c6a , ff
29 , a6e7 , 0
30 , 9055 , 0
31 , f256 , 0
For Index 6-10, 12-14, 23-27, 29-31,
Target is "0" when it should be "ff".
--
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/20170126/fb70bd6e/attachment.html>
More information about the llvm-bugs
mailing list