Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 16 additions & 11 deletions src/metal.jl
Original file line number Diff line number Diff line change
Expand Up @@ -880,18 +880,23 @@ function lower_llvm_intrinsics!(@nospecialize(job::CompilerJob), fun::LLVM.Funct

# determine type of the intrinsic
typ = value_type(call)
if typ isa LLVM.IntegerType
fn *= signed::Bool ? ".s" : ".u"
fn *= ".$(width(typ))"
elseif typ == LLVM.HalfType()
fn *= ".f16"
elseif typ == LLVM.FloatType()
fn *= ".f32"
elseif typ == LLVM.DoubleType()
fn *= ".f64"
else
error("Unsupported intrinsic type: $typ")
function type_suffix(typ)
# XXX: can't we use LLVM to do this kind of mangling?
if typ isa LLVM.IntegerType
(signed::Bool ? "s" : "u") * "$(width(typ))"
elseif typ == LLVM.HalfType()
"f16"
elseif typ == LLVM.FloatType()
"f32"
elseif typ == LLVM.DoubleType()
"f64"
elseif typ isa LLVM.VectorType
"v$(size(typ))$(type_suffix(eltype(typ)))"
else
error("Unsupported intrinsic type: $typ")
end
end
fn *= "." * type_suffix(typ)

new_intr = LLVM.Function(mod, fn, call_ft)
@dispose builder=IRBuilder() begin
Expand Down
8 changes: 8 additions & 0 deletions test/metal_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,14 @@ end
@test !occursin(r"call i32 @julia.air.thread_position_in_threadgroup.i32", ir)
end

@testset "vector intrinsics" begin
foo(x, y) = ccall("llvm.smax.v2i64", llvmcall, NTuple{2, VecElement{Int64}},
(NTuple{2, VecElement{Int64}}, NTuple{2, VecElement{Int64}}), x, y)

ir = sprint(io->Metal.code_llvm(io, foo, (NTuple{2, VecElement{Int64}}, NTuple{2, VecElement{Int64}})))
@test occursin("air.max.v2s64", ir)
end

end

end
Expand Down