[llvm] [InstSimplify] Support ptrtoaddr in simplifyICmpInst() (PR #171985)

Yingwei Zheng via llvm-commits llvm-commits at lists.llvm.org
Fri Dec 12 06:56:13 PST 2025


================
@@ -3847,17 +3847,19 @@ static Value *simplifyICmpInst(CmpPredicate Pred, Value *LHS, Value *RHS,
     Type *SrcTy = SrcOp->getType();
     Type *DstTy = LI->getType();
 
-    // Turn icmp (ptrtoint x), (ptrtoint/constant) into a compare of the input
-    // if the integer type is the same size as the pointer type.
-    if (MaxRecurse && isa<PtrToIntInst>(LI) &&
-        Q.DL.getTypeSizeInBits(SrcTy) == DstTy->getPrimitiveSizeInBits()) {
+    // Turn icmp (ptrtoint/ptrtoaddr x), (ptrtoint/ptrtoaddr/constant) into a
+    // compare of the input if the integer type is the same size as the
+    // pointer address type (icmp only compares the address of the pointer).
+    if (MaxRecurse && (isa<PtrToIntInst>(LI) || isa<PtrToAddrInst>(LI)) &&
----------------
dtcxzyw wrote:

```suggestion
    if (MaxRecurse && (isa<PtrToIntInst, PtrToAddrInst>(LI)) &&
```

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


More information about the llvm-commits mailing list