<div dir="ltr">Could we get this merged into 3.8?<div class="gmail_extra"><br><div class="gmail_quote">On Wed, Feb 3, 2016 at 1:30 PM, David Majnemer 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">Author: majnemer<br>
Date: Wed Feb  3 15:30:34 2016<br>
New Revision: 259702<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=259702&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=259702&view=rev</a><br>
Log:<br>
[LoopStrengthReduce] Don't rewrite PHIs with incoming values from CatchSwitches<br>
<br>
Bail out if we have a PHI on an EHPad that gets a value from a<br>
CatchSwitchInst.  Because the CatchSwitchInst cannot be split, there is<br>
no good place to stick any instructions.<br>
<br>
This fixes PR26373.<br>
<br>
Modified:<br>
    llvm/trunk/include/llvm/IR/Instructions.h<br>
    llvm/trunk/lib/Transforms/Scalar/LoopStrengthReduce.cpp<br>
    llvm/trunk/test/Transforms/LoopStrengthReduce/funclet.ll<br>
<br>
Modified: llvm/trunk/include/llvm/IR/Instructions.h<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/Instructions.h?rev=259702&r1=259701&r2=259702&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/include/llvm/IR/Instructions.h?rev=259702&r1=259701&r2=259702&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/include/llvm/IR/Instructions.h (original)<br>
+++ llvm/trunk/include/llvm/IR/Instructions.h Wed Feb  3 15:30:34 2016<br>
@@ -2512,6 +2512,14 @@ public:<br>
     return block_begin() + getNumOperands();<br>
   }<br>
<br>
+  iterator_range<block_iterator> blocks() {<br>
+    return make_range(block_begin(), block_end());<br>
+  }<br>
+<br>
+  iterator_range<const_block_iterator> blocks() const {<br>
+    return make_range(block_begin(), block_end());<br>
+  }<br>
+<br>
   op_range incoming_values() { return operands(); }<br>
<br>
   const_op_range incoming_values() const { return operands(); }<br>
<br>
Modified: llvm/trunk/lib/Transforms/Scalar/LoopStrengthReduce.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/LoopStrengthReduce.cpp?rev=259702&r1=259701&r2=259702&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/LoopStrengthReduce.cpp?rev=259702&r1=259701&r2=259702&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/Transforms/Scalar/LoopStrengthReduce.cpp (original)<br>
+++ llvm/trunk/lib/Transforms/Scalar/LoopStrengthReduce.cpp Wed Feb  3 15:30:34 2016<br>
@@ -4799,6 +4799,17 @@ LSRInstance::LSRInstance(Loop *L, IVUser<br>
       DEBUG(dbgs() << "LSR skipping loop, too many IV Users in " << U << "\n");<br>
       return;<br>
     }<br>
+    // Bail out if we have a PHI on an EHPad that gets a value from a<br>
+    // CatchSwitchInst.  Because the CatchSwitchInst cannot be split, there is<br>
+    // no good place to stick any instructions.<br>
+    if (auto *PN = dyn_cast<PHINode>(U.getUser())) {<br>
+       auto *FirstNonPHI = PN->getParent()->getFirstNonPHI();<br>
+       if (isa<FuncletPadInst>(FirstNonPHI) ||<br>
+           isa<CatchSwitchInst>(FirstNonPHI))<br>
+         for (BasicBlock *PredBB : PN->blocks())<br>
+           if (isa<CatchSwitchInst>(PredBB->getFirstNonPHI()))<br>
+             return;<br>
+    }<br>
   }<br>
<br>
 #ifndef NDEBUG<br>
<br>
Modified: llvm/trunk/test/Transforms/LoopStrengthReduce/funclet.ll<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/LoopStrengthReduce/funclet.ll?rev=259702&r1=259701&r2=259702&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/LoopStrengthReduce/funclet.ll?rev=259702&r1=259701&r2=259702&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/test/Transforms/LoopStrengthReduce/funclet.ll (original)<br>
+++ llvm/trunk/test/Transforms/LoopStrengthReduce/funclet.ll Wed Feb  3 15:30:34 2016<br>
@@ -214,3 +214,32 @@ try.cont.7:<br>
<br>
 ; CHECK: catch.dispatch.2:<br>
 ; CHECK: %e.0 = phi i32* [ %c, %try.cont ], [ %b, %catch.dispatch ]<br>
+<br>
+define i32 @test2() personality i32 (...)* @_except_handler3 {<br>
+entry:<br>
+  br label %for.body<br>
+<br>
+for.body:                                         ; preds = %for.inc, %entry<br>
+  %phi = phi i32 [ %inc, %for.inc ], [ 0, %entry ]<br>
+  invoke void @reserve()<br>
+          to label %for.inc unwind label %catch.dispatch<br>
+<br>
+catch.dispatch:                                   ; preds = %for.body<br>
+  %tmp18 = catchswitch within none [label %catch.handler] unwind to caller<br>
+<br>
+catch.handler:                                    ; preds = %catch.dispatch<br>
+  %phi.lcssa = phi i32 [ %phi, %catch.dispatch ]<br>
+  %tmp19 = catchpad within %tmp18 [i8* null]<br>
+  catchret from %tmp19 to label %done<br>
+<br>
+done:<br>
+  ret i32 %phi.lcssa<br>
+<br>
+for.inc:                                          ; preds = %for.body<br>
+  %inc = add i32 %phi, 1<br>
+  br label %for.body<br>
+}<br>
+<br>
+; CHECK-LABEL: define i32 @test2(<br>
+; CHECK:      %phi.lcssa = phi i32 [ %phi, %catch.dispatch ]<br>
+; CHECK-NEXT: catchpad within<br>
<br>
<br>
_______________________________________________<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/mailman/listinfo/llvm-commits</a><br>
</blockquote></div><br></div></div>