<div dir="ltr"><br><div class="gmail_extra"><br><br><div class="gmail_quote">On Wed, Jul 23, 2014 at 4:06 PM, Rekha R <span dir="ltr"><<a href="mailto:rekharamapai@nitc.ac.in" target="_blank">rekharamapai@nitc.ac.in</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div><div><div><div><div>Ok. Got it.<br><br>
</div>If <i>add nsw</i> overflows, this results in undefined value.<br></div>But then <i>add</i> on same arguments results in well-defined value.<br><br></div>Hence treating first one as redundant based on the second is acceptable. But vice versa is not.<br>
</div></div></div></blockquote><div><br></div><div>If they are in different code paths, sure. It's not an undefined value, it's undefined *behaviour*. We can assume that the operation might crash, so the rest of the block is unreachable.</div>
<div><div>What you're really saying to the compiler with the nsw flag is " that the operation is <b>guaranteed </b>to not overflow" (<a href="http://llvm.org/releases/2.6/docs/ReleaseNotes.html">http://llvm.org/releases/2.6/docs/ReleaseNotes.html</a>)</div>
</div><div>And that the compiler can use this information in optimising the rest of your code.</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<div dir="ltr"><div><div>

<br></div><div>I was wondering on the role played by flags in detecting redundancies. At first I thought one need to consider only operands and operators. Now I understand flags also play a role.<br><br></div>Thanks,<br>

</div>
Rekha<br></div><div class="gmail_extra"><div><div class="h5"><br><br><div class="gmail_quote">On Wed, Jul 23, 2014 at 11:42 AM, Jeremy Lakeman <span dir="ltr"><<a href="mailto:Jeremy.Lakeman@gmail.com" target="_blank">Jeremy.Lakeman@gmail.com</a>></span> wrote:<br>


<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div>IMHO;</div>On undefined behaviour we can do whatever we want. If the "add nsw" overflows this would lead to undefined behaviour. <div>


Therefore we can assume that "add", with the same arguments will not overflow.</div>
</div><div class="gmail_extra"><br><br><div class="gmail_quote"><div><div>On Wed, Jul 23, 2014 at 3:32 PM, Tim Northover <span dir="ltr"><<a href="mailto:t.p.northover@gmail.com" target="_blank">t.p.northover@gmail.com</a>></span> wrote:<br>



</div></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div><div><div>On 23 July 2014 06:25, Rekha R <<a href="mailto:rekharamapai@nitc.ac.in" target="_blank">rekharamapai@nitc.ac.in</a>> wrote:<br>




> Are the following instructions semantically same?<br>
>   %add2 = add nsw i32 %add, %add1<br>
>   %add3 = add        i32 %add, %add1<br>
><br>
> Based on my understanding from the Language Reference Manual, I think they<br>
> are different. But then why is the gvn pass detecting %add3 as redundant and deleting it?<br>
<br>
</div>On their common domain, the two instructions coincide. But the second<br>
one is defined for more pairs of input. That is, it's also defined<br>
when the (signed) sum overflows.<br>
<br>
So it's correct to eliminate the first one as redundant, in favour of<br>
the second, but not the reverse. This is what I see GVN doing too from<br>
my simple tests, do you have a complete .ll file where the wrong one<br>
is removed?<br>
<br>
Cheers.<br>
<br>
Tim.<br></div></div>
_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:LLVMdev@cs.uiuc.edu" target="_blank">LLVMdev@cs.uiuc.edu</a>         <a href="http://llvm.cs.uiuc.edu" target="_blank">http://llvm.cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a><br>
</blockquote></div><br></div>
</blockquote></div><br><br clear="all"><br></div></div><span class=""><font color="#888888">-- <br>Rekha
</font></span></div>
</blockquote></div><br></div></div>