[llvm] [SPIR-V] Add lowering of ptrtoaddr (PR #184577)

Juan Manuel Martinez Caamaño via llvm-commits llvm-commits at lists.llvm.org
Wed Mar 4 05:14:34 PST 2026


================
@@ -0,0 +1,11 @@
+; RUN: llc -O0 -mtriple=spirv64-unknown-unknown %s -o - | FileCheck %s
+; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv64-unknown-unknown %s -o - -filetype=obj | spirv-val %}
+
+; CHECK: OpConvertPtrToU
+
+define spir_kernel void @test_ptrtoaddr(ptr addrspace(1) %p, ptr addrspace(1) %res) {
+entry:
+  %addr = ptrtoaddr ptr addrspace(1) %p to i64
----------------
jmmartinez wrote:

According to the LLVM spec https://llvm.org/docs/LangRef.html#id293 : _"The ‘ptrtoaddr’ instruction converts the pointer or a vector of pointers value to the underlying integer address (or vector of addresses)"_. And it is also the case for `ptrtoint`.

I suppose that, in an ideal world, we should accept any valid LLVM-IR.

If it is not supported for vectors of pointers for `ptrtoint` already, I think it's ok to leave it unsupported and emit an error.


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


More information about the llvm-commits mailing list