[flang-commits] [clang] [flang] [llvm] [InstCombine] Canonicalize GEP source element types (PR #180745)
Yingwei Zheng via flang-commits
flang-commits at lists.llvm.org
Thu Feb 26 08:41:40 PST 2026
================
@@ -3488,6 +3488,24 @@ Instruction *InstCombinerImpl::visitGetElementPtrInst(GetElementPtrInst &GEP) {
BackIndices, GEP.getNoWrapFlags());
}
+ // Canonicalize gep %T to gep [sizeof(%T) x i8]:
+ auto IsCanonicalType = [](Type *Ty) {
+ if (auto *AT = dyn_cast<ArrayType>(Ty))
+ Ty = AT->getElementType();
+ return Ty->isIntegerTy(8);
+ };
+ if (Indices.size() == 1 && !IsCanonicalType(GEPEltType)) {
+ TypeSize Scale = DL.getTypeAllocSize(GEPEltType);
----------------
dtcxzyw wrote:
I am not sure if we should respect ABI alignment in GEP: https://godbolt.org/z/bM1zdT96h
The current canonicalization doubles the stride.
If the answer is yes, it may be problematic to strip the leading zero index of a GEP with a vector source element type.
See also https://github.com/llvm/llvm-project/pull/75448.
https://github.com/llvm/llvm-project/pull/180745
More information about the flang-commits
mailing list