[llvm] [SPIRV][HLSL] Add HLSL intrinsic tests (PR #86844)

Natalie Chouinard via llvm-commits llvm-commits at lists.llvm.org
Thu Mar 28 12:39:51 PDT 2024


================
@@ -0,0 +1,29 @@
+; RUN: llc -O0 -mtriple=spirv-unknown-unknown %s -o - | FileCheck %s
+; RUN: %if spirv-tools %{ llc -O0 -mtriple=spirv-unknown-unknown %s -o - -filetype=obj | spirv-val %}
+
+; CHECK: OpExtInstImport "GLSL.std.450"
+
+define noundef half @test_fmax_half(half noundef %a, half noundef %b) {
+entry:
+; CHECK: %[[#]] = OpExtInst %[[#]] %[[#]] FMax %[[#]] %[[#]]
+  %0 = call half @llvm.maxnum.f16(half %a, half %b)
+  ret half %0
+}
+
+define noundef float @test_fmax_float(float noundef %a, float noundef %b) {
+entry:
+; CHECK: %[[#]] = OpExtInst %[[#]] %[[#]] FMax %[[#]] %[[#]]
+  %0 = call float @llvm.maxnum.f32(float %a, float %b)
+  ret float %0
+}
+
+define noundef double @test_fmax_double(double noundef %a, double noundef %b) {
+entry:
+; CHECK: %[[#]] = OpExtInst %[[#]] %[[#]] FMax %[[#]] %[[#]]
----------------
sudonatalie wrote:

FMax is undefined if one of the operands in NaN, so in DXC we use NMax to match HLSL max. It looks like that matches the LLVM instrinsic semantics, so I think this will be a straightforward SPIR-V backend change, but we do have to check that it doesn't break anything for the OpenCL side. Can you add a TODO to look into this and file an issue?

https://github.com/llvm/llvm-project/pull/86844


More information about the llvm-commits mailing list