<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">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>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="">On 23 July 2014 06:25, Rekha R <<a href="mailto:rekharamapai@nitc.ac.in">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>
_______________________________________________<br>
LLVM Developers mailing list<br>
<a href="mailto:LLVMdev@cs.uiuc.edu">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>