Skip to content

Commit 790ce0e

Browse files
authored
AMDGPU: Add minimumnum/maximumnum to list of canonicalizing opcodes (#139124)
This makes no difference in the test, as these always expand now.
1 parent ab6c4f5 commit 790ce0e

File tree

2 files changed

+65
-1
lines changed

2 files changed

+65
-1
lines changed

llvm/lib/Target/AMDGPU/SIISelLowering.cpp

+5-1
Original file line numberDiff line numberDiff line change
@@ -13151,6 +13151,8 @@ bool SITargetLowering::isCanonicalized(SelectionDAG &DAG, SDValue Op,
1315113151
case ISD::FMAXNUM_IEEE:
1315213152
case ISD::FMINIMUM:
1315313153
case ISD::FMAXIMUM:
13154+
case ISD::FMINIMUMNUM:
13155+
case ISD::FMAXIMUMNUM:
1315413156
case AMDGPUISD::CLAMP:
1315513157
case AMDGPUISD::FMED3:
1315613158
case AMDGPUISD::FMAX3:
@@ -13315,7 +13317,9 @@ bool SITargetLowering::isCanonicalized(Register Reg, const MachineFunction &MF,
1331513317
case AMDGPU::G_FMINNUM_IEEE:
1331613318
case AMDGPU::G_FMAXNUM_IEEE:
1331713319
case AMDGPU::G_FMINIMUM:
13318-
case AMDGPU::G_FMAXIMUM: {
13320+
case AMDGPU::G_FMAXIMUM:
13321+
case AMDGPU::G_FMINIMUMNUM:
13322+
case AMDGPU::G_FMAXIMUMNUM: {
1331913323
if (Subtarget->supportsMinMaxDenormModes() ||
1332013324
// FIXME: denormalsEnabledForType is broken for dynamic
1332113325
denormalsEnabledForType(MRI.getType(Reg), MF))

llvm/test/CodeGen/AMDGPU/fcanonicalize-elimination.ll

+60
Original file line numberDiff line numberDiff line change
@@ -855,6 +855,66 @@ define float @v_test_canonicalize_amdgcn_exp2(float %a) {
855855
ret float %canonicalized
856856
}
857857

858+
; GCN-LABEL: {{^}}v_test_canonicalize_minimum:
859+
; GCN: s_waitcnt
860+
; GCN-NEXT: v_min_f32_e32 [[MIN:v[0-9]+]], v0, v1
861+
; GCN-NEXT: v_mov_b32_e32 [[K:v[0-9]+]], 0x7fc00000
862+
; GCN-NEXT: v_cmp_o_f32_e32 vcc, v0, v1
863+
; GCN-NEXT: v_cndmask_b32_e32 v0, [[K]], [[MIN]], vcc
864+
; VI-FLUSH-NEXT: v_mul_f32_e32 v0, 1.0, v0
865+
; GCN-NEXT: s_setpc_b64
866+
define float @v_test_canonicalize_minimum(float %a, float %b) {
867+
%min = call float @llvm.minimum.f32(float %a, float %b)
868+
%canonicalized = call float @llvm.canonicalize.f32(float %min)
869+
ret float %canonicalized
870+
}
871+
872+
; GCN-LABEL: {{^}}v_test_canonicalize_maximum:
873+
; GCN: s_waitcnt
874+
; GCN-NEXT: v_max_f32_e32 [[MIN:v[0-9]+]], v0, v1
875+
; GCN-NEXT: v_mov_b32_e32 [[K:v[0-9]+]], 0x7fc00000
876+
; GCN-NEXT: v_cmp_o_f32_e32 vcc, v0, v1
877+
; GCN-NEXT: v_cndmask_b32_e32 v0, [[K]], [[MIN]], vcc
878+
; VI-FLUSH-NEXT: v_mul_f32_e32 v0, 1.0, v0
879+
; GCN-NEXT: s_setpc_b64
880+
define float @v_test_canonicalize_maximum(float %a, float %b) {
881+
%min = call float @llvm.maximum.f32(float %a, float %b)
882+
%canonicalized = call float @llvm.canonicalize.f32(float %min)
883+
ret float %canonicalized
884+
}
885+
886+
; GCN-LABEL: {{^}}v_test_canonicalize_minimumnum:
887+
; GCN: s_waitcnt
888+
; VI-NEXT: v_mul_f32_e32 v1, 1.0, v1
889+
; VI-NEXT: v_mul_f32_e32 v0, 1.0, v0
890+
891+
; GFX9-NEXT: v_max_f32_e32 v1, v1, v1
892+
; GFX9-NEXT: v_max_f32_e32 v0, v0, v0
893+
894+
; GCN-NEXT: v_min_f32_e32 v0, v0, v1
895+
; GCN-NEXT: s_setpc_b64
896+
define float @v_test_canonicalize_minimumnum(float %a, float %b) {
897+
%min = call float @llvm.minimumnum.f32(float %a, float %b)
898+
%canonicalized = call float @llvm.canonicalize.f32(float %min)
899+
ret float %canonicalized
900+
}
901+
902+
; GCN-LABEL: {{^}}v_test_canonicalize_maximumnum:
903+
; GCN: s_waitcnt
904+
; VI-NEXT: v_mul_f32_e32 v1, 1.0, v1
905+
; VI-NEXT: v_mul_f32_e32 v0, 1.0, v0
906+
907+
; GFX9-NEXT: v_max_f32_e32 v1, v1, v1
908+
; GFX9-NEXT: v_max_f32_e32 v0, v0, v0
909+
910+
; GCN-NEXT: v_max_f32_e32 v0, v0, v1
911+
; GCN-NEXT: s_setpc_b64
912+
define float @v_test_canonicalize_maximumnum(float %a, float %b) {
913+
%min = call float @llvm.maximumnum.f32(float %a, float %b)
914+
%canonicalized = call float @llvm.canonicalize.f32(float %min)
915+
ret float %canonicalized
916+
}
917+
858918
; Avoid failing the test on FreeBSD11.0 which will match the GCN-NOT: 1.0
859919
; in the .amd_amdgpu_isa "amdgcn-unknown-freebsd11.0--gfx802" directive
860920
; GCN: .amd_amdgpu_isa

0 commit comments

Comments
 (0)