summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Transforms/Scalar/ConstantHoisting.cpp
diff options
context:
space:
mode:
authorSanjay Patel <spatel@rotateright.com>2019-03-04 20:57:14 +0000
committerSanjay Patel <spatel@rotateright.com>2019-03-04 20:57:14 +0000
commit6e32b46b1ddc79f73c18631df04735c4d453f830 (patch)
treed826e373266513a5e17e0eed9b5e56bdb099a06b /llvm/lib/Transforms/Scalar/ConstantHoisting.cpp
parentfc778fa2c599cd09f041037987171fdc8c202be8 (diff)
downloadbcm5719-llvm-6e32b46b1ddc79f73c18631df04735c4d453f830.tar.gz
bcm5719-llvm-6e32b46b1ddc79f73c18631df04735c4d453f830.zip
[ConstantHoisting] avoid hang/crash from unreachable blocks (PR40930)
I'm not too familiar with this pass, so there might be a better solution, but this appears to fix the degenerate: PR40930 PR40931 PR40932 PR40934 ...without affecting any real-world code. As we've seen in several other passes, when we have unreachable blocks, they can contain semi-bogus IR and/or cause unexpected conditions. We would not typically expect these patterns to make it this far, but we have to guard against them anyway. llvm-svn: 355337
Diffstat (limited to 'llvm/lib/Transforms/Scalar/ConstantHoisting.cpp')
-rw-r--r--llvm/lib/Transforms/Scalar/ConstantHoisting.cpp7
1 files changed, 6 insertions, 1 deletions
diff --git a/llvm/lib/Transforms/Scalar/ConstantHoisting.cpp b/llvm/lib/Transforms/Scalar/ConstantHoisting.cpp
index 1af14ea73b8..0764778a7c4 100644
--- a/llvm/lib/Transforms/Scalar/ConstantHoisting.cpp
+++ b/llvm/lib/Transforms/Scalar/ConstantHoisting.cpp
@@ -208,6 +208,9 @@ static void findBestInsertionSet(DominatorTree &DT, BlockFrequencyInfo &BFI,
// in the dominator tree from Entry to 'BB'.
SmallPtrSet<BasicBlock *, 16> Candidates;
for (auto BB : BBs) {
+ // Ignore unreachable basic blocks.
+ if (!DT.isReachableFromEntry(BB))
+ continue;
Path.clear();
// Walk up the dominator tree until Entry or another BB in BBs
// is reached. Insert the nodes on the way to the Path.
@@ -821,7 +824,9 @@ bool ConstantHoistingPass::emitBaseConstants(GlobalVariable *BaseGV) {
BaseGV ? ConstGEPInfoMap[BaseGV] : ConstIntInfoVec;
for (auto const &ConstInfo : ConstInfoVec) {
SmallPtrSet<Instruction *, 8> IPSet = findConstantInsertionPoint(ConstInfo);
- assert(!IPSet.empty() && "IPSet is empty");
+ // We can have an empty set if the function contains unreachable blocks.
+ if (IPSet.empty())
+ continue;
unsigned UsesNum = 0;
unsigned ReBasesNum = 0;
OpenPOWER on IntegriCloud