[llvm] r271816 - [SimplifyCFG] Don't kill empty cleanuppads with multiple uses

David Majnemer via llvm-commits llvm-commits at lists.llvm.org
Sat Jun 4 16:50:04 PDT 2016


Author: majnemer
Date: Sat Jun  4 18:50:03 2016
New Revision: 271816

URL: http://llvm.org/viewvc/llvm-project?rev=271816&view=rev
Log:
[SimplifyCFG] Don't kill empty cleanuppads with multiple uses

A basic block could contain:
  %cp = cleanuppad []
  cleanupret from %cp unwind to caller

This basic block is empty and is thus a candidate for removal.  However,
there can be other uses of %cp outside of this basic block.  This is
only possible in unreachable blocks.

Make our transform more correct by checking that the pad has a single
user before removing the BB.

This fixes PR28005.

Modified:
    llvm/trunk/lib/Transforms/Utils/SimplifyCFG.cpp
    llvm/trunk/test/Transforms/SimplifyCFG/empty-cleanuppad.ll

Modified: llvm/trunk/lib/Transforms/Utils/SimplifyCFG.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/SimplifyCFG.cpp?rev=271816&r1=271815&r2=271816&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Utils/SimplifyCFG.cpp (original)
+++ llvm/trunk/lib/Transforms/Utils/SimplifyCFG.cpp Sat Jun  4 18:50:03 2016
@@ -3424,6 +3424,11 @@ static bool removeEmptyCleanup(CleanupRe
     // This isn't an empty cleanup.
     return false;
 
+  // We cannot kill the pad if it has multiple uses.  This typically arises
+  // from unreachable basic blocks.
+  if (!CPInst->hasOneUse())
+    return false;
+
   // Check that there are no other instructions except for benign intrinsics.
   BasicBlock::iterator I = CPInst->getIterator(), E = RI->getIterator();
   while (++I != E) {

Modified: llvm/trunk/test/Transforms/SimplifyCFG/empty-cleanuppad.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/SimplifyCFG/empty-cleanuppad.ll?rev=271816&r1=271815&r2=271816&view=diff
==============================================================================
--- llvm/trunk/test/Transforms/SimplifyCFG/empty-cleanuppad.ll (original)
+++ llvm/trunk/test/Transforms/SimplifyCFG/empty-cleanuppad.ll Sat Jun  4 18:50:03 2016
@@ -434,6 +434,30 @@ try.cont:
   ret i32 0
 }
 
+; CHECK-LABEL: define void @f10(
+define void @f10(i32 %V) personality i32 (...)* @__CxxFrameHandler3 {
+entry:
+  invoke void @g()
+          to label %unreachable unwind label %cleanup
+; CHECK:       call void @g()
+; CHECK-NEXT:  unreachable
+
+unreachable:
+  unreachable
+
+cleanup:
+  %cp = cleanuppad within none []
+  switch i32 %V, label %cleanupret1 [
+    i32 0, label %cleanupret2
+  ]
+
+cleanupret1:
+  cleanupret from %cp unwind to caller
+
+cleanupret2:
+  cleanupret from %cp unwind to caller
+}
+
 %struct.S = type { i8 }
 %struct.S2 = type { i8 }
 declare void @"\01??1S2@@QEAA at XZ"(%struct.S2*)




More information about the llvm-commits mailing list