diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp index af51dea002da9..58358eb5d6624 100644 --- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp +++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp @@ -6884,14 +6884,13 @@ VPBlendRecipe *VPRecipeBuilder::tryToBlend(Instruction *I, VPlanPtr &Plan) { return new VPBlendRecipe(Phi, Masks); } -bool VPRecipeBuilder::tryToWiden(Instruction *I, VPBasicBlock *VPBB, - VFRange &Range) { +VPWidenRecipe *VPRecipeBuilder::tryToWiden(Instruction *I, VFRange &Range) { bool IsPredicated = LoopVectorizationPlanner::getDecisionAndClampRange( [&](unsigned VF) { return CM.isScalarWithPredication(I, VF); }, Range); if (IsPredicated) - return false; + return nullptr; auto IsVectorizableOpcode = [](unsigned Opcode) { switch (Opcode) { @@ -6940,13 +6939,13 @@ bool VPRecipeBuilder::tryToWiden(Instruction *I, VPBasicBlock *VPBB, }; if (!IsVectorizableOpcode(I->getOpcode())) - return false; + return nullptr; if (CallInst *CI = dyn_cast(I)) { Intrinsic::ID ID = getVectorIntrinsicIDForCall(CI, TLI); if (ID && (ID == Intrinsic::assume || ID == Intrinsic::lifetime_end || ID == Intrinsic::lifetime_start || ID == Intrinsic::sideeffect)) - return false; + return nullptr; } auto willWiden = [&](unsigned VF) -> bool { @@ -6975,13 +6974,10 @@ bool VPRecipeBuilder::tryToWiden(Instruction *I, VPBasicBlock *VPBB, }; if (!LoopVectorizationPlanner::getDecisionAndClampRange(willWiden, Range)) - return false; + return nullptr; // Success: widen this instruction. - VPWidenRecipe *WidenRecipe = new VPWidenRecipe(*I); - setRecipe(I, WidenRecipe); - VPBB->appendRecipe(WidenRecipe); - return true; + return new VPWidenRecipe(*I); } VPBasicBlock *VPRecipeBuilder::handleReplication( @@ -7085,8 +7081,11 @@ bool VPRecipeBuilder::tryToCreateRecipe(Instruction *Instr, VFRange &Range, // Check if Instr is to be widened by a general VPWidenRecipe, after // having first checked for specific widening recipes. - if (tryToWiden(Instr, VPBB, Range)) + if ((Recipe = tryToWiden(Instr, Range))) { + setRecipe(Instr, Recipe); + VPBB->appendRecipe(Recipe); return true; + } return false; } diff --git a/llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h b/llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h index f3172d49cf2af..ab9cd774f4285 100644 --- a/llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h +++ b/llvm/lib/Transforms/Vectorize/VPRecipeBuilder.h @@ -108,12 +108,10 @@ class VPRecipeBuilder { VPBlendRecipe *tryToBlend(Instruction *I, VPlanPtr &Plan); /// Check if \p I can be widened within the given VF \p Range. If \p I can be - /// widened for \p Range.Start, check if the last recipe of \p VPBB can be - /// extended to include \p I or else build a new VPWidenRecipe for it and - /// append it to \p VPBB. Return true if \p I can be widened for Range.Start, - /// false otherwise. Range.End may be decreased to ensure same decision from - /// \p Range.Start to \p Range.End. - bool tryToWiden(Instruction *I, VPBasicBlock *VPBB, VFRange &Range); + /// widened for \p Range.Start, build a new VPWidenRecipe and return it. + /// Range.End may be decreased to ensure same decision from \p Range.Start to + /// \p Range.End. + VPWidenRecipe *tryToWiden(Instruction *I, VFRange &Range); /// Create a replicating region for instruction \p I that requires /// predication. \p PredRecipe is a VPReplicateRecipe holding \p I.