<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Tue, Nov 4, 2014 at 12:28 AM, Nick Lewycky <span dir="ltr"><<a href="mailto:nicholas@mxc.ca" target="_blank">nicholas@mxc.ca</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">NAK. Please don't commit this.</blockquote><div><br></div><div>I committed it yesterday with r221223.  The submitted code replaced setPreservesCFG with addPreserved<DominatorTreeWrapperPass> and addPreserved<LoopInfo>.</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><span class="">
  The reason<br>
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
is that InstCombine can modify terminator instructions (branches)<br>
specifically the predicate.<br>
</blockquote>
<br></span>
This is the thing where it removes an '%newcond = xor %cond, true' and switches 'br %newcond, label %A, label %B' with 'br %cond, label %B, label %A'?<br>
<br>
If it's actually causing you problems, please just move that transform to simplifycfg instead of removing preserves-cfg from instcombine.</blockquote><div><br></div><div>The problem I encountered is in instcombine where it clears out instructions from unreachable BB's and replaces their uses with undef:</div><div><br></div><div><a href="http://llvm.org/docs/doxygen/html/InstructionCombining_8cpp_source.html#l02796">http://llvm.org/docs/doxygen/html/InstructionCombining_8cpp_source.html#l02796</a> </div><div><br></div><div>These uses can include branch predicates.  Loop simplify then turns these 'bra undefs' at loop latches to always exit so loopsimplify is not preserved so setPreservesCfg should not be used by instcombine.... or am I missing something?</div><div><br></div><div>Mark</div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><span class=""><font color="#888888">
Nick</font></span><div><div class="h5"><br>
<br>
  Instcombine clears out dead blocks and<br>
</div></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div><div class="h5">
replaces all the dead instruction uses with undef:<br>
<br>
<a href="http://llvm.org/docs/doxygen/html/InstructionCombining_8cpp_source.html#l02792" target="_blank">http://llvm.org/docs/doxygen/<u></u>html/InstructionCombining_<u></u>8cpp_source.html#l02792</a><br>
<br>
These new undefs can be predicates of branches, and from the comment<br>
of setPreservesCFG():<br>
<br>
// setPreservesCFG - This function should be called to by the pass, iff<br>
they do<br>
// not:<br>
//<br>
//  1. Add or remove basic blocks from the function<br>
//  2. Modify terminator instructions in any way.<br>
<br>
Clearly instcombine is modifying terminator instructions so should not<br>
be calling setPreservesCFG().  The specific issue I ran into was a dead<br>
loop not being deleted because of stale analysis data.  Repro:<br>
<br>
void foo(int *a, int start_x, int end_x, int start_y, int end_y, int k) {<br>
   for (int y = start_y; y < end_y; y++) {<br>
     for (int x = start_x; x < end_x; x++) {<br>
       for (int i = 0; i < 1000; i++) {<br>
         a[x + y + k*i] = 0;<br>
       }<br>
     }<br>
   }<br>
}<br>
<br>
# Dead loop left after loop deletion:<br>
clang -S -emit-llvm foo.c -o - | opt -O1 -loop-rotate -loop-unswitch<br>
-instcombine -loop-deletion -S > bad.ll<br>
<br>
# Dead loop removed by splitting out loop-deletion into separate opt<br>
invocation:<br>
clang -S -emit-llvm foo.c -o - | opt -O1 -loop-rotate -loop-unswitch<br>
-instcombine | opt -loop-deletion -S > good.ll<br>
<br>
This patch fixes this discrepancy.<br>
<br>
Mark<br>
<br>
<br></div></div><span class="">
______________________________<u></u>_________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@cs.uiuc.edu" target="_blank">llvm-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" target="_blank">http://lists.cs.uiuc.edu/<u></u>mailman/listinfo/llvm-commits</a><br>
</span></blockquote>
<br>
</blockquote></div><br></div></div>