[llvm-dev] the nsw story, revisited

Peter Lawrence via llvm-dev llvm-dev at lists.llvm.org
Thu Jun 15 07:47:38 PDT 2017


Nuno,
          A very thought provoking example, but I don’t think I understand your argument yet

It seems you are saying the transformations are illegal because we’ve turned it into
“undefined behavior” based on the proposed definition of “branch on poison is undefined 
behavior”,  IE your argument  seems to hinge on the definition of “branch on poison”
and not on anything related to “nsw"

Or to put it another way, changing the function f(a,b) from using “+nsw” to just plain “+”
doesn’t seem to change anything, we still introduce UB when there wasn’t any originally,
or am I missing something ?

so I return to my previous claim that this definition isn’t justified, because
it appears as though you've just provided an example for why it isn’t.


Thoughts ?
Comments ?
Questions ?

Peter Lawrence.





> On Jun 14, 2017, at 3:13 PM, Nuno Lopes <nunoplopes at sapo.pt> wrote:
> 
> I guess an important thing to realize is that poison flows throughout the data-flow graph; it's not something that you can control locally.  Simply removing nsw from an operation doesn't mean that its result will be non-poisonous.
> Right now there's no way to stop propagation of poison; freeze adds that functionality.
> 
> Imagine you want to hoist an 'add nsw', drop nsw, and then do loop unswitching (your suggestion):
> 
> f(a, b) {
> while (..) {
>   if (a +nsw 1 > b) { S } else { T }
> }
> }
> 
> =>
> 
> f(a, b) {
> // drop nsw
> if (a + 1 > b) {
>    while (...) S;
> else
>    while (...) T;
> }
> }
> 
> 
> Is this correct? No!  Dropping nsw doesn't give any guarantee.  To see why, imagine that function f is now inlined in g:
> g() {
> f(poison, poison);
> }
> 
> after inlining:
> g() {
> if (poison) ...
> }
> 
> We've just introduced a branch on poison when the loop condition is false. Since we've decided to make branch-on-poison UB, the transformation we did above is incorrect.  Dropping nsw doesn't help. You need a way to stop poison from being propagated.  LLVM currently doesn't have this mechanism.
> 
> Nuno
> 
> P.S.: Please fix your address book entry for my email address; a colleague of mine is receiving your emails not me.
> 
> 



More information about the llvm-dev mailing list