summaryrefslogtreecommitdiff
path: root/llvm/lib/CodeGen/WinEHPrepare.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/lib/CodeGen/WinEHPrepare.cpp')
-rw-r--r--llvm/lib/CodeGen/WinEHPrepare.cpp20
1 files changed, 17 insertions, 3 deletions
diff --git a/llvm/lib/CodeGen/WinEHPrepare.cpp b/llvm/lib/CodeGen/WinEHPrepare.cpp
index 253a3887009a..37f6726bafca 100644
--- a/llvm/lib/CodeGen/WinEHPrepare.cpp
+++ b/llvm/lib/CodeGen/WinEHPrepare.cpp
@@ -866,9 +866,6 @@ void WinEHPrepareImpl::demotePHIsOnFunclets(Function &F,
for (BasicBlock &BB : make_early_inc_range(F)) {
if (!BB.isEHPad())
continue;
- if (DemoteCatchSwitchPHIOnly &&
- !isa<CatchSwitchInst>(BB.getFirstNonPHIIt()))
- continue;
for (Instruction &I : make_early_inc_range(BB)) {
auto *PN = dyn_cast<PHINode>(&I);
@@ -876,6 +873,23 @@ void WinEHPrepareImpl::demotePHIsOnFunclets(Function &F,
if (!PN)
break;
+ // If DemoteCatchSwitchPHIOnly is true, we only demote a PHI when
+ // 1. The PHI is within a catchswitch BB
+ // 2. The PHI has a catchswitch BB has one of its incoming blocks
+ if (DemoteCatchSwitchPHIOnly) {
+ bool IsCatchSwitchBB = isa<CatchSwitchInst>(BB.getFirstNonPHIIt());
+ bool HasIncomingCatchSwitchBB = false;
+ for (unsigned I = 0, E = PN->getNumIncomingValues(); I < E; ++I) {
+ if (isa<CatchSwitchInst>(
+ PN->getIncomingBlock(I)->getFirstNonPHIIt())) {
+ HasIncomingCatchSwitchBB = true;
+ break;
+ }
+ }
+ if (!IsCatchSwitchBB && !HasIncomingCatchSwitchBB)
+ break;
+ }
+
AllocaInst *SpillSlot = insertPHILoads(PN, F);
if (SpillSlot)
insertPHIStores(PN, SpillSlot);