<div dir="ltr"><br><div class="gmail_extra"><br><br><div class="gmail_quote">On Wed, Jul 23, 2014 at 1:54 AM, Tobias Grosser <span dir="ltr"><<a href="mailto:tobias@grosser.es" target="_blank">tobias@grosser.es</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div class="">On 23/07/2014 09:46, Tim Northover wrote:<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">

Then why does the Release Note say<br>
" the operation is guaranteed to not overflow".<br>
</blockquote>
<br>
It means that the person who wrote the IR has guaranteed that there's<br>
no overflow (by some means) so LLVM can assume it during optimisation.<br>
<br>
This guarantee might come from doing explicit checks before executing<br>
the add/sub; or perhaps from performing the operation after a sext so<br>
that the type is guaranteed to be big enough; or (as in C) by trusting<br>
the programmer to make sure that doesn't happen.<br>
<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
What are the redundancies in the following code snip. Assume they appear in<br>
that order in a basic block.<br>
<br>
   Case1; %add2 = add nsw i32 %add, %add1<br>
              %add3 = add        i32 %add, %add1<br>
<br>
   Case2: %add2 = add        i32 %add, %add1<br>
              %add3 = add nsw i32 %add, %add1<br>
</blockquote>
<br>
In both cases the add with nsw can be removed in favour of the one<br>
without. Order is completely irrelevant for normal LLVM arithmetic<br>
instructions.<br>
</blockquote>
<br></div>
Tim,<br>
<br>
if both instructions are right after each other such that we know that either none of them or both will be executed, is there a way to leave the nsw flag taking advantage of the knowledge that any pair of values<br>
that cause nsw in the instruction that originally had now nsw flag is already known to break the nsw assumption of the other instruction<br>
and causes consequently undefined behaviour?<br></blockquote><div><br></div><div>No; the motivation for poison values (formerly named trap values, if anyone is reading the rationale linked to earlier in the thread) is to defer undefined behavior until execution can no longer be speculative. The location where a poison value is produced isn't significant. What's important is the location of the use of a poison value (and how it's used).<br>
</div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
The langref description is a little surprising, as it seems the undefined behaviour only is invoked is the resulting poison value is<br>
actually used:<br>
<br>
"Poison Values have the same behavior as undef values, with the additional affect that any instruction which has a dependence on a poison value has undefined behavior."<br></blockquote><div><br></div><div>Correct. nsw isn't a guarantee that overflow won't occur. It is (intended to be) a guarantee that if overflow does occur, the program will avoid using the result for anything important (roughly speaking).<br>
<br></div><div>Dan<br><br></div></div></div></div>