[llvm] [InferAddressSpaces] apply InferAddressSpaces to inttoptr-zext-ptrtoint address expression. (PR #79108)

via llvm-commits llvm-commits at lists.llvm.org
Sun Apr 7 04:39:06 PDT 2024


================
@@ -0,0 +1,73 @@
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 4
+; RUN: opt -S -o - -passes=infer-address-spaces -assume-default-is-flat-addrspace %s | FileCheck %s
+
+target datalayout = "e-p:64:64-p1:64:64-p2:32:32-p3:32:32-p4:64:64-p5:32:32-p6:32:32-p7:160:256:256:32-p8:128:128-i64:64-v16:16-v24:32-v32:32-v48:64-v96:128-v192:256-v256:256-v512:512-v1024:1024-v2048:2048-n32:64-S32-A5-ni:7:8"
+
+define void @zext_ptrint_conversion(ptr addrspace(3) %x) {
+; CHECK-LABEL: define void @zext_ptrint_conversion(
+; CHECK-SAME: ptr addrspace(3) [[X:%.*]]) {
+; CHECK-NEXT:    store i32 0, ptr addrspace(3) [[X]], align 4
+; CHECK-NEXT:    ret void
+;
+  %tmp0 = ptrtoint ptr addrspace(3) %x to i32
+  %tmp1 = zext i32 %tmp0 to i64
+  %tmp2 = inttoptr i64 %tmp1 to ptr
+  store i32 0, ptr %tmp2
----------------
yujc9 wrote:

I actually don't introduce another no-op cast, but another special case. This code works for AMDGPU in fact. In AMDGPU, the pointer with address space 3 is 32 bit, while the pointer with address space 0 is 64 bit. So, no-op cast won't handle this conversion. That's why there is a zero ext.
Introducing this pattern does similar thing `We only special case the case we do now because the IR is missing a way to bitcast between pointers with the same size`, but "missing a way to convert between pointers with different size".

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


More information about the llvm-commits mailing list