================
@@ -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);
----------------
nikic wrote:
> I am not sure if we should respect ABI alignment in GEP:
> https://godbolt.org/z/bM1zdT96h The current canonicalization doubles the
> stride.
Respecting ABI alignment is correct here, GEP is defined in terms of the type
allocation size, not the type store size. Note that the godbolt doesn't really
test what you want it to, because the data layout gets overwritten by the
target data layout. (It's not possible to use llc with a custom data layout.)
> 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 #75448.
This is a good point. The leading zero removal is indeed incorrect for GEPs
into vectors of overaligned type.
https://github.com/llvm/llvm-project/pull/180745
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits