summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--llvm/lib/Transforms/IPO/Attributor.cpp22
-rw-r--r--llvm/test/Transforms/FunctionAttrs/liveness.ll4
-rw-r--r--llvm/test/Transforms/FunctionAttrs/noreturn_async.ll8
-rw-r--r--llvm/test/Transforms/FunctionAttrs/noreturn_sync.ll4
4 files changed, 22 insertions, 16 deletions
diff --git a/llvm/lib/Transforms/IPO/Attributor.cpp b/llvm/lib/Transforms/IPO/Attributor.cpp
index 08675de6cb1..2778daf9fab 100644
--- a/llvm/lib/Transforms/IPO/Attributor.cpp
+++ b/llvm/lib/Transforms/IPO/Attributor.cpp
@@ -2139,8 +2139,6 @@ struct AAIsDeadImpl : public AAIsDead {
BasicBlock *BB = I->getParent();
Instruction *SplitPos = I->getNextNode();
// TODO: mark stuff before unreachable instructions as dead.
- if (isa_and_nonnull<UnreachableInst>(SplitPos))
- continue;
if (auto *II = dyn_cast<InvokeInst>(I)) {
// If we keep the invoke the split position is at the beginning of the
@@ -2183,15 +2181,23 @@ struct AAIsDeadImpl : public AAIsDead {
// also manifest.
assert(!NormalDestBB->isLandingPad() &&
"Expected the normal destination not to be a landingpad!");
- BasicBlock *SplitBB =
- SplitBlockPredecessors(NormalDestBB, {BB}, ".dead");
- // The split block is live even if it contains only an unreachable
- // instruction at the end.
- assumeLive(A, *SplitBB);
- SplitPos = SplitBB->getTerminator();
+ if (NormalDestBB->getUniquePredecessor() == BB) {
+ assumeLive(A, *NormalDestBB);
+ } else {
+ BasicBlock *SplitBB =
+ SplitBlockPredecessors(NormalDestBB, {BB}, ".dead");
+ // The split block is live even if it contains only an unreachable
+ // instruction at the end.
+ assumeLive(A, *SplitBB);
+ SplitPos = SplitBB->getTerminator();
+ HasChanged = ChangeStatus::CHANGED;
+ }
}
}
+ if (isa_and_nonnull<UnreachableInst>(SplitPos))
+ continue;
+
BB = SplitPos->getParent();
SplitBlock(BB, SplitPos);
changeToUnreachable(BB->getTerminator(), /* UseLLVMTrap */ false);
diff --git a/llvm/test/Transforms/FunctionAttrs/liveness.ll b/llvm/test/Transforms/FunctionAttrs/liveness.ll
index b75887efb8f..b6a4900d2af 100644
--- a/llvm/test/Transforms/FunctionAttrs/liveness.ll
+++ b/llvm/test/Transforms/FunctionAttrs/liveness.ll
@@ -177,7 +177,7 @@ cond.true: ; preds = %entry
%call = invoke i32 @foo_noreturn() to label %continue
unwind label %cleanup
; CHECK: %call = invoke i32 @foo_noreturn()
- ; CHECK-NEXT: to label %continue.dead unwind label %cleanup
+ ; CHECK-NEXT: to label %continue unwind label %cleanup
cond.false: ; preds = %entry
call void @normal_call()
@@ -189,7 +189,7 @@ cond.end: ; preds = %cond.false, %contin
ret i32 %cond
continue:
- ; CHECK: continue.dead:
+ ; CHECK: continue:
; CHECK-NEXT: unreachable
br label %cond.end
diff --git a/llvm/test/Transforms/FunctionAttrs/noreturn_async.ll b/llvm/test/Transforms/FunctionAttrs/noreturn_async.ll
index e9e423688df..e06a13f40c5 100644
--- a/llvm/test/Transforms/FunctionAttrs/noreturn_async.ll
+++ b/llvm/test/Transforms/FunctionAttrs/noreturn_async.ll
@@ -42,12 +42,12 @@ entry:
%retval = alloca i32, align 4
%__exception_code = alloca i32, align 4
; CHECK: invoke void @"?overflow@@YAXXZ"()
-; CHECK: to label %invoke.cont.dead unwind label %catch.dispatch
+; CHECK: to label %invoke.cont unwind label %catch.dispatch
invoke void @"?overflow@@YAXXZ"()
to label %invoke.cont unwind label %catch.dispatch
invoke.cont: ; preds = %entry
-; CHECK: invoke.cont.dead:
+; CHECK: invoke.cont:
; CHECK-NEXT: unreachable
br label %invoke.cont1
@@ -101,12 +101,12 @@ entry:
%retval = alloca i32, align 4
%__exception_code = alloca i32, align 4
; CHECK: invoke void @"?overflow@@YAXXZ_may_throw"()
-; CHECK: to label %invoke.cont.dead unwind label %catch.dispatch
+; CHECK: to label %invoke.cont unwind label %catch.dispatch
invoke void @"?overflow@@YAXXZ_may_throw"()
to label %invoke.cont unwind label %catch.dispatch
invoke.cont: ; preds = %entry
-; CHECK: invoke.cont.dead:
+; CHECK: invoke.cont:
; CHECK-NEXT: unreachable
br label %invoke.cont1
diff --git a/llvm/test/Transforms/FunctionAttrs/noreturn_sync.ll b/llvm/test/Transforms/FunctionAttrs/noreturn_sync.ll
index 5d644965fb2..423a369f704 100644
--- a/llvm/test/Transforms/FunctionAttrs/noreturn_sync.ll
+++ b/llvm/test/Transforms/FunctionAttrs/noreturn_sync.ll
@@ -97,12 +97,12 @@ entry:
%retval = alloca i32, align 4
%__exception_code = alloca i32, align 4
; CHECK: invoke void @"?overflow@@YAXXZ_may_throw"()
-; CHECK: to label %invoke.cont.dead unwind label %catch.dispatch
+; CHECK: to label %invoke.cont unwind label %catch.dispatch
invoke void @"?overflow@@YAXXZ_may_throw"()
to label %invoke.cont unwind label %catch.dispatch
invoke.cont: ; preds = %entry
-; CHECK: invoke.cont.dead:
+; CHECK: invoke.cont:
; CHECK-NEXT: unreachable
br label %invoke.cont1
OpenPOWER on IntegriCloud