[llvm] [InferAS] Infer the address space of inttoptr (PR #173244)
Artem Belevich via llvm-commits
llvm-commits at lists.llvm.org
Thu Jan 8 11:01:38 PST 2026
================
@@ -369,15 +384,56 @@ 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.");
}
}
+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;
+
+ auto *Xor = dyn_cast<Operator>(I2P->getOperand(0));
+ if (!Xor || Xor->getOpcode() != Instruction::Xor)
+ return false;
----------------
Artem-B wrote:
What I meant is whether we can infer unchanged bits for an arbitrary sequence of instructions.
It appears that InstCombine pass can do it in principle: https://godbolt.org/z/98jsWavjT
We may want to do something similar.
https://github.com/llvm/llvm-project/pull/173244
More information about the llvm-commits
mailing list