[llvm] [SROA][Target] Add requiresStructuredGEP to TTI (PR #183296)
Jameson Nash via llvm-commits
llvm-commits at lists.llvm.org
Mon Mar 2 19:32:39 PST 2026
================
@@ -4103,18 +4113,25 @@ class AggLoadStoreRewriter : public InstVisitor<AggLoadStoreRewriter, bool> {
LoadOpSplitter(Instruction *InsertionPoint, Value *Ptr, Type *BaseTy,
AAMDNodes AATags, Align BaseAlign, const DataLayout &DL,
- IRBuilderTy &IRB)
+ const TargetTransformInfo &TTI, IRBuilderTy &IRB)
: OpSplitter<LoadOpSplitter>(InsertionPoint, Ptr, BaseTy, BaseAlign, DL,
- IRB),
+ TTI, IRB),
AATags(AATags) {}
/// Emit a leaf load of a single value. This is called at the leaves of the
/// recursive emission to actually load values.
void emitFunc(Type *Ty, Value *&Agg, Align Alignment, const Twine &Name) {
assert(Ty->isSingleValueType());
// Load the single value and insert it using the indices.
- Value *GEP =
- IRB.CreateInBoundsGEP(BaseTy, Ptr, GEPIndices, Name + ".gep");
+ Value *GEP = nullptr;
+ if (TTI.requiresStructuredGEP()) {
+ assert(GEPIndices.size() > 0);
+ llvm::ArrayRef<Value *> SGEPIndices =
+ llvm::ArrayRef<Value *>(GEPIndices).drop_front(1);
+ GEP = IRB.CreateStructuredGEP(BaseTy, Ptr, SGEPIndices, Name + ".gep");
+ } else {
+ GEP = IRB.CreateInBoundsGEP(BaseTy, Ptr, GEPIndices, Name + ".gep");
+ }
----------------
vtjnash wrote:
Since this feels like it will be a fairly common operation, I wonder if this pattern should be added as a helper in IRBuilderBase, if the user explicitly provides both values? With the availability of DataLayout, it is also trivial for IRBuilder to convert a GEP to ptradd and a ptradd to GEP using getElementOffset and getElementContainingOffset (for ptradd with known BaseTy), respectively
https://github.com/llvm/llvm-project/pull/183296
More information about the llvm-commits
mailing list