From bc471c39eed35e82d6c39ca28e6e7d78029ee59c Mon Sep 17 00:00:00 2001 From: Xinliang David Li Date: Thu, 17 May 2018 19:24:03 +0000 Subject: Add a limit for phi folding instcombine Differential Revision: http://reviews.llvm.org/D47023 llvm-svn: 332653 --- llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'llvm/lib/Transforms') diff --git a/llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp b/llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp index 91850cee77f..14c3806c40a 100644 --- a/llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp +++ b/llvm/lib/Transforms/InstCombine/InstCombinePHI.cpp @@ -23,6 +23,10 @@ using namespace llvm::PatternMatch; #define DEBUG_TYPE "instcombine" +static cl::opt +MaxNumPhis("instcombine-max-num-phis", cl::init(512), + cl::desc("Maximum number phis to handle in intptr/ptrint folding")); + /// The PHI arguments will be folded into a single operation with a PHI node /// as input. The debug location of the single operation will be the merged /// locations of the original PHI node arguments. @@ -176,8 +180,12 @@ Instruction *InstCombiner::FoldIntegerTypedPHI(PHINode &PN) { assert(AvailablePtrVals.size() == PN.getNumIncomingValues() && "Not enough available ptr typed incoming values"); PHINode *MatchingPtrPHI = nullptr; + unsigned NumPhis = 0; for (auto II = BB->begin(), EI = BasicBlock::iterator(BB->getFirstNonPHI()); - II != EI; II++) { + II != EI; II++, NumPhis++) { + // FIXME: consider handling this in AggressiveInstCombine + if (NumPhis > MaxNumPhis) + return nullptr; PHINode *PtrPHI = dyn_cast(II); if (!PtrPHI || PtrPHI == &PN || PtrPHI->getType() != IntToPtr->getType()) continue; -- cgit v1.2.3