[llvm] [clang] [InstCombine] Canonicalize constant GEPs to i8 source element type (PR #68882)

Björn Pettersson via cfe-commits cfe-commits at lists.llvm.org
Tue Nov 28 04:07:34 PST 2023


================
@@ -2282,6 +2282,15 @@ Instruction *InstCombinerImpl::visitGetElementPtrInst(GetElementPtrInst &GEP) {
   if (MadeChange)
     return &GEP;
 
+  // Canonicalize constant GEPs to i8 type.
----------------
bjope wrote:

FWIW, this is a bit interesting downstream with non-8-bit addressing units :-)

Today i8 would be quite rare as GEP type for us as it is smaller than the addressing unit size. But I figure that canonicalizing to some other type downstream could end up as a lot of work (or lots of missed optimizations).

Afaict accumulateConstantOffset is returning an offset that depends on TypeStoreSize. So as long as this is used in a way so that the address still would be given by `baseptr +  DL.getTypeStoreSize(i8) * Offset` and not `baseptr + 8 * Offset` , then I guess things will be fine (i.e not assuming that the offset is an 8-bit offset).

As far as I can tell you could just as well have picked i1 instead of i8 (given that `DL.getTypeStoreSize(i1)==DL.getTypeStoreSize(i8)`). That would probably look confusing, but that is what happens for us when using i8 as type as we can't address individual octets.

(I also see this as a reminder for looking at the ptradd RFC to understand how that will impact us, so that we are prepared for that.)

https://github.com/llvm/llvm-project/pull/68882


More information about the cfe-commits mailing list