[llvm] [SeparateConstOffsetFromGEP] Support GEP reordering for different types (PR #90802)

Jeffrey Byrnes via llvm-commits llvm-commits at lists.llvm.org
Mon May 6 15:36:18 PDT 2024


================
@@ -1017,6 +1016,51 @@ bool SeparateConstOffsetFromGEP::reorderGEP(GetElementPtrInst *GEP,
       IsChainInBounds &= KnownPtrGEPIdx.isNonNegative();
     }
   }
+  TypeSize GEPSize = DL->getTypeSizeInBits(GEP->getSourceElementType());
+  TypeSize PtrGEPSize = DL->getTypeSizeInBits(PtrGEP->getSourceElementType());
----------------
jrbyrnes wrote:

> maybe I don't get what this code is doing

I think you probably do .. We're looking at GEPs that have ptrs produced by another GEP. If the inner GEP has a constant offset and the outer GEP doesn't, we reorganize so the outer GEP has the constant offset. Previously, this was only supported for GEPs with the same alloc type; this patch extends it somewhat by allowing for some differences in alloc type and doing the necessary accounting in the index. 

> Why do you need/want to rewrite them?

We're not requiring one use on the nested GEP, so we can't write it in place. Not sure if it makes sense to try to write the outer GEP in place if we're changing it's pointer?

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


More information about the llvm-commits mailing list