[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.
This commit is contained in:
Nikita Popov 2022-03-14 14:34:01 +01:00
parent 64721a3312
commit da48f08abf
2 changed files with 30 additions and 1 deletions

View 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 {

View File

@ -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
}