<div dir="auto">Just yesterday I talked to Dan Gohman, who suggested we strip nowrap flags when speculating. It solves a lot of poison problems.</div><div class="gmail_extra"><br><div class="gmail_quote">On Feb 3, 2017 5:49 AM, "Hal Finkel via llvm-dev" <<a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a>> wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br>
On 02/03/2017 07:28 AM, Artur Pilipenko wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
I'm looking at the bug (<a href="https://llvm.org/bugs/show_bug.cgi?id=31181" rel="noreferrer" target="_blank">https://llvm.org/bugs/show_bu<wbr>g.cgi?id=31181</a>) which was triggered by my change to make CVP mark adds as no wrap (<a href="https://reviews.llvm.org/rL278220" rel="noreferrer" target="_blank">https://reviews.llvm.org/rL27<wbr>8220</a>) and I'd like to have some broader discussion of the problem. In this bug CVP correctly marks an add as nuw basing on the loop latch check, but later loop rotation pass moves the add to a point before the check. In the new context nuw is no longer valid and leads to an incorrect transformation of the loop. See <a href="https://llvm.org/bugs/show_bug.cgi?id=31181#c5" rel="noreferrer" target="_blank">https://llvm.org/bugs/show_bug<wbr>.cgi?id=31181#c5</a> comment in the bug for more details.<br>
<br>
Since nsw, nuw flags can be control dependent, it seems like we should be treating them as metadata, i.e. we should be stripping them when we speculate the instruction. I don’t think that we are doing this now anywhere. The problem was noticed on loop rotation, but I expect any other pass which speculates overflowing operations is suffering from the same problem.<br>
<br>
Thoughts?<br>
</blockquote>
<br>
We generally don't strip these because violating the wrapping constraint does not immediately cause UB. Instead, it generates a poison value. So long as that poison value is not used in way which causes UB, then everything is fine. In this case, I suspect that we want to fix IndVars to strip the flag, or not do the transformation, when it might introduce this kind of issue (i.e. a situation where we might branch on a poison value).<br>
<br>
 -Hal<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
Artur<br>
</blockquote>
<br>
-- <br>
Hal Finkel<br>
Lead, Compiler Technology and Programming Languages<br>
Leadership Computing Facility<br>
Argonne National Laboratory<br>
<br>
______________________________<wbr>_________________<br>
LLVM Developers mailing list<br>
<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/llvm-dev</a><br>
</blockquote></div></div>