[llvm] [InferAS] Infer the address space of inttoptr (PR #173244)
Matt Arsenault via llvm-commits
llvm-commits at lists.llvm.org
Thu Jan 22 01:54:47 PST 2026
================
@@ -375,15 +390,81 @@ 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:
----------------
arsenm wrote:
I'm not sure why you are checking computeKnownBits, and switching over the opcodes to interpret it. computeKnownBits did everything for you?
If you really need to do that, should avoid calling computeKnownBits unless you're going to use the result
https://github.com/llvm/llvm-project/pull/173244
More information about the llvm-commits
mailing list