[llvm] [InstCombine] Remove one-use restriction on icmp of gep fold (PR #76730)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 3 07:39:32 PST 2024


================
@@ -813,14 +813,29 @@ Instruction *InstCombinerImpl::foldGEPICmp(GEPOperator *GEPLHS, Value *RHS,
       }
     }
 
-    // Only lower this if the icmp is the only user of the GEP or if we expect
-    // the result to fold to a constant!
-    if ((GEPsInBounds || CmpInst::isEquality(Cond)) &&
-        (GEPLHS->hasAllConstantIndices() || GEPLHS->hasOneUse()) &&
-        (GEPRHS->hasAllConstantIndices() || GEPRHS->hasOneUse())) {
+    if (GEPsInBounds || CmpInst::isEquality(Cond)) {
+      auto EmitGEPOffsetAndRewrite = [&](GEPOperator *GEP) {
+        auto *Inst = dyn_cast<Instruction>(GEP);
----------------
nikic wrote:

I've added an insert pointer guard, though I think it shouldn't make a difference in practice.

Getelementptr constant expressions exist, but the syntax is `getelementptr (`, not `(getelementptr`.

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


More information about the llvm-commits mailing list