[PATCH] Teach IndVarSimplify to add nuw and nsw to operations that provably don't overflow.

Sanjoy Das sanjoy at playingwithpointers.com
Tue Dec 23 16:47:04 PST 2014


But isn't it always legal to remove nuw and nsw?  If we are blocked on
a transform because of an nsw, why can't we drop the nsw and the
continue with the transform?  That way we'd be no worse than where
we'd have been if the nsw had not been added in the first place.

For example in the slides, it is shown we cannot replace

  %L = mul nsw i8 %A, %B
  %I = mul nsw i8 %L, %C

with

  %R = mul nsw i8 %B, %C
  %I = mul nsw i8 %A, %R

But this would be an argument against tagging values with nsw only if
it were possible to replace

  %L = mul i8 %A, %B
  %I = mul i8 %L, %C

with

  %R = mul nsw i8 %B, %C
  %I = mul nsw i8 %A, %R

On Tue, Dec 23, 2014 at 4:31 PM, Hal Finkel <hfinkel at anl.gov> wrote:
> ----- Original Message -----
>> From: "Sanjoy Das" <sanjoy at playingwithpointers.com>
>> To: sanjoy at playingwithpointers.com, atrick at apple.com, "david majnemer" <david.majnemer at gmail.com>, hfinkel at anl.gov
>> Cc: llvm-commits at cs.uiuc.edu
>> Sent: Tuesday, December 23, 2014 6:22:31 PM
>> Subject: Re: [PATCH] Teach IndVarSimplify to add nuw and nsw to operations that provably don't overflow.
>>
>> Hi Hal,
>>
>> Thank you for the review.
>>
>> This is the context:
>>  http://lists.cs.uiuc.edu/pipermail/llvmdev/2014-December/079885.html
>>  This patch tries to fix point (1) as mentioned in the mail
>>
>> I am not aware of transforms that are valid only on overflowing
>> operators: as far as I can tell, adding nsw / nuw is a strict
>> increase in the amount of information there is available about an
>> instruction.  Can you give me some pointers on where to look for
>> examples?  Don't bother if you don't have them handy, I'll look for
>> them myself later.
>
> We really need to add this to an FAQ somewhere, it comes up a lot...
>
> For example, see slides 20-31 of http://llvm.org/devmtg/2014-10/Slides/Menendez-Alive.pdf -- shows a reassociation example valid only without the no-wrap flags. There are other examples too that have been discussed on the mailing list.
>
>>
>> As an aside, I'll be on vacation starting a few hours from now, so I
>> won't be able to check this in before the first week of 2015.
>
> Okay; enjoy your vacation!
>
>  -Hal
>
>>
>>
>> http://reviews.llvm.org/D6748
>>
>> EMAIL PREFERENCES
>>   http://reviews.llvm.org/settings/panel/emailpreferences/
>>
>>
>>
>
> --
> Hal Finkel
> Assistant Computational Scientist
> Leadership Computing Facility
> Argonne National Laboratory



More information about the llvm-commits mailing list