[LLVMdev] Do we abuse the "nsw" flag
Shuxin Yang
shuxin.llvm at gmail.com
Mon May 6 16:55:43 PDT 2013
Hi, There:
Clang fails to compile 254.gap @ CPU2000int suite. The symptom is
that executable fail to run
with reference input.
The root cause is that the compiler mistakenly optimizes expr "x * y
/ y" into x where the x*y is blindly
flagged with nsw without any analysis.
The preproceeded code is excerpted bellow:
cat -n integer.i
---------------------------------
2361 TypHandle ProdInt ( hdL, hdR )
2362 TypHandle hdL, hdR;
2363 {
....
2373 if ( (int)hdL & (int)hdR & 1 ) {
2374
2375
2376 i = ((int)hdL - 1) * ((int)hdR >> 1); /* !!! No barbaric
NSW, please !!! */
2377 if ( ((int)hdR >> 1) == 0 || i / ((int)hdR >> 1) ==
((int)hdL-1) ) {
---------------------------------
I catch the case where the multiplication overflow: the 1st and 2nd
operand hold the
value 0x4000 and 0x20000, respectively.
Dose gap source code has some "undefined" behavior according to some
spec
on this planet? Or it is compiler's fault for blindly mark any mul NSW?
Thanks
Shuxin
More information about the llvm-dev
mailing list