[LLVMdev] Do we abuse the "nsw" flag

Cameron Zwarich zwarich at apple.com
Mon May 6 16:59:06 PDT 2013


This has come up before, and we just added -fwrapv to work around the problem:

http://lists.cs.uiuc.edu/pipermail/llvm-commits/Week-of-Mon-20110131/115969.html

Are you compiling without -fwrapv?

Cameron

On May 6, 2013, at 4:55 PM, Shuxin Yang <shuxin.llvm at gmail.com> wrote:

> 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
> 
> 
> 
> 
> 
> _______________________________________________
> LLVM Developers mailing list
> LLVMdev at cs.uiuc.edu         http://llvm.cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev




More information about the llvm-dev mailing list