Skip to content

Commit 019913e

Browse files
authored
[VPlan] Add WidenGEP::getSourceElementType (NFC) (#159029)
1 parent b280cf5 commit 019913e

File tree

3 files changed

+21
-17
lines changed

3 files changed

+21
-17
lines changed

llvm/lib/Transforms/Vectorize/VPlan.h

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1763,6 +1763,8 @@ struct LLVM_ABI_FOR_TEST VPWidenSelectRecipe : public VPRecipeWithIRFlags,
17631763

17641764
/// A recipe for handling GEP instructions.
17651765
class LLVM_ABI_FOR_TEST VPWidenGEPRecipe : public VPRecipeWithIRFlags {
1766+
Type *SourceElementTy;
1767+
17661768
bool isPointerLoopInvariant() const {
17671769
return getOperand(0)->isDefinedOutsideLoopRegions();
17681770
}
@@ -1779,7 +1781,8 @@ class LLVM_ABI_FOR_TEST VPWidenGEPRecipe : public VPRecipeWithIRFlags {
17791781

17801782
public:
17811783
VPWidenGEPRecipe(GetElementPtrInst *GEP, ArrayRef<VPValue *> Operands)
1782-
: VPRecipeWithIRFlags(VPDef::VPWidenGEPSC, Operands, *GEP) {
1784+
: VPRecipeWithIRFlags(VPDef::VPWidenGEPSC, Operands, *GEP),
1785+
SourceElementTy(GEP->getSourceElementType()) {
17831786
SmallVector<std::pair<unsigned, MDNode *>> Metadata;
17841787
(void)Metadata;
17851788
getMetadataToPropagate(GEP, Metadata);
@@ -1801,6 +1804,8 @@ class LLVM_ABI_FOR_TEST VPWidenGEPRecipe : public VPRecipeWithIRFlags {
18011804
/// Generate the gep nodes.
18021805
void execute(VPTransformState &State) override;
18031806

1807+
Type *getSourceElementType() const { return SourceElementTy; }
1808+
18041809
/// Return the cost of this VPWidenGEPRecipe.
18051810
InstructionCost computeCost(ElementCount VF,
18061811
VPCostContext &Ctx) const override {
@@ -1889,20 +1894,20 @@ class VPVectorEndPointerRecipe : public VPRecipeWithIRFlags,
18891894
/// A recipe to compute the pointers for widened memory accesses of IndexTy.
18901895
class VPVectorPointerRecipe : public VPRecipeWithIRFlags,
18911896
public VPUnrollPartAccessor<1> {
1892-
Type *IndexedTy;
1897+
Type *SourceElementTy;
18931898

18941899
public:
1895-
VPVectorPointerRecipe(VPValue *Ptr, Type *IndexedTy, GEPNoWrapFlags GEPFlags,
1896-
DebugLoc DL)
1900+
VPVectorPointerRecipe(VPValue *Ptr, Type *SourceElementTy,
1901+
GEPNoWrapFlags GEPFlags, DebugLoc DL)
18971902
: VPRecipeWithIRFlags(VPDef::VPVectorPointerSC, ArrayRef<VPValue *>(Ptr),
18981903
GEPFlags, DL),
1899-
IndexedTy(IndexedTy) {}
1904+
SourceElementTy(SourceElementTy) {}
19001905

19011906
VP_CLASSOF_IMPL(VPDef::VPVectorPointerSC)
19021907

19031908
void execute(VPTransformState &State) override;
19041909

1905-
Type *getSourceElementType() const { return IndexedTy; }
1910+
Type *getSourceElementType() const { return SourceElementTy; }
19061911

19071912
bool onlyFirstLaneUsed(const VPValue *Op) const override {
19081913
assert(is_contained(operands(), Op) &&
@@ -1919,7 +1924,7 @@ class VPVectorPointerRecipe : public VPRecipeWithIRFlags,
19191924
}
19201925

19211926
VPVectorPointerRecipe *clone() override {
1922-
return new VPVectorPointerRecipe(getOperand(0), IndexedTy,
1927+
return new VPVectorPointerRecipe(getOperand(0), SourceElementTy,
19231928
getGEPNoWrapFlags(), getDebugLoc());
19241929
}
19251930

llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2462,7 +2462,6 @@ void VPScalarIVStepsRecipe::print(raw_ostream &O, const Twine &Indent,
24622462

24632463
void VPWidenGEPRecipe::execute(VPTransformState &State) {
24642464
assert(State.VF.isVector() && "not widening");
2465-
auto *GEP = cast<GetElementPtrInst>(getUnderlyingInstr());
24662465
// Construct a vector GEP by widening the operands of the scalar GEP as
24672466
// necessary. We mark the vector GEP 'inbounds' if appropriate. A GEP
24682467
// results in a vector of pointers when at least one operand of the GEP
@@ -2486,9 +2485,9 @@ void VPWidenGEPRecipe::execute(VPTransformState &State) {
24862485
for (unsigned I = 0, E = getNumOperands(); I != E; I++)
24872486
Ops.push_back(State.get(getOperand(I), VPLane(0)));
24882487

2489-
auto *NewGEP = State.Builder.CreateGEP(GEP->getSourceElementType(), Ops[0],
2490-
ArrayRef(Ops).drop_front(), "",
2491-
getGEPNoWrapFlags());
2488+
auto *NewGEP =
2489+
State.Builder.CreateGEP(getSourceElementType(), Ops[0], drop_begin(Ops),
2490+
"", getGEPNoWrapFlags());
24922491
Value *Splat = State.Builder.CreateVectorSplat(State.VF, NewGEP);
24932492
State.set(this, Splat);
24942493
} else {
@@ -2512,8 +2511,8 @@ void VPWidenGEPRecipe::execute(VPTransformState &State) {
25122511

25132512
// Create the new GEP. Note that this GEP may be a scalar if VF == 1,
25142513
// but it should be a vector, otherwise.
2515-
auto *NewGEP = State.Builder.CreateGEP(GEP->getSourceElementType(), Ptr,
2516-
Indices, "", getGEPNoWrapFlags());
2514+
auto *NewGEP = State.Builder.CreateGEP(getSourceElementType(), Ptr, Indices,
2515+
"", getGEPNoWrapFlags());
25172516
assert((State.VF.isScalar() || NewGEP->getType()->isVectorTy()) &&
25182517
"NewGEP is not a pointer vector");
25192518
State.set(this, NewGEP);
@@ -2592,8 +2591,8 @@ void VPVectorPointerRecipe::execute(VPTransformState &State) {
25922591
Value *Ptr = State.get(getOperand(0), VPLane(0));
25932592

25942593
Value *Increment = createStepForVF(Builder, IndexTy, State.VF, CurrentPart);
2595-
Value *ResultPtr =
2596-
Builder.CreateGEP(IndexedTy, Ptr, Increment, "", getGEPNoWrapFlags());
2594+
Value *ResultPtr = Builder.CreateGEP(getSourceElementType(), Ptr, Increment,
2595+
"", getGEPNoWrapFlags());
25972596

25982597
State.set(this, ResultPtr, /*IsScalar*/ true);
25992598
}

llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1992,12 +1992,12 @@ struct VPCSEDenseMapInfo : public DenseMapInfo<VPSingleDefRecipe *> {
19921992
// All VPInstructions that lower to GEPs must have the i8 source element
19931993
// type (as they are PtrAdds), so we omit it.
19941994
return TypeSwitch<const VPSingleDefRecipe *, Type *>(R)
1995-
.Case<VPReplicateRecipe, VPWidenGEPRecipe>([](auto *I) -> Type * {
1995+
.Case<VPReplicateRecipe>([](auto *I) -> Type * {
19961996
if (auto *GEP = dyn_cast<GetElementPtrInst>(I->getUnderlyingValue()))
19971997
return GEP->getSourceElementType();
19981998
return nullptr;
19991999
})
2000-
.Case<VPVectorPointerRecipe>(
2000+
.Case<VPVectorPointerRecipe, VPWidenGEPRecipe>(
20012001
[](auto *I) { return I->getSourceElementType(); })
20022002
.Default([](auto *) { return nullptr; });
20032003
}

0 commit comments

Comments
 (0)