diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp --- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp +++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp @@ -8719,10 +8719,8 @@ GEP, make_range(Operands.begin(), Operands.end()))); if (auto *SI = dyn_cast(Instr)) { - bool InvariantCond = - PSE.getSE()->isLoopInvariant(PSE.getSCEV(SI->getOperand(0)), OrigLoop); return toVPRecipeResult(new VPWidenSelectRecipe( - *SI, make_range(Operands.begin(), Operands.end()), InvariantCond)); + *SI, make_range(Operands.begin(), Operands.end()))); } return toVPRecipeResult(tryToWiden(Instr, Operands, VPBB, Plan)); @@ -9114,7 +9112,7 @@ SmallPtrSet DeadInstructions; VPlanTransforms::VPInstructionsToVPRecipes( - OrigLoop, Plan, + Plan, [this](PHINode *P) { return Legal->getIntOrFpInductionDescriptor(P); }, DeadInstructions, *PSE.getSE(), *TLI); diff --git a/llvm/lib/Transforms/Vectorize/VPlan.h b/llvm/lib/Transforms/Vectorize/VPlan.h --- a/llvm/lib/Transforms/Vectorize/VPlan.h +++ b/llvm/lib/Transforms/Vectorize/VPlan.h @@ -960,17 +960,15 @@ }; /// A recipe for widening select instructions. -class VPWidenSelectRecipe : public VPRecipeBase, public VPValue { - - /// Is the condition of the select loop invariant? - bool InvariantCond; +struct VPWidenSelectRecipe : public VPRecipeBase, public VPValue { + bool isInvariantCond() const { + return getOperand(0)->isDefinedOutsideVectorRegions(); + } public: template - VPWidenSelectRecipe(SelectInst &I, iterator_range Operands, - bool InvariantCond) - : VPRecipeBase(VPDef::VPWidenSelectSC, Operands), VPValue(this, &I), - InvariantCond(InvariantCond) {} + VPWidenSelectRecipe(SelectInst &I, iterator_range Operands) + : VPRecipeBase(VPDef::VPWidenSelectSC, Operands), VPValue(this, &I) {} ~VPWidenSelectRecipe() override = default; diff --git a/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp b/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp --- a/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp +++ b/llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp @@ -536,7 +536,7 @@ getOperand(1)->printAsOperand(O, SlotTracker); O << ", "; getOperand(2)->printAsOperand(O, SlotTracker); - O << (InvariantCond ? " (condition is loop invariant)" : ""); + O << (isInvariantCond() ? " (condition is loop invariant)" : ""); } #endif @@ -549,7 +549,7 @@ // We have to take the 'vectorized' value and pick the first lane. // Instcombine will make this a no-op. auto *InvarCond = - InvariantCond ? State.get(getOperand(0), VPIteration(0, 0)) : nullptr; + isInvariantCond() ? State.get(getOperand(0), VPIteration(0, 0)) : nullptr; for (unsigned Part = 0; Part < State.UF; ++Part) { Value *Cond = InvarCond ? InvarCond : State.get(getOperand(0), Part); diff --git a/llvm/lib/Transforms/Vectorize/VPlanTransforms.h b/llvm/lib/Transforms/Vectorize/VPlanTransforms.h --- a/llvm/lib/Transforms/Vectorize/VPlanTransforms.h +++ b/llvm/lib/Transforms/Vectorize/VPlanTransforms.h @@ -31,7 +31,7 @@ /// Replaces the VPInstructions in \p Plan with corresponding /// widen recipes. static void - VPInstructionsToVPRecipes(Loop *OrigLoop, VPlanPtr &Plan, + VPInstructionsToVPRecipes(VPlanPtr &Plan, function_ref GetIntOrFpInductionDescriptor, SmallPtrSetImpl &DeadInstructions, diff --git a/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp b/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp --- a/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp +++ b/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp @@ -24,7 +24,7 @@ using namespace llvm; void VPlanTransforms::VPInstructionsToVPRecipes( - Loop *OrigLoop, VPlanPtr &Plan, + VPlanPtr &Plan, function_ref GetIntOrFpInductionDescriptor, SmallPtrSetImpl &DeadInstructions, ScalarEvolution &SE, @@ -83,10 +83,8 @@ new VPWidenCallRecipe(*CI, Plan->mapToVPValues(CI->args()), getVectorIntrinsicIDForCall(CI, &TLI)); } else if (SelectInst *SI = dyn_cast(Inst)) { - bool InvariantCond = - SE.isLoopInvariant(SE.getSCEV(SI->getOperand(0)), OrigLoop); - NewRecipe = new VPWidenSelectRecipe( - *SI, Plan->mapToVPValues(SI->operands()), InvariantCond); + NewRecipe = + new VPWidenSelectRecipe(*SI, Plan->mapToVPValues(SI->operands())); } else { NewRecipe = new VPWidenRecipe(*Inst, Plan->mapToVPValues(Inst->operands())); diff --git a/llvm/unittests/Transforms/Vectorize/VPlanHCFGTest.cpp b/llvm/unittests/Transforms/Vectorize/VPlanHCFGTest.cpp --- a/llvm/unittests/Transforms/Vectorize/VPlanHCFGTest.cpp +++ b/llvm/unittests/Transforms/Vectorize/VPlanHCFGTest.cpp @@ -139,8 +139,7 @@ TargetLibraryInfo TLI(TLII); SmallPtrSet DeadInstructions; VPlanTransforms::VPInstructionsToVPRecipes( - LI->getLoopFor(LoopHeader), Plan, [](PHINode *P) { return nullptr; }, - DeadInstructions, *SE, TLI); + Plan, [](PHINode *P) { return nullptr; }, DeadInstructions, *SE, TLI); } TEST_F(VPlanHCFGTest, testVPInstructionToVPRecipesInner) { @@ -171,8 +170,7 @@ TargetLibraryInfoImpl TLII(Triple(M.getTargetTriple())); TargetLibraryInfo TLI(TLII); VPlanTransforms::VPInstructionsToVPRecipes( - LI->getLoopFor(LoopHeader), Plan, [](PHINode *P) { return nullptr; }, - DeadInstructions, *SE, TLI); + Plan, [](PHINode *P) { return nullptr; }, DeadInstructions, *SE, TLI); VPBlockBase *Entry = Plan->getEntry()->getEntryBasicBlock(); EXPECT_NE(nullptr, Entry->getSingleSuccessor()); diff --git a/llvm/unittests/Transforms/Vectorize/VPlanTest.cpp b/llvm/unittests/Transforms/Vectorize/VPlanTest.cpp --- a/llvm/unittests/Transforms/Vectorize/VPlanTest.cpp +++ b/llvm/unittests/Transforms/Vectorize/VPlanTest.cpp @@ -899,7 +899,7 @@ Args.push_back(&Op2); Args.push_back(&Op3); VPWidenSelectRecipe WidenSelectR(*SelectI, - make_range(Args.begin(), Args.end()), false); + make_range(Args.begin(), Args.end())); EXPECT_TRUE(isa(&WidenSelectR)); VPRecipeBase *BaseR = &WidenSelectR; EXPECT_TRUE(isa(BaseR)); @@ -1048,8 +1048,7 @@ Args.push_back(&Op1); Args.push_back(&Op2); Args.push_back(&Op3); - VPWidenSelectRecipe Recipe(*SelectI, make_range(Args.begin(), Args.end()), - false); + VPWidenSelectRecipe Recipe(*SelectI, make_range(Args.begin(), Args.end())); EXPECT_FALSE(Recipe.mayHaveSideEffects()); EXPECT_FALSE(Recipe.mayReadFromMemory()); EXPECT_FALSE(Recipe.mayWriteToMemory());