[llvm] [InstSimplify] Support ptrtoaddr in simplifyICmpInst() (PR #171985)
Yingwei Zheng via llvm-commits
llvm-commits at lists.llvm.org
Fri Dec 12 06:56:14 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)) &&
+ Q.DL.getAddressType(SrcTy) == DstTy) {
if (Constant *RHSC = dyn_cast<Constant>(RHS)) {
// Transfer the cast to the constant.
if (Value *V = simplifyICmpInst(Pred, SrcOp,
ConstantExpr::getIntToPtr(RHSC, SrcTy),
Q, MaxRecurse - 1))
return V;
- } else if (PtrToIntInst *RI = dyn_cast<PtrToIntInst>(RHS)) {
+ } else if (isa<PtrToIntInst>(RHS) || isa<PtrToAddrInst>(RHS)) {
----------------
dtcxzyw wrote:
```suggestion
} else if (isa<PtrToIntInst, PtrToAddrInst>(RHS)) {
```
https://github.com/llvm/llvm-project/pull/171985
More information about the llvm-commits
mailing list