Hi, I am trying to understand the semantics of Instructions in llvm. Are the following instructions semantically same? * %add2 = add nsw i32 %add, %add1 %add3 = add i32 %add, %add1* Based on my understanding from the Language Reference Manual, I think they are different. But then why is the *gvn* pass detecting *%add3* as redundant and deleting it? Your views are appreciated. Rekha -- Rekha -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20140723/b0bdfc10/attachment.html>
Tim Northover
2014-Jul-23 06:02 UTC
[LLVMdev] On semantics of add instruction - nsw,nuw flags
On 23 July 2014 06:25, Rekha R <rekharamapai at nitc.ac.in> wrote:> Are the following instructions semantically same? > %add2 = add nsw i32 %add, %add1 > %add3 = add i32 %add, %add1 > > Based on my understanding from the Language Reference Manual, I think they > are different. But then why is the gvn pass detecting %add3 as redundant and deleting it?On their common domain, the two instructions coincide. But the second one is defined for more pairs of input. That is, it's also defined when the (signed) sum overflows. So it's correct to eliminate the first one as redundant, in favour of the second, but not the reverse. This is what I see GVN doing too from my simple tests, do you have a complete .ll file where the wrong one is removed? Cheers. Tim.
Jeremy Lakeman
2014-Jul-23 06:12 UTC
[LLVMdev] On semantics of add instruction - nsw,nuw flags
IMHO; On undefined behaviour we can do whatever we want. If the "add nsw" overflows this would lead to undefined behaviour. Therefore we can assume that "add", with the same arguments will not overflow. On Wed, Jul 23, 2014 at 3:32 PM, Tim Northover <t.p.northover at gmail.com> wrote:> On 23 July 2014 06:25, Rekha R <rekharamapai at nitc.ac.in> wrote: > > Are the following instructions semantically same? > > %add2 = add nsw i32 %add, %add1 > > %add3 = add i32 %add, %add1 > > > > Based on my understanding from the Language Reference Manual, I think > they > > are different. But then why is the gvn pass detecting %add3 as redundant > and deleting it? > > On their common domain, the two instructions coincide. But the second > one is defined for more pairs of input. That is, it's also defined > when the (signed) sum overflows. > > So it's correct to eliminate the first one as redundant, in favour of > the second, but not the reverse. This is what I see GVN doing too from > my simple tests, do you have a complete .ll file where the wrong one > is removed? > > Cheers. > > Tim. > _______________________________________________ > LLVM Developers mailing list > LLVMdev at cs.uiuc.edu http://llvm.cs.uiuc.edu > http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20140723/2da04b74/attachment.html>
Possibly Parallel Threads
- [LLVMdev] On semantics of add instruction - nsw,nuw flags
- [LLVMdev] On semantics of add instruction - nsw,nuw flags
- [LLVMdev] On semantics of add instruction - nsw,nuw flags
- [LLVMdev] Appropriate DS for implementing worklist
- [LLVMdev] Appropriate DS for implementing worklist