diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp --- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp +++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp @@ -817,6 +817,7 @@ // and RHS as base and Idx as the offset. int Ln = std::min(LHS.second, RHS.second) + Idx; assert(Ln >= 0 && "Bad lane calculation"); + unsigned UsersBudget = 4; for (User *U : V->users()) { if (const TreeEntry *UserTE = R.getTreeEntry(U)) { // The user is in the VectorizableTree. Check if we need to insert. @@ -838,6 +839,9 @@ Cost += ExternalUseCost; } } + // Limit the number of visited uses to cap compilation time. + if (--UsersBudget == 0) + break; } } return Cost; @@ -898,7 +902,10 @@ // Recursion towards the operands of I1 and I2. We are trying all possbile // operand pairs, and keeping track of the best score. - for (unsigned OpIdx1 = 0, NumOperands1 = I1->getNumOperands(); + // Limit the number of operands to visit to reduce compilation time. + unsigned OperandsBudget = 2; + for (unsigned OpIdx1 = 0, NumOperands1 = std::max(I1->getNumOperands(), + OperandsBudget); OpIdx1 != NumOperands1; ++OpIdx1) { // Try to pair op1I with the best operand of I2. int MaxTmpScore = 0; @@ -907,7 +914,7 @@ // If I2 is commutative try all combinations. unsigned FromIdx = isCommutative(I2) ? 0 : OpIdx1; unsigned ToIdx = isCommutative(I2) - ? I2->getNumOperands() + ? std::max(I2->getNumOperands(), OperandsBudget) : std::min(I2->getNumOperands(), OpIdx1 + 1); assert(FromIdx <= ToIdx && "Bad index"); for (unsigned OpIdx2 = FromIdx; OpIdx2 != ToIdx; ++OpIdx2) {