Skip to content

Commit 0a500c7

Browse files
committed
Add getGEPIndexTy utility function to avoid duplication
1 parent 6a575e2 commit 0a500c7

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

llvm/lib/Transforms/Vectorize/VPlanRecipes.cpp

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1813,16 +1813,22 @@ void VPWidenGEPRecipe::print(raw_ostream &O, const Twine &Indent,
18131813
}
18141814
#endif
18151815

1816+
static Type *getGEPIndexTy(bool IsScalable, bool IsReverse,
1817+
unsigned CurrentPart, IRBuilderBase &Builder) {
1818+
// Use i32 for the gep index type when the value is constant,
1819+
// or query DataLayout for a more suitable index type otherwise.
1820+
const DataLayout &DL = Builder.GetInsertBlock()->getDataLayout();
1821+
return IsScalable && (IsReverse || CurrentPart > 0)
1822+
? DL.getIndexType(Builder.getPtrTy(0))
1823+
: Builder.getInt32Ty();
1824+
}
1825+
18161826
void VPReverseVectorPointerRecipe::execute(VPTransformState &State) {
18171827
auto &Builder = State.Builder;
18181828
State.setDebugLocFrom(getDebugLoc());
18191829
unsigned CurrentPart = getUnrollPart(*this);
1820-
// Use i32 for the gep index type when the value is constant,
1821-
// or query DataLayout for a more suitable index type otherwise.
1822-
const DataLayout &DL = Builder.GetInsertBlock()->getDataLayout();
1823-
Type *IndexTy = State.VF.isScalable()
1824-
? DL.getIndexType(IndexedTy->getPointerTo())
1825-
: Builder.getInt32Ty();
1830+
Type *IndexTy = getGEPIndexTy(State.VF.isScalable(), /*IsReverse*/ true,
1831+
CurrentPart, Builder);
18261832

18271833
// The wide store needs to start at the last vector element.
18281834
Value *RunTimeVF = State.get(getVFValue(), VPLane(0));
@@ -1857,12 +1863,8 @@ void VPVectorPointerRecipe::execute(VPTransformState &State) {
18571863
auto &Builder = State.Builder;
18581864
State.setDebugLocFrom(getDebugLoc());
18591865
unsigned CurrentPart = getUnrollPart(*this);
1860-
// Use i32 for the gep index type when the value is constant,
1861-
// or query DataLayout for a more suitable index type otherwise.
1862-
const DataLayout &DL = Builder.GetInsertBlock()->getDataLayout();
1863-
Type *IndexTy = State.VF.isScalable() && CurrentPart > 0
1864-
? DL.getIndexType(Builder.getPtrTy(0))
1865-
: Builder.getInt32Ty();
1866+
Type *IndexTy = getGEPIndexTy(State.VF.isScalable(), /*IsReverse*/ false,
1867+
CurrentPart, Builder);
18661868
Value *Ptr = State.get(getOperand(0), VPLane(0));
18671869
bool InBounds = isInBounds();
18681870

0 commit comments

Comments
 (0)