[llvm] [InferAddressSpaces] apply InferAddressSpaces to inttoptr-zext-ptrtoint address expression. (PR #79108)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Jan 25 19:32:34 PST 2024
yujc9 wrote:
The reason for implementing this patch is to eliminate the cast for the pattern inttoptr - zext - ptrtoint.
```
define void @zext_ptrint_conversion(ptr addrspace(3) %x) {
%tmp1 = ptrtoint ptr addrspace(3) %x to i32
%tmp2 = zext i32 %tmp1 to i64
%tmp3 = inttoptr i64 %tmp2 to ptr
store i32 0, ptr %tmp3
ret void
}
```
For instance, if we try to store a value to a generic pointer `%tmp3` which is converted from a pointer `%x` with address space 3. If these two pointers have different size, an `zext` operation may be inserted. Since `zext` does not introduce any information, storing a value to the generic pointer `%tmp3` should be equivalent to storing to ptr addrspace(3) `%x` directly.
To keep the transformation safe, the `ptrtoint` and `inttoptr` operation should be no-op cast. In addition, we require these two pointers in different address spaces and different size so that no extra information is added by `zext` operation.
Not sure other possibilities to make this conversion unsafe.
https://github.com/llvm/llvm-project/pull/79108
More information about the llvm-commits
mailing list