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

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 21 07:50:09 PDT 2025


================
@@ -2072,6 +2072,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_c_Add(m_PtrToIntSameSize(DL, m_Value(Base)), m_Value(Offset))) &&
----------------
nikic wrote:

Should this have a one use check on the add? Otherwise we can end up with both the add and the gep.

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


More information about the llvm-commits mailing list