-
Notifications
You must be signed in to change notification settings - Fork 59
add pass to replace copysign.f16 #722
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
Conversation
since pocl does not support it.
|
Your PR requires formatting changes to meet the project's style guidelines. Click here to view the suggested changes.diff --git a/src/spirv.jl b/src/spirv.jl
index 07ae2da..4ca9538 100644
--- a/src/spirv.jl
+++ b/src/spirv.jl
@@ -361,54 +361,56 @@ function replace_copysign_f16!(mod::LLVM.Module)
changed = false
@tracepoint "replace copysign f16" begin
- # Find llvm.copysign.f16 intrinsic
- copysign_name = "llvm.copysign.f16"
- if haskey(functions(mod), copysign_name)
- copysign_fn = functions(mod)[copysign_name]
-
- # Process all uses of the intrinsic
- for use in uses(copysign_fn)
- call_inst = user(use)
- if isa(call_inst, LLVM.CallInst)
- @dispose builder=IRBuilder() begin
- # Position builder before the call
- position!(builder, call_inst)
-
- # Get operands (x and y)
- x = operands(call_inst)[1] # magnitude
- y = operands(call_inst)[2] # sign source
-
- # Create the replacement implementation
- i16_type = LLVM.IntType(16)
-
- # Bitcast half values to i16
- x_bits = bitcast!(builder, x, i16_type)
- y_bits = bitcast!(builder, y, i16_type)
-
- # XOR the bit patterns and check if result is negative
- xor_result = xor!(builder, y_bits, x_bits)
- is_negative = icmp!(builder, LLVM.API.LLVMIntSLT, xor_result,
- ConstantInt(i16_type, 0))
-
- # Create fneg of x
- neg_x = fneg!(builder, x)
-
- # Select between neg_x and x based on the sign test
- result = select!(builder, is_negative, neg_x, x)
-
- # Replace uses and erase the original call
- replace_uses!(call_inst, result)
- erase!(call_inst)
- changed = true
+ # Find llvm.copysign.f16 intrinsic
+ copysign_name = "llvm.copysign.f16"
+ if haskey(functions(mod), copysign_name)
+ copysign_fn = functions(mod)[copysign_name]
+
+ # Process all uses of the intrinsic
+ for use in uses(copysign_fn)
+ call_inst = user(use)
+ if isa(call_inst, LLVM.CallInst)
+ @dispose builder = IRBuilder() begin
+ # Position builder before the call
+ position!(builder, call_inst)
+
+ # Get operands (x and y)
+ x = operands(call_inst)[1] # magnitude
+ y = operands(call_inst)[2] # sign source
+
+ # Create the replacement implementation
+ i16_type = LLVM.IntType(16)
+
+ # Bitcast half values to i16
+ x_bits = bitcast!(builder, x, i16_type)
+ y_bits = bitcast!(builder, y, i16_type)
+
+ # XOR the bit patterns and check if result is negative
+ xor_result = xor!(builder, y_bits, x_bits)
+ is_negative = icmp!(
+ builder, LLVM.API.LLVMIntSLT, xor_result,
+ ConstantInt(i16_type, 0)
+ )
+
+ # Create fneg of x
+ neg_x = fneg!(builder, x)
+
+ # Select between neg_x and x based on the sign test
+ result = select!(builder, is_negative, neg_x, x)
+
+ # Replace uses and erase the original call
+ replace_uses!(call_inst, result)
+ erase!(call_inst)
+ changed = true
+ end
end
end
- end
- # Remove the intrinsic declaration if no longer used
- if isempty(uses(copysign_fn))
- erase!(copysign_fn)
+ # Remove the intrinsic declaration if no longer used
+ if isempty(uses(copysign_fn))
+ erase!(copysign_fn)
+ end
end
- end
end
return changed |
companion PR to JuliaGPU/GPUCompiler.jl#722
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #722 +/- ##
==========================================
- Coverage 75.40% 74.81% -0.59%
==========================================
Files 24 24
Lines 3521 3550 +29
==========================================
+ Hits 2655 2656 +1
- Misses 866 894 +28 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
Changes moved into JuliaGPU/OpenCL.jl#371 |
since pocl does not support it.
Written with help from Copilot