Skip to content

Commit 17ded78

Browse files
david-xlrocm-hcc
authored andcommitted
Add a limit for phi folding instcombine
Differential Revision: http://reviews.llvm.org/D47023 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@332653 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 1bb7ded commit 17ded78

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

lib/Transforms/InstCombine/InstCombinePHI.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ using namespace llvm::PatternMatch;
2323

2424
#define DEBUG_TYPE "instcombine"
2525

26+
static cl::opt<unsigned>
27+
MaxNumPhis("instcombine-max-num-phis", cl::init(512),
28+
cl::desc("Maximum number phis to handle in intptr/ptrint folding"));
29+
2630
/// The PHI arguments will be folded into a single operation with a PHI node
2731
/// as input. The debug location of the single operation will be the merged
2832
/// locations of the original PHI node arguments.
@@ -176,8 +180,12 @@ Instruction *InstCombiner::FoldIntegerTypedPHI(PHINode &PN) {
176180
assert(AvailablePtrVals.size() == PN.getNumIncomingValues() &&
177181
"Not enough available ptr typed incoming values");
178182
PHINode *MatchingPtrPHI = nullptr;
183+
unsigned NumPhis = 0;
179184
for (auto II = BB->begin(), EI = BasicBlock::iterator(BB->getFirstNonPHI());
180-
II != EI; II++) {
185+
II != EI; II++, NumPhis++) {
186+
// FIXME: consider handling this in AggressiveInstCombine
187+
if (NumPhis > MaxNumPhis)
188+
return nullptr;
181189
PHINode *PtrPHI = dyn_cast<PHINode>(II);
182190
if (!PtrPHI || PtrPHI == &PN || PtrPHI->getType() != IntToPtr->getType())
183191
continue;

0 commit comments

Comments
 (0)