[clang] [llvm] [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 05:45:11 PST 2023


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

Right. So things can be expected to just work (given getTypeStoreSize(i8)==1), even when the addressing unit isn't 8 bits.

Since
```
%gep = getelementptr i3, ptr %p, i16 1
%gep = getelementptr i8, ptr %p, i16 1
%gep = getelementptr i16, ptr %p, i16 1
```
all are equivalent (for my target), then this patch just makes that more obvious by canonicalizing them into a single form. 
So we just need to update some lit test checks to expect "getelementptr i8" instead of "getelementptr i16" downstream, and hopefully things will be fine.

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


More information about the cfe-commits mailing list