Index: lib/Transforms/Scalar/CallSiteSplitting.cpp =================================================================== --- lib/Transforms/Scalar/CallSiteSplitting.cpp +++ lib/Transforms/Scalar/CallSiteSplitting.cpp @@ -84,6 +84,15 @@ "their cost is below DuplicationThreshold"), cl::init(5)); + +/// Only allow N level of predecessors to be walked. +static cl::opt + PredecessorWalkThreshold("callsite-predecessor-walk-threshold", cl::Hidden, + cl::desc("Only allow N number of predecessors to be" + "walked"), + cl::init(16)); + + static void addNonNullAttribute(CallSite CS, Value *Op) { unsigned ArgNo = 0; for (auto &I : CS.args()) { @@ -152,6 +161,7 @@ /// x == 1 and x == 0, the first condition will be used. static void recordConditions(CallSite CS, BasicBlock *Pred, ConditionsTy &Conditions) { + uint32_t PredWalked = 0; recordCondition(CS, Pred, CS.getInstruction()->getParent(), Conditions); BasicBlock *From = Pred; BasicBlock *To = Pred; @@ -161,6 +171,9 @@ recordCondition(CS, From, To, Conditions); Visited.insert(From); To = From; + // Make sure we do not traverse too many predecessors up the CFG. + if (++PredWalked > PredecessorWalkThreshold) + break; } }