[llvm] [InstComb] Fold inttoptr (add (ptrtoint %B), %O) -> GEP for ICMP users. (PR #153421)

Yingwei Zheng via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 21 05:42:05 PDT 2025


================
@@ -2073,6 +2073,18 @@ Instruction *InstCombinerImpl::visitIntToPtr(IntToPtrInst &CI) {
     return new IntToPtrInst(P, CI.getType());
   }
 
+  // Replace (inttoptr (add (ptrtoint %Base), %Offset)) with
+  // (getelementptr i8, %Base, %Offset) if all users are ICmps.
+  Value *Base;
+  Value *Offset;
+  if (match(CI.getOperand(0),
+            m_Add(m_PtrToIntSameSize(DL, m_Value(Base)), m_Value(Offset))) &&
----------------
dtcxzyw wrote:

```suggestion
            m_c_Add(m_PtrToIntSameSize(DL, m_Value(Base)), m_Value(Offset))) &&
```
Please add some commuted tests.


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


More information about the llvm-commits mailing list