diff options
author | Sanjay Patel <spatel@rotateright.com> | 2019-03-04 20:57:14 +0000 |
---|---|---|
committer | Sanjay Patel <spatel@rotateright.com> | 2019-03-04 20:57:14 +0000 |
commit | 6e32b46b1ddc79f73c18631df04735c4d453f830 (patch) | |
tree | d826e373266513a5e17e0eed9b5e56bdb099a06b /llvm/lib/Transforms/Scalar/ConstantHoisting.cpp | |
parent | fc778fa2c599cd09f041037987171fdc8c202be8 (diff) | |
download | bcm5719-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.cpp | 7 |
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; |