[llvm] da48f08 - [SCCP][IR] Landing pads are not safe to remove
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Mon Mar 14 06:59:43 PDT 2022
Author: Nikita Popov
Date: 2022-03-14T14:59:32+01:00
New Revision: da48f08abf3cb26d1fce4a6909c4fe2e63278d80
URL: https://github.com/llvm/llvm-project/commit/da48f08abf3cb26d1fce4a6909c4fe2e63278d80
DIFF: https://github.com/llvm/llvm-project/commit/da48f08abf3cb26d1fce4a6909c4fe2e63278d80.diff
LOG: [SCCP][IR] Landing pads are not safe to remove
For landingpads with {} type, SCCP ended up dropping them, because
we considered them as safe to remove.
Added:
llvm/test/Transforms/SCCP/landingpad.ll
Modified:
llvm/lib/IR/Instruction.cpp
Removed:
################################################################################
diff --git a/llvm/lib/IR/Instruction.cpp b/llvm/lib/IR/Instruction.cpp
index 9f1d5dabf14b5..bf76c89f26ca8 100644
--- a/llvm/lib/IR/Instruction.cpp
+++ b/llvm/lib/IR/Instruction.cpp
@@ -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
index 0000000000000..e07ef689ac02a
--- /dev/null
+++ b/llvm/test/Transforms/SCCP/landingpad.ll
@@ -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
+}
More information about the llvm-commits
mailing list