Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LLVMPtr's address space annotation is lost with opaque pointers #54549

Closed
maleadt opened this issue May 22, 2024 · 0 comments · Fixed by #54548
Closed

LLVMPtr's address space annotation is lost with opaque pointers #54549

maleadt opened this issue May 22, 2024 · 0 comments · Fixed by #54548
Labels
bug Indicates an unexpected problem or unintended behavior compiler:codegen Generation of LLVM IR and native code

Comments

@maleadt
Copy link
Member

maleadt commented May 22, 2024

MWE:

using InteractiveUtils
using Core: LLVMPtr

@inline passthrough(ptr::LLVMPtr{T,A}) where {T,A} = Base.llvmcall(("""
        define ptr addrspace(1) @entry(ptr addrspace(1) %0) #0 {
        entry:
            ret ptr addrspace(1) %0
        }

        attributes #0 = { alwaysinline }""", "entry"),
    LLVMPtr{T,A}, Tuple{LLVMPtr{T,A}}, ptr)

f(gws) = passthrough(reinterpret(LLVMPtr{UInt32,1}, gws))

code_llvm(f, Tuple{Ptr{Nothing}})
julia-debug: /workspace/srcdir/llvm-project/llvm/lib/IR/Instructions.cpp:652: void llvm::CallInst::init(llvm::FunctionType*, llvm::Value*, llvm::ArrayRef<llvm::Value*>, llvm::ArrayRef<llvm::OperandBundleDefT<llvm::Value*> >, const llvm::Twine&): Assertion `(i >= FTy->getNumParams() || FTy->getParamType(i) == Args[i]->getType()) && "Calling a function with a bad signature!"' failed.

Looks like we're somehow losing the address space property of the LLVMPtr when its bitcasted:

(rr) call jl_(ctx.code )
Array{Any, 1}(dims=(4,), mem=Memory{Any}(4, 0x7493e013fea0)[
  Expr(:call, Base.bitcast, Core.LLVMPtr{UInt32, 1}, Core.Argument(n=2)),
  Expr(:call, Core.tuple, "define ptr addrspace(1) @entry(ptr addrspace(1) %0) #0 {\nentry:\n    ret ptr addrspace(1) %0\n}\n\nattributes #0 = { alwaysinline }", "entry"),
  Expr(:call, Base.llvmcall, SSAValue(2), Core.LLVMPtr{UInt32, 1}, Tuple{Core.LLVMPtr{UInt32, 1}}, SSAValue(1)),
  Core.ReturnNode(val=SSAValue(3))])

(rr)
837	        jl_value_t *argi = args[4 + i];
(rr) call jl_(argi)
SSAValue(1)

(rr)
838	        jl_cgval_t arg = emit_expr(ctx, argi);
(rr) call arg.V->dump()
ptr %"gws::Ptr"

IR looks fine:

13 1 ─ %1 = Core.bitcast(LLVMPtr{UInt32, 1}, _2)::LLVMPtr{UInt32, 1}
   │   %2 = Core.tuple("define ptr addrspace(1) @entry(ptr addrspace(1) %0) #0 {\nentry:\n    ret ptr addrspace(1) %0\n}\n\nattributes #0 = { alwaysinline }", "entry")::Tuple{String, String}
   │   %3 = Base.llvmcall(%2, LLVMPtr{UInt32, 1}, Tuple{LLVMPtr{UInt32, 1}}, %1)::LLVMPtr{UInt32, 1}
   └──      return %3                                          ││
    => LLVMPtr{UInt32, 1}
@maleadt maleadt added bug Indicates an unexpected problem or unintended behavior compiler:codegen Generation of LLVM IR and native code labels May 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Indicates an unexpected problem or unintended behavior compiler:codegen Generation of LLVM IR and native code
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant