aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Transforms/Instrumentation/ControlHeightReduction.cpp
diff options
context:
space:
mode:
authorNikita Popov <npopov@redhat.com>2023-08-10 16:30:17 +0200
committerNikita Popov <npopov@redhat.com>2023-08-16 10:07:32 +0200
commit7e2f1ae7e0ebc7e71ffaa865175aef27fae3b034 (patch)
tree479e989ffade586f61694159e1d866d45068497b /llvm/lib/Transforms/Instrumentation/ControlHeightReduction.cpp
parentc8626cd916ac07f6e6c4e3ba20c089589b878847 (diff)
downloadllvm-7e2f1ae7e0ebc7e71ffaa865175aef27fae3b034.zip
llvm-7e2f1ae7e0ebc7e71ffaa865175aef27fae3b034.tar.gz
llvm-7e2f1ae7e0ebc7e71ffaa865175aef27fae3b034.tar.bz2
Reapply [CHR] Fix up phi nodes with unreachable predecessors (PR64594)
Relative to the previous attempt, this also adjusts RegionInfo verification to allow unreachable predecessors. ----- If a block in the CHR region has an unreachable predecessor, then there will be no edge from that predecessor to the newly cloned block. However, a phi node entry for it will be left behind. Make sure that these incoming blocks get dropped as well. Fixes https://github.com/llvm/llvm-project/issues/64594. Differential Revision: https://reviews.llvm.org/D157621
Diffstat (limited to 'llvm/lib/Transforms/Instrumentation/ControlHeightReduction.cpp')
-rw-r--r--llvm/lib/Transforms/Instrumentation/ControlHeightReduction.cpp14
1 files changed, 14 insertions, 0 deletions
diff --git a/llvm/lib/Transforms/Instrumentation/ControlHeightReduction.cpp b/llvm/lib/Transforms/Instrumentation/ControlHeightReduction.cpp
index 3e3be53..597cec8 100644
--- a/llvm/lib/Transforms/Instrumentation/ControlHeightReduction.cpp
+++ b/llvm/lib/Transforms/Instrumentation/ControlHeightReduction.cpp
@@ -1777,6 +1777,20 @@ void CHR::cloneScopeBlocks(CHRScope *Scope,
BasicBlock *NewBB = CloneBasicBlock(BB, VMap, ".nonchr", &F);
NewBlocks.push_back(NewBB);
VMap[BB] = NewBB;
+
+ // Unreachable predecessors will not be cloned and will not have an edge
+ // to the cloned block. As such, also remove them from any phi nodes.
+ // To avoid iterator invalidation, first collect the dead predecessors
+ // from the first phi node, and then perform the actual removal.
+ if (auto *FirstPN = dyn_cast<PHINode>(NewBB->begin())) {
+ SmallVector<BasicBlock *> DeadPreds;
+ for (BasicBlock *Pred : FirstPN->blocks())
+ if (!DT.isReachableFromEntry(Pred))
+ DeadPreds.push_back(Pred);
+ for (PHINode &PN : make_early_inc_range(NewBB->phis()))
+ for (BasicBlock *Pred : DeadPreds)
+ PN.removeIncomingValue(Pred);
+ }
}
// Place the cloned blocks right after the original blocks (right before the