[llvm] [InstCombine] fold `sub(zext(ptrtoint), zext(ptrtoint))` (PR #115369)

Nikita Popov via llvm-commits llvm-commits at lists.llvm.org
Wed Nov 13 14:23:58 PST 2024


================
@@ -2631,6 +2631,18 @@ Instruction *InstCombinerImpl::visitSub(BinaryOperator &I) {
                                                /* IsNUW */ false))
       return replaceInstUsesWith(I, Res);
 
+  if (match(Op0, m_ZExt(m_PtrToInt(m_Value(LHSOp)))) &&
+      match(Op1, m_PtrToInt(m_Value(RHSOp))) && isa<GlobalValue>(RHSOp)) {
+    Value *Offset;
+    if (match(LHSOp, m_GEP(m_Specific(RHSOp), m_Value(Offset)))) {
----------------
nikic wrote:

This is going to restrict to a single-offset GEP, which is unnecessary. You should directly start with a `dyn_cast<GEPOperator>` and then check getPointerOperand().

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


More information about the llvm-commits mailing list