[LLVMdev] Removing nuw and nsw

Duncan Sands baldrick at free.fr
Mon Nov 26 09:18:07 PST 2012


Hi Raffael,

> currently I'm writing a thesis about compiler optimization techniques and I've
> choosen LLVM as a framework for implementing and testing my ideas.
>
> While reading the LLVM Language Reference Manual I noticed that the nuw and nsw
> keywords for the instructions add, sub and mul complicate reasoning about
> integer arithmetic for the purpose of my thesis somewhat. Things would be easier
> for me if there would be just the plain variants of these instructions so I
> could formally treat them modular arithmetic operations. Thus, I'm wondering if
> it's a valid transformation to simply drop these keywords during an optimisation
> pass ...

it is valid.  Dropping them decreases the effectiveness of the optimizers, but
it doesn't create any correctness issues.

> As I see it, the effect of nuw resp. nsw is to create poison values in case of
> an overflow, which are essentially undefined values with the additional effect
> that they can cause other operation that depend on them to also produce poison
> values. So, as I understand it, removing these keywords would basically turn
> undefined values into defined ones, thus dropping some information that could be
> used for further optimizations, but it would not strictly speaking be an
> incorrect transformation - is this correct or do I miss or misunderstand something?

That's right, you got it.

Ciao, Duncan.

>
> Thanks in advance for any comments and insights about this matter!
>
> Raffael Bild
>
> _______________________________________________
> 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