[llvm] [InstCombine] Add limit for expansion of gep chains (PR #147065)

Yingwei Zheng via llvm-commits llvm-commits at lists.llvm.org
Sat Jul 5 00:25:07 PDT 2025


================
@@ -2144,13 +2144,35 @@ CommonPointerBase CommonPointerBase::compute(Value *LHS, Value *RHS) {
   return Base;
 }
 
+bool CommonPointerBase::isExpensive() const {
+  bool SeenConst = false;
+  unsigned NumGEPs = 0;
+  auto ProcessGEPs = [&SeenConst, &NumGEPs](ArrayRef<GEPOperator *> GEPs) {
+    bool SeenMultiUse = false;
+    for (GEPOperator *GEP : GEPs) {
+      // Only count GEPs after the first multi-use GEP. For the first one,
+      // we will directly reuse the offset.
----------------
dtcxzyw wrote:

> Do you think it would be better to start with changing the GEP expansion/rewriting?

Yeah, if the compile-time impact is acceptable.

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


More information about the llvm-commits mailing list