[llvm] [SROA] analyze gep(ptr,phi(const...)) (PR #82425)

Artem Belevich via llvm-commits llvm-commits at lists.llvm.org
Wed Feb 21 16:37:43 PST 2024


================
@@ -4070,12 +4070,67 @@ class AggLoadStoreRewriter : public InstVisitor<AggLoadStoreRewriter, bool> {
     return true;
   }
 
+  bool foldGEPPhiConst(GetElementPtrInst &GEPI) {
----------------
Artem-B wrote:

> can we copy foldGEPSelect and handle both gep(phi(ptr), idx) and gep(ptr, phi(idx)) in one function? 

They are deceptively similar on the surface, but they do literally everything differently. The first one operates on pointer, the other one on the indices. Combined function will literally have to provide different if/else for each of the steps, except for a just a few common lines . I've tried and the code is rather unreadable.

> and also handle GEPs with more than one index

That is probably unnecessary, now that instcombine normalizes GEPs to untyped ones with a single byte offset.

Also, if we were to do try expanding multiple indices this way, it would result in a combinatorial explosion of the number of GEPs we may need to create.

If/when we run into this, and do discover that we want to handle multiple indices, we should be able to relax the algorithm a bit and iteratively expand one index at a time. 

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


More information about the llvm-commits mailing list