[llvm] [InferAS] Infer the address space of inttoptr (PR #173244)

Jay Foad via llvm-commits llvm-commits at lists.llvm.org
Tue Mar 10 03:58:06 PDT 2026


jayfoad wrote:

I am concerned that this PR is confusing "bits that are preserved by an addrspacecast" with "bits that can be changed in a pointer while keeping it in the same address space".

To take an AMDGPU example, FLAT (AS 0) and GLOBAL (AS 1) are 64-bit address spaces with identical bit layout. Casts between FLAT and GLOBAL preserve all bits, but not every valid FLAT address is a valid GLOBAL address.

Example:
```llvm
   %flatp = addrspacecast ptr addrspace(1) %globalp to ptr
   %a = ptrtoint ptr %flatp to i64
   %b = xor i64 %a, %c ; where %c can have any value
   %flatp2 = inttoptr i64 %b to ptr
```
This PR will replace all uses of `%flatp2 = inttoptr i64 %b to ptr` with `%globalp2 = inttoptr i64 %b to ptr addrspace(1)`. I think that is wrong because the bit pattern in `%b` might not correspond to any valid GLOBAL pointer. Unless I am missing something about the semantics of ptrtoint/inttoptr?

https://github.com/llvm/llvm-project/pull/173244


More information about the llvm-commits mailing list