[llvm] [InferAS] Infer the address space of inttoptr (PR #173244)
Luo Yuanke via llvm-commits
llvm-commits at lists.llvm.org
Sat Jan 24 18:11:59 PST 2026
================
@@ -375,15 +394,77 @@ getPointerOperands(const Value &V, const DataLayout &DL,
return {II.getArgOperand(0)};
}
case Instruction::IntToPtr: {
- assert(isNoopPtrIntCastPair(&Op, DL, TTI));
- auto *P2I = cast<Operator>(Op.getOperand(0));
- return {P2I->getOperand(0)};
+ if (isNoopPtrIntCastPair(&Op, DL, TTI)) {
+ auto *P2I = cast<Operator>(Op.getOperand(0));
+ return {P2I->getOperand(0)};
+ }
+ assert(isSafeToCastPtrIntPair(&Op, DL));
+ return {PtrIntCastPairs[&Op]};
}
default:
llvm_unreachable("Unexpected instruction type.");
}
}
+// Return mask. The 1 in mask indicate the bit is changed.
+// This helper function is to compute the max know changed bits for ptr1 and
+// ptr2 after the operation `ptr2 = ptr1 Op Mask`.
+static APInt computeMaxChangedPtrBits(const Operator *Op, const Value *Mask,
+ const DataLayout &DL, AssumptionCache *AC,
+ const DominatorTree *DT) {
+ KnownBits Known = computeKnownBits(Mask, DL, AC, nullptr, DT);
+ switch (Op->getOpcode()) {
+ case Instruction::Xor:
+ case Instruction::Or:
+ return ~Known.Zero;
+ case Instruction::And:
+ return ~Known.One;
+ default:
+ return APInt::getAllOnes(Known.getBitWidth());
+ }
+}
+
+bool InferAddressSpacesImpl::isSafeToCastPtrIntPair(
+ const Operator *I2P, const DataLayout &DL) const {
+ assert(I2P->getOpcode() == Instruction::IntToPtr);
+ if (PtrIntCastPairs.count(I2P))
+ return true;
+
+ if (I2P->getType()->isVectorTy())
+ return false;
+
+ Value *LogicalOp = I2P->getOperand(0);
+ Value *OldPtr, *Mask;
+ if (!match(LogicalOp,
+ m_c_BitwiseLogic(m_PtrToInt(m_Value(OldPtr)), m_Value(Mask))))
----------------
LuoYuanke wrote:
revert the pattern match patch.
https://github.com/llvm/llvm-project/pull/173244
More information about the llvm-commits
mailing list