[llvm] r256763 - [LICM] Don't insert instructions after a catchswitch when performing loop promotion

David Majnemer via llvm-commits llvm-commits at lists.llvm.org
Mon Jan 4 09:42:19 PST 2016


Author: majnemer
Date: Mon Jan  4 11:42:19 2016
New Revision: 256763

URL: http://llvm.org/viewvc/llvm-project?rev=256763&view=rev
Log:
[LICM] Don't insert instructions after a catchswitch when performing loop promotion

Inserting after a catchswitch results in verifier errors, bail out on
promotion if a catchswitch is a loop exit.

Modified:
    llvm/trunk/lib/Transforms/Scalar/LICM.cpp
    llvm/trunk/test/Transforms/LICM/funclet.ll

Modified: llvm/trunk/lib/Transforms/Scalar/LICM.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/LICM.cpp?rev=256763&r1=256762&r2=256763&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/LICM.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/LICM.cpp Mon Jan  4 11:42:19 2016
@@ -1009,6 +1009,21 @@ bool llvm::promoteLoopAccessesToScalars(
   if (!GuaranteedToExecute)
     return Changed;
 
+  // Figure out the loop exits and their insertion points, if this is the
+  // first promotion.
+  if (ExitBlocks.empty()) {
+    CurLoop->getUniqueExitBlocks(ExitBlocks);
+    InsertPts.clear();
+    InsertPts.reserve(ExitBlocks.size());
+    for (BasicBlock *ExitBlock : ExitBlocks) {
+      // Can't insert into a catchswitch.
+      if (isa<CatchSwitchInst>(ExitBlock->getTerminator()))
+        return Changed;
+
+      InsertPts.push_back(&*ExitBlock->getFirstInsertionPt());
+    }
+  }
+
   // Otherwise, this is safe to promote, lets do it!
   DEBUG(dbgs() << "LICM: Promoting value stored to in loop: " <<*SomePtr<<'\n');
   Changed = true;
@@ -1020,15 +1035,6 @@ bool llvm::promoteLoopAccessesToScalars(
   // location is better than none.
   DebugLoc DL = LoopUses[0]->getDebugLoc();
 
-  // Figure out the loop exits and their insertion points, if this is the
-  // first promotion.
-  if (ExitBlocks.empty()) {
-    CurLoop->getUniqueExitBlocks(ExitBlocks);
-    InsertPts.resize(ExitBlocks.size());
-    for (unsigned i = 0, e = ExitBlocks.size(); i != e; ++i)
-      InsertPts[i] = &*ExitBlocks[i]->getFirstInsertionPt();
-  }
-
   // We use the SSAUpdater interface to insert phi nodes as required.
   SmallVector<PHINode*, 16> NewPHIs;
   SSAUpdater SSA(&NewPHIs);

Modified: llvm/trunk/test/Transforms/LICM/funclet.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/LICM/funclet.ll?rev=256763&r1=256762&r2=256763&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/LICM/funclet.ll (original)
+++ llvm/trunk/test/Transforms/LICM/funclet.ll Mon Jan  4 11:42:19 2016
@@ -60,6 +60,42 @@ try.cont:
 ; CHECK-NEXT: store i32 %[[CALL]], i32* %s
 ; CHECK-NEXT: cleanupret from %[[CP]] unwind to caller
 
+define void @test3(i1 %a, i1 %b, i1 %c) personality i32 (...)* @__CxxFrameHandler3 {
+entry:
+  %.frame = alloca i8, align 4
+  %bc = bitcast i8* %.frame to i32*
+  br i1 %a, label %try.success.or.caught, label %forbody
+
+catch.object.Throwable:                           ; preds = %catch.dispatch
+  %cp = catchpad within %cs [i8* null, i32 64, i8* null]
+  unreachable
+
+try.success.or.caught:                            ; preds = %forcond.backedge, %0
+  ret void
+
+postinvoke:                                       ; preds = %forbody
+  br i1 %b, label %else, label %forcond.backedge
+
+forcond.backedge:                                 ; preds = %else, %postinvoke
+  br i1 %c, label %try.success.or.caught, label %forbody
+
+catch.dispatch:                                   ; preds = %else, %forbody
+  %cs = catchswitch within none [label %catch.object.Throwable] unwind to caller
+
+forbody:                                          ; preds = %forcond.backedge, %0
+  store i32 1, i32* %bc, align 4
+  invoke void @may_throw()
+          to label %postinvoke unwind label %catch.dispatch
+
+else:                                             ; preds = %postinvoke
+  invoke void @may_throw()
+          to label %forcond.backedge unwind label %catch.dispatch
+}
+
+; CHECK-LABEL: define void @test3(
+; CHECK:      catchswitch within none
+; CHECK:      store i32 1, i32* %bc, align 4
+
 declare void @may_throw()
 
 declare i32 @pure_computation() nounwind argmemonly readonly




More information about the llvm-commits mailing list