Skip to content

Conversation

@simeonschaub
Copy link
Member

@simeonschaub simeonschaub commented Sep 22, 2025

since pocl does not support it.

Written with help from Copilot

since pocl does not support it.
@github-actions
Copy link
Contributor

Your PR requires formatting changes to meet the project's style guidelines.
Please consider running Runic (git runic master) to apply these changes.

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

simeonschaub added a commit to simeonschaub/OpenCL.jl that referenced this pull request Sep 22, 2025
@codecov
Copy link

codecov bot commented Sep 23, 2025

Codecov Report

❌ Patch coverage is 3.44828% with 28 lines in your changes missing coverage. Please review.
✅ Project coverage is 74.81%. Comparing base (aa05fa3) to head (712270b).
⚠️ Report is 2 commits behind head on master.

Files with missing lines Patch % Lines
src/spirv.jl 3.44% 28 Missing ⚠️
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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@simeonschaub
Copy link
Member Author

Changes moved into JuliaGPU/OpenCL.jl#371

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants