[SCCP][IR] Landing pads are not safe to remove
authorNikita Popov <npopov@redhat.com>
Mon, 14 Mar 2022 13:34:01 +0000 (14:34 +0100)
committerNikita Popov <npopov@redhat.com>
Mon, 14 Mar 2022 13:59:32 +0000 (14:59 +0100)
For landingpads with {} type, SCCP ended up dropping them, because
we considered them as safe to remove.

llvm/lib/IR/Instruction.cpp
llvm/test/Transforms/SCCP/landingpad.ll [new file with mode: 0644]

index 9f1d5da..bf76c89 100644 (file)
@@ -698,7 +698,7 @@ bool Instruction::mayHaveSideEffects() const {
 
 bool Instruction::isSafeToRemove() const {
   return (!isa<CallInst>(this) || !this->mayHaveSideEffects()) &&
-         !this->isTerminator();
+         !this->isTerminator() && !this->isEHPad();
 }
 
 bool Instruction::willReturn() const {
diff --git a/llvm/test/Transforms/SCCP/landingpad.ll b/llvm/test/Transforms/SCCP/landingpad.ll
new file mode 100644 (file)
index 0000000..e07ef68
--- /dev/null
@@ -0,0 +1,29 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
+; RUN: opt -S -ipsccp < %s | FileCheck %s
+
+; SCCP should never remove landingpads.
+
+declare void @fn()
+
+define void @test() personality i8* null {
+; CHECK-LABEL: @test(
+; CHECK-NEXT:    invoke void @fn()
+; CHECK-NEXT:    to label [[SUCCESS:%.*]] unwind label [[FAILURE:%.*]]
+; CHECK:       success:
+; CHECK-NEXT:    ret void
+; CHECK:       failure:
+; CHECK-NEXT:    [[PAD:%.*]] = landingpad {}
+; CHECK-NEXT:    cleanup
+; CHECK-NEXT:    unreachable
+;
+  invoke void @fn()
+  to label %success unwind label %failure
+
+success:
+  ret void
+
+failure:
+  %pad = landingpad {}
+  cleanup
+  unreachable
+}