Skip to content

Commit

Permalink
Fix type suffix of integer intrinsics (#538)
Browse files Browse the repository at this point in the history
Co-authored-by: Tim Besard <[email protected]>
  • Loading branch information
tgymnich and maleadt authored Jan 5, 2024
1 parent 111685f commit 962b84e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
9 changes: 7 additions & 2 deletions src/metal.jl
Original file line number Diff line number Diff line change
Expand Up @@ -894,7 +894,7 @@ function lower_llvm_intrinsics!(@nospecialize(job::CompilerJob), fun::LLVM.Funct
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))"
"i$(width(typ))"
elseif typ == LLVM.HalfType()
"f16"
elseif typ == LLVM.FloatType()
Expand All @@ -907,7 +907,12 @@ function lower_llvm_intrinsics!(@nospecialize(job::CompilerJob), fun::LLVM.Funct
error("Unsupported intrinsic type: $typ")
end
end
fn *= "." * type_suffix(typ)

if typ isa LLVM.IntegerType || (typ isa LLVM.VectorType && eltype(typ) isa LLVM.IntegerType)
fn *= "." * (signed::Bool ? "s" : "u") * "." * type_suffix(typ)
else
fn *= "." * type_suffix(typ)
end

new_intr = if haskey(functions(mod), fn)
functions(mod)[fn]
Expand Down
2 changes: 1 addition & 1 deletion test/metal_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ end
(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)
@test occursin("air.max.s.v2i64", ir)
end

end
Expand Down

0 comments on commit 962b84e

Please sign in to comment.