[llvm] [InferAS] Infer the address space of inttoptr (PR #173244)
Matt Arsenault via llvm-commits
llvm-commits at lists.llvm.org
Tue Jan 20 11:06:21 PST 2026
================
@@ -1927,6 +1927,20 @@ class TargetTransformInfo {
/// This should also apply to lowering for vector funnel shifts (rotates).
LLVM_ABI bool isVectorShiftByScalarCheap(Type *Ty) const;
+ /// Return true if it is safe to cast integer to pointer with new address
+ /// space. The address of integer form may only change in the least
+ /// significant bit (e.g. within a page). In that case target can determine
+ /// if it is safe to cast the generic address space to the original address
+ /// space. For below example, we can replace `%gp2 = inttoptr i64 %b to ptr`
+ /// with `%gp2 = inttoptr i64 %b to ptr addrspace(2)`
+ /// %gp = addrspacecast ptr addrspace(2) %sp to ptr
+ /// %a = ptrtoint ptr %gp to i64
+ /// %b = xor i64 7, %a
+ /// %gp2 = inttoptr i64 %b to ptr
+ /// store i16 0, ptr %gp2, align 2
+ LLVM_ABI bool isSafeToCastIntPtrWithAS(unsigned AddrChangedLSB,
+ unsigned SrcAS, unsigned DstAS) const;
----------------
arsenm wrote:
I think this API needs some work. Instead of "AddrChangedLSB", how about a pointer-width APInt bit mask indicating which bits are changed?
The name could also be rephrased in terms of addrspacecast masked bits preserve address space.
Alternatively, can you deduce this from computeKnownBitsAddrSpaceCast?
https://github.com/llvm/llvm-project/pull/173244
More information about the llvm-commits
mailing list