[llvm] 1e44d9a - [SPIR-V] Map llvm.{min, max}num to GL::N{Min, Max} (#88009)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Apr 9 06:41:51 PDT 2024
Author: Natalie Chouinard
Date: 2024-04-09T09:41:47-04:00
New Revision: 1e44d9ac5e9d1ff8baa99fd5495477f3f2f1abe6
URL: https://github.com/llvm/llvm-project/commit/1e44d9ac5e9d1ff8baa99fd5495477f3f2f1abe6
DIFF: https://github.com/llvm/llvm-project/commit/1e44d9ac5e9d1ff8baa99fd5495477f3f2f1abe6.diff
LOG: [SPIR-V] Map llvm.{min,max}num to GL::N{Min,Max} (#88009)
SPIR-V intsruction selection was mapping the LLVM float min/max
intrinsics to FMin and FMax respectively for GL/Vulkan environments,
which does not match the intrinsics' documented treatment of NaN
operands. This patch switches the mapping to the correctly matched NMin
and NMax operations.
Fixes #87072
Added:
Modified:
llvm/lib/Target/SPIRV/SPIRVInstructionSelector.cpp
llvm/test/CodeGen/SPIRV/hlsl-intrinsics/fmax.ll
llvm/test/CodeGen/SPIRV/hlsl-intrinsics/fmin.ll
Removed:
################################################################################
diff --git a/llvm/lib/Target/SPIRV/SPIRVInstructionSelector.cpp b/llvm/lib/Target/SPIRV/SPIRVInstructionSelector.cpp
index 49749b56345306..45a70da7f86902 100644
--- a/llvm/lib/Target/SPIRV/SPIRVInstructionSelector.cpp
+++ b/llvm/lib/Target/SPIRV/SPIRVInstructionSelector.cpp
@@ -432,10 +432,10 @@ bool SPIRVInstructionSelector::spvSelect(Register ResVReg,
case TargetOpcode::G_FMINNUM:
case TargetOpcode::G_FMINIMUM:
- return selectExtInst(ResVReg, ResType, I, CL::fmin, GL::FMin);
+ return selectExtInst(ResVReg, ResType, I, CL::fmin, GL::NMin);
case TargetOpcode::G_FMAXNUM:
case TargetOpcode::G_FMAXIMUM:
- return selectExtInst(ResVReg, ResType, I, CL::fmax, GL::FMax);
+ return selectExtInst(ResVReg, ResType, I, CL::fmax, GL::NMax);
case TargetOpcode::G_FCOPYSIGN:
return selectExtInst(ResVReg, ResType, I, CL::copysign);
diff --git a/llvm/test/CodeGen/SPIRV/hlsl-intrinsics/fmax.ll b/llvm/test/CodeGen/SPIRV/hlsl-intrinsics/fmax.ll
index 48e916581f9ff2..159d4ac19c8cc8 100644
--- a/llvm/test/CodeGen/SPIRV/hlsl-intrinsics/fmax.ll
+++ b/llvm/test/CodeGen/SPIRV/hlsl-intrinsics/fmax.ll
@@ -1,25 +1,24 @@
; 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 %}
-; TODO: This need to be NMax: See https://github.com/llvm/llvm-project/issues/87072
; CHECK: OpExtInstImport "GLSL.std.450"
define noundef half @test_fmax_half(half noundef %a, half noundef %b) {
entry:
-; CHECK: %[[#]] = OpExtInst %[[#]] %[[#]] FMax %[[#]] %[[#]]
+; CHECK: %[[#]] = OpExtInst %[[#]] %[[#]] NMax %[[#]] %[[#]]
%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 %[[#]] %[[#]]
+; CHECK: %[[#]] = OpExtInst %[[#]] %[[#]] NMax %[[#]] %[[#]]
%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 %[[#]] %[[#]]
+; CHECK: %[[#]] = OpExtInst %[[#]] %[[#]] NMax %[[#]] %[[#]]
%0 = call double @llvm.maxnum.f64(double %a, double %b)
ret double %0
}
diff --git a/llvm/test/CodeGen/SPIRV/hlsl-intrinsics/fmin.ll b/llvm/test/CodeGen/SPIRV/hlsl-intrinsics/fmin.ll
index 5bfd69c972a3fa..15946b5038eec3 100644
--- a/llvm/test/CodeGen/SPIRV/hlsl-intrinsics/fmin.ll
+++ b/llvm/test/CodeGen/SPIRV/hlsl-intrinsics/fmin.ll
@@ -1,27 +1,26 @@
; 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 %}
-; TODO: This need to be NMin: See https://github.com/llvm/llvm-project/issues/87072
; CHECK: OpExtInstImport "GLSL.std.450"
; CHECK: OpMemoryModel Logical GLSL450
define noundef half @test_fmax_half(half noundef %a, half noundef %b) {
entry:
-; CHECK: %[[#]] = OpExtInst %[[#]] %[[#]] FMin %[[#]] %[[#]]
+; CHECK: %[[#]] = OpExtInst %[[#]] %[[#]] NMin %[[#]] %[[#]]
%0 = call half @llvm.minnum.f16(half %a, half %b)
ret half %0
}
define noundef float @test_fmax_float(float noundef %a, float noundef %b) {
entry:
-; CHECK: %[[#]] = OpExtInst %[[#]] %[[#]] FMin %[[#]] %[[#]]
+; CHECK: %[[#]] = OpExtInst %[[#]] %[[#]] NMin %[[#]] %[[#]]
%0 = call float @llvm.minnum.f32(float %a, float %b)
ret float %0
}
define noundef double @test_fmax_double(double noundef %a, double noundef %b) {
entry:
-; CHECK: %[[#]] = OpExtInst %[[#]] %[[#]] FMin %[[#]] %[[#]]
+; CHECK: %[[#]] = OpExtInst %[[#]] %[[#]] NMin %[[#]] %[[#]]
%0 = call double @llvm.minnum.f64(double %a, double %b)
ret double %0
}
More information about the llvm-commits
mailing list