[llvm] [LSROA] Support arrays, vectors, and nested structs (PR #218846)
Deric C. via llvm-commits
llvm-commits at lists.llvm.org
Mon Aug 31 19:59:29 PDT 2026
================
@@ -1809,23 +1809,20 @@ class StructuredGEPInst : public IntrinsicInst {
return make_range(op_begin() + 1, op_begin() + 1 + getNumIndices());
}
+ static Type *getTypeAtIndex(Type *Ty, const Value *Index) {
+ if (ArrayType *AT = dyn_cast<ArrayType>(Ty))
+ return AT->getElementType();
+ if (VectorType *VT = dyn_cast<VectorType>(Ty))
+ return VT->getElementType();
+ if (StructType *ST = dyn_cast<StructType>(Ty))
+ return ST->getElementType(cast<ConstantInt>(Index)->getZExtValue());
----------------
Icohedron wrote:
[QUESTION] Should we align with the GEP's `getTypeAtIndex` implementation and check that the struct element index is valid?
https://github.com/llvm/llvm-project/blob/2e718be51d78bec269a883e9606f621539fe567a/llvm/lib/IR/Instructions.cpp#L1592-L1593
GEP's `getTypeAtIndex` also returns `nullptr` instead of using `llvm_unreachable`, so the caller is at least guaranteed a known value (`nullptr`) instead of undefined behavior in a release build.
https://github.com/llvm/llvm-project/pull/218846
More information about the llvm-commits
mailing list