[llvm] r252370 - [InstCombine] Don't insert an instruction after a terminator

David Majnemer via llvm-commits llvm-commits at lists.llvm.org
Fri Nov 6 15:59:23 PST 2015


Author: majnemer
Date: Fri Nov  6 17:59:23 2015
New Revision: 252370

URL: http://llvm.org/viewvc/llvm-project?rev=252370&view=rev
Log:
[InstCombine] Don't insert an instruction after a terminator

We tried to insert a cast of a phi in a block whose terminator is an
EHPad.  This is invalid.  Do not attempt the transform in these
circumstances.

Modified:
    llvm/trunk/lib/Transforms/InstCombine/InstCombinePHI.cpp
    llvm/trunk/test/Transforms/InstCombine/token.ll

Modified: llvm/trunk/lib/Transforms/InstCombine/InstCombinePHI.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/InstCombine/InstCombinePHI.cpp?rev=252370&r1=252369&r2=252370&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/InstCombine/InstCombinePHI.cpp (original)
+++ llvm/trunk/lib/Transforms/InstCombine/InstCombinePHI.cpp Fri Nov  6 17:59:23 2015
@@ -469,6 +469,12 @@ Instruction *InstCombiner::FoldPHIArgZex
 /// only used by the PHI, PHI together their inputs, and do the operation once,
 /// to the result of the PHI.
 Instruction *InstCombiner::FoldPHIArgOpIntoPHI(PHINode &PN) {
+  // We cannot create a new instruction after the PHI if the terminator is an
+  // EHPad because there is no valid insertion point.
+  if (TerminatorInst *TI = PN.getParent()->getTerminator())
+    if (TI->isEHPad())
+      return nullptr;
+
   Instruction *FirstInst = cast<Instruction>(PN.getIncomingValue(0));
 
   if (isa<GetElementPtrInst>(FirstInst))

Modified: llvm/trunk/test/Transforms/InstCombine/token.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/InstCombine/token.ll?rev=252370&r1=252369&r2=252370&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/InstCombine/token.ll (original)
+++ llvm/trunk/test/Transforms/InstCombine/token.ll Fri Nov  6 17:59:23 2015
@@ -4,7 +4,7 @@ target triple = "x86_64-pc-windows-msvc1
 
 declare i32 @__CxxFrameHandler3(...)
 
-define i8* @f() personality i32 (...)* @__CxxFrameHandler3 {
+define void @test1() personality i32 (...)* @__CxxFrameHandler3 {
 bb:
   unreachable
 
@@ -13,9 +13,45 @@ unreachable:
   cleanupret %cl unwind to caller
 }
 
+; CHECK-LABEL: define void @test1(
 ; CHECK: unreachable:
 ; CHECK:   %cl = cleanuppad []
 ; CHECK:   cleanupret %cl unwind to caller
 
+define void @test2(i8 %A, i8 %B) personality i32 (...)* @__CxxFrameHandler3 {
+bb:
+  %X = zext i8 %A to i32
+  invoke void @g(i32 0)
+    to label %cont
+    unwind label %catch
+
+cont:
+  %Y = zext i8 %B to i32
+  invoke void @g(i32 0)
+    to label %unreachable
+    unwind label %catch
+
+catch:
+  %phi = phi i32 [ %X, %bb ], [ %Y, %cont ]
+  %cl = catchpad []
+   to label %doit
+   unwind label %endpad
+
+doit:
+  call void @g(i32 %phi)
+  unreachable
+
+unreachable:
+  unreachable
+
+endpad:
+  catchendpad unwind to caller
+}
+
+
+; CHECK-LABEL: define void @test2(
+; CHECK:  %X = zext i8 %A to i32
+; CHECK:  %Y = zext i8 %B to i32
+; CHECK:  %phi = phi i32 [ %X, %bb ], [ %Y, %cont ]
 
-declare void @g(i8*)
+declare void @g(i32)




More information about the llvm-commits mailing list