From da48f08abf3cb26d1fce4a6909c4fe2e63278d80 Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Mon, 14 Mar 2022 14:34:01 +0100 Subject: [PATCH] [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. --- llvm/lib/IR/Instruction.cpp | 2 +- llvm/test/Transforms/SCCP/landingpad.ll | 29 +++++++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 1 deletion(-) create mode 100644 llvm/test/Transforms/SCCP/landingpad.ll diff --git a/llvm/lib/IR/Instruction.cpp b/llvm/lib/IR/Instruction.cpp index 9f1d5da..bf76c89 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(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 0000000..e07ef68 --- /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 +} -- 2.7.4