<div dir="ltr">Will we need to change the shufflevector <<a href="http://llvm.org/docs/LangRef.html#shufflevector-instruction">http://llvm.org/docs/LangRef.html#shufflevector-instruction</a>> semantics? It defines undef to be meaningful for the second vector.</div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, Jan 24, 2017 at 10:37 AM, Friedman, Eli via llvm-commits <span dir="ltr"><<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="HOEnZb"><div class="h5">On 1/23/2017 4:15 AM, Nuno Lopes via llvm-commits wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hi,<br>
<br>
Following our talk at the LLVM dev meeting regarding poison, we would like to introduce the freeze instruction in the LLVM IR so that we can fix a longstanding bug in loop unswitch.<br>
In the talk I mentioned a bigger proposal with several orthogonal changes. We are now splitting that proposal in smaller pieces, and this set of patches is the first piece.  These pieces are independent and can be reviewed independently.<br>
Juneyoung Lee implemented the whole thing; I'm just the messenger.<br>
<br>
A few details about the problem:<br>
<br>
Loop unswitch does the following transformation:<br>
  while (...) {<br>
    if (C) { A }<br>
    else   { B }<br>
  }<br>
<br>
into:<br>
  if (C) {<br>
    while (...) { A }<br>
  } else {<br>
    while (...) { B }<br>
  }<br>
<br>
<br>
This transformation is incorrect if C may be poison/undef, since branching on poison/undef is UB. If, for example, the loop never executed, the transformed code would be branching on C while the original was not, and so we introduced UB (if C is undef/poison).<br>
<br>
This has been shown to lead to end-to-end miscompilations when loop unswitch is combined with other passes, like GVN:<br>
 - <a href="https://llvm.org/bugs/show_bug.cgi?id=27506" rel="noreferrer" target="_blank">https://llvm.org/bugs/show_bug<wbr>.cgi?id=27506</a><br>
 - <a href="https://llvm.org/bugs/show_bug.cgi?id=31652" rel="noreferrer" target="_blank">https://llvm.org/bugs/show_bug<wbr>.cgi?id=31652</a><br>
<br>
<br>
We propose a simple change, which is to transform the code above into:<br>
  C' = freeze(c)<br>
  if (C') {<br>
    while (...) { A }<br>
  } else {<br>
    while (...) { B }<br>
  }<br>
<br>
<br>
Freeze always returns a non-poison/undef value. When given a poison/undef value, it returns a non-deterministic value that is fixed for all uses.<br>
<br>
<br>
We've split the changes in 5 patches:<br>
 - Add Freeze instruction to IR: <a href="https://reviews.llvm.org/D29011" rel="noreferrer" target="_blank">https://reviews.llvm.org/D2901<wbr>1</a><br>
 - InstCombine/InstSimplify support for freeze: <a href="https://reviews.llvm.org/D29013" rel="noreferrer" target="_blank">https://reviews.llvm.org/D2901<wbr>3</a><br>
 - SelectionDAG support for freeze: <a href="https://reviews.llvm.org/D29014" rel="noreferrer" target="_blank">https://reviews.llvm.org/D2901<wbr>4</a><br>
 - Fix wrong code emission by loop unswitch: <a href="https://reviews.llvm.org/D29015" rel="noreferrer" target="_blank">https://reviews.llvm.org/D2901<wbr>5</a><br>
 - Optimize placement of freeze in loop unswitch: <a href="https://reviews.llvm.org/D29016" rel="noreferrer" target="_blank">https://reviews.llvm.org/D2901<wbr>6</a><br>
</blockquote>
<br></div></div>
I'm not seeing any patch in this series with the necessary changes to LangRef?<br>
<br>
-Eli<span class="HOEnZb"><font color="#888888"><br>
<br>
-- <br>
Employee of Qualcomm Innovation Center, Inc.<br>
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project</font></span><div class="HOEnZb"><div class="h5"><br>
<br>
______________________________<wbr>_________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@lists.llvm.org" target="_blank">llvm-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/llvm-commits</a><br>
</div></div></blockquote></div><br></div>