[llvm] [NVPTX] Handle symbol-relative integer initializers in aggregates (PR #201220)

Artem Belevich via llvm-commits llvm-commits at lists.llvm.org
Wed Jun 3 12:07:17 PDT 2026


================
@@ -20,3 +20,18 @@
 ; PTX64-NEXT: .visible .global .align 8 .u64 b2[2] = {b, b};
 @b2 = addrspace(1) global [2 x ptr addrspace(1)] [ptr addrspace(1) @b, ptr addrspace(1) @b]
 @b = addrspace(1) global i8 1
+
+
+; Emit global aggregates with a field computed from the address of another global.
+ at g = addrspace(1) global i8 0
+ at h = addrspace(1) global i8 0
+
+; PTX64: .visible .global .align 8 .u64 sadd[2] = {g+4, 7};
+ at sadd = addrspace(1) global { i64, i64 } { i64 add (i64 ptrtoint (ptr addrspace(1) @g to i64), i64 4), i64 7 }
+
+; PTX64: .visible .global .align 8 .u64 ssub[2] = {g-4, 7};
+ at ssub = addrspace(1) global { i64, i64 } { i64 sub (i64 ptrtoint (ptr addrspace(1) @g to i64), i64 4), i64 7 }
+
+; PTX32: .visible .global .align 8 .u64 sdiff = (g&4294967295)-(h&4294967295);
+; PTX64: .visible .global .align 8 .u64 sdiff = g-h;
----------------
Artem-B wrote:

Huh. TIL that IR han have initializer expressions. I'm surprised that ptxas supports them, too.
I assume the test with PTXAS enabled does pass.

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


More information about the llvm-commits mailing list