Skip to content

[SPIR-V] Map llvm.{min,max}num to GL::N{Min,Max} #88009

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

Merged
merged 2 commits into from
Apr 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions llvm/lib/Target/SPIRV/SPIRVInstructionSelector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Copy link
Member

@farzonl farzonl Apr 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm a little suprised there were no other tests that needed to be updated than the ones I added.

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);
Expand Down
7 changes: 3 additions & 4 deletions llvm/test/CodeGen/SPIRV/hlsl-intrinsics/fmax.ll
Original file line number Diff line number Diff line change
@@ -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
}
Expand Down
7 changes: 3 additions & 4 deletions llvm/test/CodeGen/SPIRV/hlsl-intrinsics/fmin.ll
Original file line number Diff line number Diff line change
@@ -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
}
Expand Down