[llvm] AMDGPU/GlobalISel: Regbanklegalize rules for G_FMIN*/MAX* (PR #179778)

via llvm-commits llvm-commits at lists.llvm.org
Wed Feb 4 12:55:08 PST 2026


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-globalisel

@llvm/pr-subscribers-backend-amdgpu

Author: None (vangthao95)

<details>
<summary>Changes</summary>



---

Patch is 114.55 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/179778.diff


17 Files Affected:

- (modified) llvm/lib/Target/AMDGPU/AMDGPURegBankLegalizeRules.cpp (+14) 
- (modified) llvm/test/CodeGen/AMDGPU/GlobalISel/clamp-fmed3-const-combine.ll (+2-2) 
- (modified) llvm/test/CodeGen/AMDGPU/GlobalISel/clamp-minmax-const-combine.ll (+2-2) 
- (modified) llvm/test/CodeGen/AMDGPU/GlobalISel/fmed3-min-max-const-combine.ll (+3-3) 
- (modified) llvm/test/CodeGen/AMDGPU/fmaximum.ll (+448-174) 
- (modified) llvm/test/CodeGen/AMDGPU/fmed3-cast-combine.ll (+3-3) 
- (modified) llvm/test/CodeGen/AMDGPU/fmed3.ll (+5-5) 
- (modified) llvm/test/CodeGen/AMDGPU/fminimum.ll (+448-174) 
- (modified) llvm/test/CodeGen/AMDGPU/fneg-combines-gfx1200.ll (+1-1) 
- (modified) llvm/test/CodeGen/AMDGPU/mad-mix-hi.ll (+24-13) 
- (modified) llvm/test/CodeGen/AMDGPU/mad-mix-lo.ll (+40-24) 
- (modified) llvm/test/CodeGen/AMDGPU/mad-mix.ll (+7-7) 
- (modified) llvm/test/CodeGen/AMDGPU/minimummaximum.ll (+2-2) 
- (modified) llvm/test/CodeGen/AMDGPU/minmax.ll (+6-6) 
- (modified) llvm/test/CodeGen/AMDGPU/vector-reduce-fmax.ll (+8-8) 
- (modified) llvm/test/CodeGen/AMDGPU/vector-reduce-fmin.ll (+8-8) 
- (modified) llvm/test/CodeGen/AMDGPU/vector-reduce-fminimum.ll (+2-2) 


``````````diff
diff --git a/llvm/lib/Target/AMDGPU/AMDGPURegBankLegalizeRules.cpp b/llvm/lib/Target/AMDGPU/AMDGPURegBankLegalizeRules.cpp
index 20c7457eb7f43..cfe653428228f 100644
--- a/llvm/lib/Target/AMDGPU/AMDGPURegBankLegalizeRules.cpp
+++ b/llvm/lib/Target/AMDGPU/AMDGPURegBankLegalizeRules.cpp
@@ -1229,6 +1229,20 @@ RegBankLegalizeRules::RegBankLegalizeRules(const GCNSubtarget &_ST,
       .Uni(S32, {{UniInVgprS32}, {Vgpr32, Vgpr32}})
       .Div(S32, {{Vgpr32}, {Vgpr32, Vgpr32}});
 
+  addRulesForGOpcs({G_FMINIMUM, G_FMAXIMUM, G_FMINNUM_IEEE, G_FMAXNUM_IEEE,
+                    G_FMINNUM, G_FMAXNUM},
+                   Standard)
+      .Div(S16, {{Vgpr16}, {Vgpr16, Vgpr16}})
+      .Div(S32, {{Vgpr32}, {Vgpr32, Vgpr32}})
+      .Uni(S64, {{UniInVgprS64}, {Vgpr64, Vgpr64}})
+      .Div(S64, {{Vgpr64}, {Vgpr64, Vgpr64}})
+      .Uni(V2S16, {{UniInVgprV2S16}, {VgprV2S16, VgprV2S16}})
+      .Div(V2S16, {{VgprV2S16}, {VgprV2S16, VgprV2S16}})
+      .Uni(S16, {{Sgpr16}, {Sgpr16, Sgpr16}}, hasSALUFloat)
+      .Uni(S16, {{UniInVgprS16}, {Vgpr16, Vgpr16}}, !hasSALUFloat)
+      .Uni(S32, {{Sgpr32}, {Sgpr32, Sgpr32}}, hasSALUFloat)
+      .Uni(S32, {{UniInVgprS32}, {Vgpr32, Vgpr32}}, !hasSALUFloat);
+
   addRulesForGOpcs({G_FPTRUNC})
       .Any({{DivS16, S32}, {{Vgpr16}, {Vgpr32}}})
       .Any({{UniS32, S64}, {{UniInVgprS32}, {Vgpr64}}})
diff --git a/llvm/test/CodeGen/AMDGPU/GlobalISel/clamp-fmed3-const-combine.ll b/llvm/test/CodeGen/AMDGPU/GlobalISel/clamp-fmed3-const-combine.ll
index bdf54457b7159..23f5ae4f59005 100644
--- a/llvm/test/CodeGen/AMDGPU/GlobalISel/clamp-fmed3-const-combine.ll
+++ b/llvm/test/CodeGen/AMDGPU/GlobalISel/clamp-fmed3-const-combine.ll
@@ -1,6 +1,6 @@
 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
-; RUN: llc -global-isel -mtriple=amdgcn-amd-mesa3d -mcpu=gfx1010 < %s | FileCheck -check-prefix=GFX10 %s
-; RUN: llc -global-isel -mtriple=amdgcn-amd-mesa3d -mcpu=gfx1200 -mattr=-real-true16 < %s | FileCheck -check-prefix=GFX12 %s
+; RUN: llc -global-isel -new-reg-bank-select -mtriple=amdgcn-amd-mesa3d -mcpu=gfx1010 < %s | FileCheck -check-prefix=GFX10 %s
+; RUN: llc -global-isel -new-reg-bank-select -mtriple=amdgcn-amd-mesa3d -mcpu=gfx1200 -mattr=-real-true16 < %s | FileCheck -check-prefix=GFX12 %s
 
 define float @test_fmed3_f32_known_nnan_ieee_true(float %a) #0 {
 ; GFX10-LABEL: test_fmed3_f32_known_nnan_ieee_true:
diff --git a/llvm/test/CodeGen/AMDGPU/GlobalISel/clamp-minmax-const-combine.ll b/llvm/test/CodeGen/AMDGPU/GlobalISel/clamp-minmax-const-combine.ll
index 8705647e36fe1..0315bd86feeda 100644
--- a/llvm/test/CodeGen/AMDGPU/GlobalISel/clamp-minmax-const-combine.ll
+++ b/llvm/test/CodeGen/AMDGPU/GlobalISel/clamp-minmax-const-combine.ll
@@ -1,6 +1,6 @@
 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
-; RUN: llc -global-isel -mtriple=amdgcn-amd-mesa3d -mcpu=gfx1010 < %s | FileCheck -check-prefix=GFX10 %s
-; RUN: llc -global-isel -mtriple=amdgcn-amd-mesa3d -mcpu=gfx1200 -mattr=-real-true16 < %s | FileCheck -check-prefix=GFX12 %s
+; RUN: llc -global-isel -new-reg-bank-select -mtriple=amdgcn-amd-mesa3d -mcpu=gfx1010 < %s | FileCheck -check-prefix=GFX10 %s
+; RUN: llc -global-isel -new-reg-bank-select -mtriple=amdgcn-amd-mesa3d -mcpu=gfx1200 -mattr=-real-true16 < %s | FileCheck -check-prefix=GFX12 %s
 
 define float @test_min_max_ValK0_K1_f32(float %a) #0 {
 ; GFX10-LABEL: test_min_max_ValK0_K1_f32:
diff --git a/llvm/test/CodeGen/AMDGPU/GlobalISel/fmed3-min-max-const-combine.ll b/llvm/test/CodeGen/AMDGPU/GlobalISel/fmed3-min-max-const-combine.ll
index 696a87b9d0b4d..b754bb6081c31 100644
--- a/llvm/test/CodeGen/AMDGPU/GlobalISel/fmed3-min-max-const-combine.ll
+++ b/llvm/test/CodeGen/AMDGPU/GlobalISel/fmed3-min-max-const-combine.ll
@@ -1,7 +1,7 @@
 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
-; RUN: llc -global-isel -mtriple=amdgcn-amd-mesa3d -mcpu=gfx1010 < %s | FileCheck -check-prefix=GFX10 %s
-; RUN: llc -global-isel -mtriple=amdgcn-amd-mesa3d -mcpu=gfx803 < %s | FileCheck -check-prefix=GFX8 %s
-; RUN: llc -global-isel -mtriple=amdgcn-amd-mesa3d -mcpu=gfx1200 -mattr=-real-true16 < %s | FileCheck -check-prefix=GFX12 %s
+; RUN: llc -global-isel -new-reg-bank-select -mtriple=amdgcn-amd-mesa3d -mcpu=gfx1010 < %s | FileCheck -check-prefix=GFX10 %s
+; RUN: llc -global-isel -new-reg-bank-select -mtriple=amdgcn-amd-mesa3d -mcpu=gfx803 < %s | FileCheck -check-prefix=GFX8 %s
+; RUN: llc -global-isel -new-reg-bank-select -mtriple=amdgcn-amd-mesa3d -mcpu=gfx1200 -mattr=-real-true16 < %s | FileCheck -check-prefix=GFX12 %s
 
 define float @test_min_max_ValK0_K1_f32(float %a) #0 {
 ; GFX10-LABEL: test_min_max_ValK0_K1_f32:
diff --git a/llvm/test/CodeGen/AMDGPU/fmaximum.ll b/llvm/test/CodeGen/AMDGPU/fmaximum.ll
index 0283b5ff5d439..b264bf93d289b 100644
--- a/llvm/test/CodeGen/AMDGPU/fmaximum.ll
+++ b/llvm/test/CodeGen/AMDGPU/fmaximum.ll
@@ -1,10 +1,10 @@
 ; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py
 ; RUN: llc -global-isel=0 -mtriple=amdgcn -mcpu=gfx900 < %s | FileCheck -enable-var-scope -check-prefixes=GFX9,GFX9-SDAG %s
-; RUN: llc -global-isel=1 -mtriple=amdgcn -mcpu=gfx900 < %s | FileCheck -enable-var-scope -check-prefixes=GFX9,GFX9-GISEL %s
+; RUN: llc -global-isel=1 -new-reg-bank-select -mtriple=amdgcn -mcpu=gfx900 < %s | FileCheck -enable-var-scope -check-prefixes=GFX9,GFX9-GISEL %s
 ; RUN: llc -global-isel=0 -mtriple=amdgcn -mcpu=gfx1200 -mattr=+real-true16 < %s | FileCheck -enable-var-scope -check-prefixes=GFX12,GFX12-SDAG,GFX12-SDAG-TRUE16 %s
 ; RUN: llc -global-isel=0 -mtriple=amdgcn -mcpu=gfx1200 -mattr=-real-true16 < %s | FileCheck -enable-var-scope -check-prefixes=GFX12,GFX12-SDAG,GFX12-SDAG-FAKE16 %s
-; RUN: llc -global-isel=1 -mtriple=amdgcn -mcpu=gfx1200 -mattr=+real-true16 < %s | FileCheck -enable-var-scope -check-prefixes=GFX12,GFX12-GISEL,GFX12-GISEL-TRUE16 %s
-; RUN: llc -global-isel=1 -mtriple=amdgcn -mcpu=gfx1200 -mattr=-real-true16 < %s | FileCheck -enable-var-scope -check-prefixes=GFX12,GFX12-GISEL,GFX12-GISEL-FAKE16 %s
+; RUN: llc -global-isel=1 -new-reg-bank-select -mtriple=amdgcn -mcpu=gfx1200 -mattr=+real-true16 < %s | FileCheck -enable-var-scope -check-prefixes=GFX12,GFX12-GISEL,GFX12-GISEL-TRUE16 %s
+; RUN: llc -global-isel=1 -new-reg-bank-select -mtriple=amdgcn -mcpu=gfx1200 -mattr=-real-true16 < %s | FileCheck -enable-var-scope -check-prefixes=GFX12,GFX12-GISEL,GFX12-GISEL-FAKE16 %s
 
 define amdgpu_ps float @test_fmaximum_f32_vv(float %a, float %b) {
 ; GFX9-LABEL: test_fmaximum_f32_vv:
@@ -24,14 +24,28 @@ define amdgpu_ps float @test_fmaximum_f32_vv(float %a, float %b) {
 }
 
 define amdgpu_ps float @test_fmaximum_f32_ss(float inreg %a, float inreg %b) {
-; GFX9-LABEL: test_fmaximum_f32_ss:
-; GFX9:       ; %bb.0:
-; GFX9-NEXT:    v_mov_b32_e32 v0, s1
-; GFX9-NEXT:    v_max_f32_e32 v1, s0, v0
-; GFX9-NEXT:    v_mov_b32_e32 v2, 0x7fc00000
-; GFX9-NEXT:    v_cmp_o_f32_e32 vcc, s0, v0
-; GFX9-NEXT:    v_cndmask_b32_e32 v0, v2, v1, vcc
-; GFX9-NEXT:    ; return to shader part epilog
+; GFX9-SDAG-LABEL: test_fmaximum_f32_ss:
+; GFX9-SDAG:       ; %bb.0:
+; GFX9-SDAG-NEXT:    v_mov_b32_e32 v0, s1
+; GFX9-SDAG-NEXT:    v_max_f32_e32 v1, s0, v0
+; GFX9-SDAG-NEXT:    v_mov_b32_e32 v2, 0x7fc00000
+; GFX9-SDAG-NEXT:    v_cmp_o_f32_e32 vcc, s0, v0
+; GFX9-SDAG-NEXT:    v_cndmask_b32_e32 v0, v2, v1, vcc
+; GFX9-SDAG-NEXT:    ; return to shader part epilog
+;
+; GFX9-GISEL-LABEL: test_fmaximum_f32_ss:
+; GFX9-GISEL:       ; %bb.0:
+; GFX9-GISEL-NEXT:    v_mov_b32_e32 v0, s1
+; GFX9-GISEL-NEXT:    v_cmp_o_f32_e32 vcc, s0, v0
+; GFX9-GISEL-NEXT:    s_cmp_lg_u64 vcc, 0
+; GFX9-GISEL-NEXT:    v_max_f32_e32 v1, s0, v0
+; GFX9-GISEL-NEXT:    s_cselect_b32 s0, 1, 0
+; GFX9-GISEL-NEXT:    s_and_b32 s0, s0, 1
+; GFX9-GISEL-NEXT:    v_readfirstlane_b32 s1, v1
+; GFX9-GISEL-NEXT:    s_cmp_lg_u32 s0, 0
+; GFX9-GISEL-NEXT:    s_cselect_b32 s0, s1, 0x7fc00000
+; GFX9-GISEL-NEXT:    v_mov_b32_e32 v0, s0
+; GFX9-GISEL-NEXT:    ; return to shader part epilog
 ;
 ; GFX12-LABEL: test_fmaximum_f32_ss:
 ; GFX12:       ; %bb.0:
@@ -127,18 +141,42 @@ define amdgpu_ps <2 x float> @test_fmaximum_v2f32(<2 x float> %a, <2 x float> %b
 }
 
 define amdgpu_ps <2 x float> @test_fmaximum_v2f32_ss(<2 x float> inreg %a, <2 x float> inreg %b) {
-; GFX9-LABEL: test_fmaximum_v2f32_ss:
-; GFX9:       ; %bb.0:
-; GFX9-NEXT:    v_mov_b32_e32 v0, s2
-; GFX9-NEXT:    v_max_f32_e32 v1, s0, v0
-; GFX9-NEXT:    v_mov_b32_e32 v2, 0x7fc00000
-; GFX9-NEXT:    v_cmp_o_f32_e32 vcc, s0, v0
-; GFX9-NEXT:    v_cndmask_b32_e32 v0, v2, v1, vcc
-; GFX9-NEXT:    v_mov_b32_e32 v1, s3
-; GFX9-NEXT:    v_max_f32_e32 v3, s1, v1
-; GFX9-NEXT:    v_cmp_o_f32_e32 vcc, s1, v1
-; GFX9-NEXT:    v_cndmask_b32_e32 v1, v2, v3, vcc
-; GFX9-NEXT:    ; return to shader part epilog
+; GFX9-SDAG-LABEL: test_fmaximum_v2f32_ss:
+; GFX9-SDAG:       ; %bb.0:
+; GFX9-SDAG-NEXT:    v_mov_b32_e32 v0, s2
+; GFX9-SDAG-NEXT:    v_max_f32_e32 v1, s0, v0
+; GFX9-SDAG-NEXT:    v_mov_b32_e32 v2, 0x7fc00000
+; GFX9-SDAG-NEXT:    v_cmp_o_f32_e32 vcc, s0, v0
+; GFX9-SDAG-NEXT:    v_cndmask_b32_e32 v0, v2, v1, vcc
+; GFX9-SDAG-NEXT:    v_mov_b32_e32 v1, s3
+; GFX9-SDAG-NEXT:    v_max_f32_e32 v3, s1, v1
+; GFX9-SDAG-NEXT:    v_cmp_o_f32_e32 vcc, s1, v1
+; GFX9-SDAG-NEXT:    v_cndmask_b32_e32 v1, v2, v3, vcc
+; GFX9-SDAG-NEXT:    ; return to shader part epilog
+;
+; GFX9-GISEL-LABEL: test_fmaximum_v2f32_ss:
+; GFX9-GISEL:       ; %bb.0:
+; GFX9-GISEL-NEXT:    v_mov_b32_e32 v0, s2
+; GFX9-GISEL-NEXT:    v_cmp_o_f32_e32 vcc, s0, v0
+; GFX9-GISEL-NEXT:    s_cmp_lg_u64 vcc, 0
+; GFX9-GISEL-NEXT:    v_max_f32_e32 v1, s0, v0
+; GFX9-GISEL-NEXT:    s_cselect_b32 s0, 1, 0
+; GFX9-GISEL-NEXT:    s_and_b32 s0, s0, 1
+; GFX9-GISEL-NEXT:    v_mov_b32_e32 v0, s3
+; GFX9-GISEL-NEXT:    v_readfirstlane_b32 s2, v1
+; GFX9-GISEL-NEXT:    s_cmp_lg_u32 s0, 0
+; GFX9-GISEL-NEXT:    v_cmp_o_f32_e32 vcc, s1, v0
+; GFX9-GISEL-NEXT:    s_cselect_b32 s0, s2, 0x7fc00000
+; GFX9-GISEL-NEXT:    s_cmp_lg_u64 vcc, 0
+; GFX9-GISEL-NEXT:    v_max_f32_e32 v1, s1, v0
+; GFX9-GISEL-NEXT:    s_cselect_b32 s1, 1, 0
+; GFX9-GISEL-NEXT:    s_and_b32 s1, s1, 1
+; GFX9-GISEL-NEXT:    v_readfirstlane_b32 s2, v1
+; GFX9-GISEL-NEXT:    s_cmp_lg_u32 s1, 0
+; GFX9-GISEL-NEXT:    s_cselect_b32 s1, s2, 0x7fc00000
+; GFX9-GISEL-NEXT:    v_mov_b32_e32 v0, s0
+; GFX9-GISEL-NEXT:    v_mov_b32_e32 v1, s1
+; GFX9-GISEL-NEXT:    ; return to shader part epilog
 ;
 ; GFX12-LABEL: test_fmaximum_v2f32_ss:
 ; GFX12:       ; %bb.0:
@@ -315,14 +353,28 @@ define amdgpu_ps half @test_fmaximum_f16_vv(half %a, half %b) {
 }
 
 define amdgpu_ps half @test_fmaximum_f16_ss(half inreg %a, half inreg %b) {
-; GFX9-LABEL: test_fmaximum_f16_ss:
-; GFX9:       ; %bb.0:
-; GFX9-NEXT:    v_mov_b32_e32 v0, s1
-; GFX9-NEXT:    v_max_f16_e32 v1, s0, v0
-; GFX9-NEXT:    v_mov_b32_e32 v2, 0x7e00
-; GFX9-NEXT:    v_cmp_o_f16_e32 vcc, s0, v0
-; GFX9-NEXT:    v_cndmask_b32_e32 v0, v2, v1, vcc
-; GFX9-NEXT:    ; return to shader part epilog
+; GFX9-SDAG-LABEL: test_fmaximum_f16_ss:
+; GFX9-SDAG:       ; %bb.0:
+; GFX9-SDAG-NEXT:    v_mov_b32_e32 v0, s1
+; GFX9-SDAG-NEXT:    v_max_f16_e32 v1, s0, v0
+; GFX9-SDAG-NEXT:    v_mov_b32_e32 v2, 0x7e00
+; GFX9-SDAG-NEXT:    v_cmp_o_f16_e32 vcc, s0, v0
+; GFX9-SDAG-NEXT:    v_cndmask_b32_e32 v0, v2, v1, vcc
+; GFX9-SDAG-NEXT:    ; return to shader part epilog
+;
+; GFX9-GISEL-LABEL: test_fmaximum_f16_ss:
+; GFX9-GISEL:       ; %bb.0:
+; GFX9-GISEL-NEXT:    v_mov_b32_e32 v0, s1
+; GFX9-GISEL-NEXT:    v_cmp_o_f16_e32 vcc, s0, v0
+; GFX9-GISEL-NEXT:    s_cmp_lg_u64 vcc, 0
+; GFX9-GISEL-NEXT:    v_max_f16_e32 v1, s0, v0
+; GFX9-GISEL-NEXT:    s_cselect_b32 s0, 1, 0
+; GFX9-GISEL-NEXT:    s_and_b32 s0, s0, 1
+; GFX9-GISEL-NEXT:    v_readfirstlane_b32 s1, v1
+; GFX9-GISEL-NEXT:    s_cmp_lg_u32 s0, 0
+; GFX9-GISEL-NEXT:    s_cselect_b32 s0, s1, 0x7e00
+; GFX9-GISEL-NEXT:    v_mov_b32_e32 v0, s0
+; GFX9-GISEL-NEXT:    ; return to shader part epilog
 ;
 ; GFX12-LABEL: test_fmaximum_f16_ss:
 ; GFX12:       ; %bb.0:
@@ -389,16 +441,25 @@ define amdgpu_ps <2 x half> @test_fmaximum_v2f16_ss(<2 x half> inreg %a, <2 x ha
 ; GFX9-GISEL:       ; %bb.0:
 ; GFX9-GISEL-NEXT:    v_mov_b32_e32 v0, s1
 ; GFX9-GISEL-NEXT:    s_lshr_b32 s1, s1, 16
-; GFX9-GISEL-NEXT:    s_lshr_b32 s2, s0, 16
-; GFX9-GISEL-NEXT:    v_mov_b32_e32 v2, s1
 ; GFX9-GISEL-NEXT:    v_pk_max_f16 v1, s0, v0
-; GFX9-GISEL-NEXT:    v_cmp_o_f16_e32 vcc, s2, v2
-; GFX9-GISEL-NEXT:    v_mov_b32_e32 v2, 0x7e00
-; GFX9-GISEL-NEXT:    v_cmp_o_f16_e64 s[0:1], s0, v0
-; GFX9-GISEL-NEXT:    v_cndmask_b32_e64 v0, v2, v1, s[0:1]
-; GFX9-GISEL-NEXT:    v_cndmask_b32_sdwa v1, v2, v1, vcc dst_sel:DWORD dst_unused:UNUSED_PAD src0_sel:DWORD src1_sel:WORD_1
-; GFX9-GISEL-NEXT:    v_and_b32_e32 v0, 0xffff, v0
-; GFX9-GISEL-NEXT:    v_lshl_or_b32 v0, v1, 16, v0
+; GFX9-GISEL-NEXT:    s_lshr_b32 s3, s0, 16
+; GFX9-GISEL-NEXT:    v_cmp_o_f16_e32 vcc, s0, v0
+; GFX9-GISEL-NEXT:    v_mov_b32_e32 v0, s1
+; GFX9-GISEL-NEXT:    s_cmp_lg_u64 vcc, 0
+; GFX9-GISEL-NEXT:    v_cmp_o_f16_e32 vcc, s3, v0
+; GFX9-GISEL-NEXT:    v_readfirstlane_b32 s2, v1
+; GFX9-GISEL-NEXT:    s_cselect_b32 s0, 1, 0
+; GFX9-GISEL-NEXT:    s_cmp_lg_u64 vcc, 0
+; GFX9-GISEL-NEXT:    s_cselect_b32 s1, 1, 0
+; GFX9-GISEL-NEXT:    s_lshr_b32 s3, s2, 16
+; GFX9-GISEL-NEXT:    s_and_b32 s0, s0, 1
+; GFX9-GISEL-NEXT:    s_cmp_lg_u32 s0, 0
+; GFX9-GISEL-NEXT:    s_cselect_b32 s0, s2, 0x7e00
+; GFX9-GISEL-NEXT:    s_and_b32 s1, s1, 1
+; GFX9-GISEL-NEXT:    s_cmp_lg_u32 s1, 0
+; GFX9-GISEL-NEXT:    s_cselect_b32 s1, s3, 0x7e00
+; GFX9-GISEL-NEXT:    s_pack_ll_b32_b16 s0, s0, s1
+; GFX9-GISEL-NEXT:    v_mov_b32_e32 v0, s0
 ; GFX9-GISEL-NEXT:    ; return to shader part epilog
 ;
 ; GFX12-LABEL: test_fmaximum_v2f16_ss:
@@ -428,16 +489,19 @@ define amdgpu_ps <3 x half> @test_fmaximum_v3f16_vv(<3 x half> %a, <3 x half> %b
 ; GFX9-GISEL-LABEL: test_fmaximum_v3f16_vv:
 ; GFX9-GISEL:       ; %bb.0:
 ; GFX9-GISEL-NEXT:    v_pk_max_f16 v4, v0, v2
-; GFX9-GISEL-NEXT:    v_mov_b32_e32 v5, 0x7e00
-; GFX9-GISEL-NEXT:    v_cmp_o_f16_e64 s[0:1], v0, v2
+; GFX9-GISEL-NEXT:    v_mov_b32_e32 v6, 0x7e00
+; GFX9-GISEL-NEXT:    v_cmp_o_f16_e32 vcc, v0, v2
+; GFX9-GISEL-NEXT:    v_lshrrev_b32_e32 v5, 16, v4
+; GFX9-GISEL-NEXT:    v_cndmask_b32_e32 v4, v6, v4, vcc
 ; GFX9-GISEL-NEXT:    v_cmp_o_f16_sdwa vcc, v0, v2 src0_sel:WORD_1 src1_sel:WORD_1
-; GFX9-GISEL-NEXT:    v_cndmask_b32_e64 v0, v5, v4, s[0:1]
-; GFX9-GISEL-NEXT:    v_cndmask_b32_sdwa v2, v5, v4, vcc dst_sel:DWORD dst_unused:UNUSED_PAD src0_sel:DWORD src1_sel:WORD_1
-; GFX9-GISEL-NEXT:    v_pk_max_f16 v4, v1, v3
+; GFX9-GISEL-NEXT:    v_cndmask_b32_e32 v0, v6, v5, vcc
+; GFX9-GISEL-NEXT:    v_pk_max_f16 v2, v1, v3
 ; GFX9-GISEL-NEXT:    v_cmp_o_f16_e32 vcc, v1, v3
-; GFX9-GISEL-NEXT:    v_and_b32_e32 v0, 0xffff, v0
-; GFX9-GISEL-NEXT:    v_cndmask_b32_e32 v1, v5, v4, vcc
-; GFX9-GISEL-NEXT:    v_lshl_or_b32 v0, v2, 16, v0
+; GFX9-GISEL-NEXT:    v_cndmask_b32_e32 v1, v6, v2, vcc
+; GFX9-GISEL-NEXT:    v_and_b32_e32 v2, 0xffff, v4
+; GFX9-GISEL-NEXT:    v_and_b32_e32 v1, 0xffff, v1
+; GFX9-GISEL-NEXT:    v_lshl_or_b32 v0, v0, 16, v2
+; GFX9-GISEL-NEXT:    v_lshl_or_b32 v1, s0, 16, v1
 ; GFX9-GISEL-NEXT:    ; return to shader part epilog
 ;
 ; GFX12-SDAG-LABEL: test_fmaximum_v3f16_vv:
@@ -454,8 +518,11 @@ define amdgpu_ps <3 x half> @test_fmaximum_v3f16_vv(<3 x half> %a, <3 x half> %b
 ;
 ; GFX12-GISEL-FAKE16-LABEL: test_fmaximum_v3f16_vv:
 ; GFX12-GISEL-FAKE16:       ; %bb.0:
-; GFX12-GISEL-FAKE16-NEXT:    v_pk_maximum_f16 v0, v0, v2
 ; GFX12-GISEL-FAKE16-NEXT:    v_maximum_f16 v1, v1, v3
+; GFX12-GISEL-FAKE16-NEXT:    v_pk_maximum_f16 v0, v0, v2
+; GFX12-GISEL-FAKE16-NEXT:    s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_1)
+; GFX12-GISEL-FAKE16-NEXT:    v_and_b32_e32 v1, 0xffff, v1
+; GFX12-GISEL-FAKE16-NEXT:    v_lshl_or_b32 v1, s0, 16, v1
 ; GFX12-GISEL-FAKE16-NEXT:    ; return to shader part epilog
   %val = call <3 x half> @llvm.maximum.v3f16(<3 x half> %a, <3 x half> %b)
   ret <3 x half> %val
@@ -490,19 +557,33 @@ define amdgpu_ps <3 x half> @test_fmaximum_v3f16_ss(<3 x half> inreg %a, <3 x ha
 ; GFX9-GISEL-NEXT:    v_mov_b32_e32 v0, s2
 ; GFX9-GISEL-NEXT:    s_lshr_b32 s4, s0, 16
 ; GFX9-GISEL-NEXT:    v_pk_max_f16 v1, s0, v0
-; GFX9-GISEL-NEXT:    v_mov_b32_e32 v2, s5
-; GFX9-GISEL-NEXT:    v_mov_b32_e32 v4, 0x7e00
 ; GFX9-GISEL-NEXT:    v_cmp_o_f16_e32 vcc, s0, v0
-; GFX9-GISEL-NEXT:    v_lshrrev_b32_e32 v3, 16, v1
-; GFX9-GISEL-NEXT:    v_cndmask_b32_e32 v0, v4, v1, vcc
-; GFX9-GISEL-NEXT:    v_cmp_o_f16_e32 vcc, s4, v2
-; GFX9-GISEL-NEXT:    v_mov_b32_e32 v1, s3
-; GFX9-GISEL-NEXT:    v_cndmask_b32_e32 v2, v4, v3, vcc
-; GFX9-GISEL-NEXT:    v_pk_max_f16 v3, s1, v1
-; GFX9-GISEL-NEXT:    v_cmp_o_f16_e32 vcc, s1, v1
-; GFX9-GISEL-NEXT:    v_and_b32_e32 v0, 0xffff, v0
-; GFX9-GISEL-NEXT:    v_cndmask_b32_e32 v1, v4, v3, vcc
-; GFX9-GISEL-NEXT:    v_lshl_or_b32 v0, v2, 16, v0
+; GFX9-GISEL-NEXT:    v_mov_b32_e32 v0, s5
+; GFX9-GISEL-NEXT:    s_cmp_lg_u64 vcc, 0
+; GFX9-GISEL-NEXT:    v_cmp_o_f16_e32 vcc, s4, v0
+; GFX9-GISEL-NEXT:    v_readfirstlane_b32 s2, v1
+; GFX9-GISEL-NEXT:    s_cselect_b32 s0, 1, 0
+; GFX9-GISEL-NEXT:    s_cmp_lg_u64 vcc, 0
+; GFX9-GISEL-NEXT:    s_cselect_b32 s4, 1, 0
+; GFX9-GISEL-NEXT:    s_lshr_b32 s5, s2, 16
+; GFX9-GISEL-NEXT:    s_and_b32 s0, s0, 1
+; GFX9-GISEL-NEXT:    s_cmp_lg_u32 s0, 0
+; GFX9-GISEL-NEXT:    s_cselect_b32 s0, s2, 0x7e00
+; GFX9-GISEL-NEXT:    s_and_b32 s2, s4, 1
+; GFX9-GISEL-NEXT:    v_mov_b32_e32 v0, s3
+; GFX9-GISEL-NEXT:    s_cmp_lg_u32 s2, 0
+; GFX9-GISEL-NEXT:    v_cmp_o_f16_e32 vcc, s1, v0
+; GFX9-GISEL-NEXT:    s_cselect_b32 s2, s5, 0x7e00
+; GFX9-GISEL-NEXT:    s_cmp_lg_u64 vcc, 0
+; GFX9-GISEL-NEXT:    v_pk_max_f16 v1, s1, v0
+; GFX9-GISEL-NEXT:    s_cselect_b32 s1, 1, 0
+; GFX9-GISEL-NEXT:    s_and_b32 s1, s1, 1
+; GFX9-GISEL-NEXT:    v_readfirstlane_b32 s3, v1
+; GFX9-GISEL-NEXT:    s_cmp_lg_u32 s1, 0
+; GFX9-GISEL-NEXT:    s_cselect_b32 s1, s3, 0x7e00
+; GFX9-GISEL-NEXT:    s_pack_ll_b32_b16 s0, s0, s2
+; GFX9-GISEL-NEXT:    v_mov_b32_e32 v0, s0
+; GFX9-GISEL-NEXT:    v_mov_b32_e32 v1, s1
 ; GFX9-GISEL-NEXT:    ; return to shader part epilog
 ;
 ; GFX12-SDAG-LABEL: test_fmaximum_v3f16_ss:
@@ -607,27 +688,45 @@ define amdgpu_ps <4 x half> @test_fmaximum_v4f16_ss(<4 x half> inreg %a, <4 x ha
 ; GFX9-GISEL-NEXT:    v_mov_b32_e32 v0, s2
 ; GFX9-GISEL-NEXT:    s_lshr_b32 s2, s2, 16
 ; GFX9-GISEL-NEXT:    v_pk_max_f16 v1, s0, v0
-; GFX9-GISEL-NEXT:    s_lshr_b32 s4, s0, 16
-; GFX9-GISEL-NEXT:    v_mov_b32_e32 v2, s2
-; GFX9-GISEL-NEXT:    v_mov_b32_e32 v4, 0x7e00
+; GFX9-GISEL-NEXT:    s_lshr_b32 s5, s0, 16
 ; GFX9-GISEL-NEXT:    v_cmp_o_f16_e32 vcc, s0, v0
-; GFX9-GISEL-NEXT:    v_lshrrev_b32_e32 v3, 16, v1
-; GFX9-GISEL-NEXT:    v_cndmask_b32_e32 v0, v4, v1, vcc
-; GFX9-GISEL-NEXT:    v_cmp_o_f16_e32 vcc, s4, v2
-; GFX9-GISEL-NEXT:    v_cndmask_b32_e32 v1, v4, v3, vcc
-; GFX9-GISEL-NEXT:    v_and_b32_e32 v0, 0xffff, v0
-; GFX9-GISEL-NEXT:    s_lshr_b32 s2, s3, 16
-; GFX9-GISEL-NEXT:    v_lshl_or_b32 v0, v1, 16, v0
-; GFX9-GISEL-NEXT:    v_mov_b32_e32 v1, s3
-; GFX9-GISEL-NEXT:    s_lshr_b32 s0, s1, 16
-; GFX9-GISEL-NEXT:    v_mov_b32_e32 v3, s2
-; GFX9-GISEL-NEXT:    v_pk_max_f16 v2, s1, v1
-; GFX9-GISEL-NEXT:    v_cmp_o_f16_e32 vcc, s0, v3
-; GFX9-GISEL-NEXT:    v_cmp_o_f16_e64 s[0:1], s1, v1
-; GFX9-GISEL-NEXT:    v_cndmask_b32_e64 v1, v4, v2, s[0:1]
-; GFX9-GISEL-NEXT:    v_cndmask_b32_sdwa v2, v4, v2, vcc dst_sel:DWORD dst_unused:UNUSED_PAD src0_sel:DWORD src1_sel:WORD_1
-; GFX9-GISEL-NEXT:    v_and_b32_e32 v1, 0xffff, v1
-; GFX9-GISEL-NEXT:    v_lshl_or_b32 v1, v2, 16, v1
+; GFX9-GISEL-NEXT:    v_mov_b32_e32 v0, s2
+; GFX9-GISEL-NEXT:    s_cmp_lg_u64 vcc, 0
+; GFX9-GISEL-NEXT:    v_cmp_o_f16_e32 vcc, s5, v0
+; GFX9-GISEL-NEXT:    v_readfirstlane_b32 s4, v1
+; GFX9-GISEL-NEXT:    s_cselect_b32 s0, 1, 0
+; GFX9-GISEL-NEXT:    s_cmp_lg_u64 vcc, 0
+; GFX9-GISEL-NEXT:    s_cselect_b32 s2, 1, 0
+; GFX9-GISEL-NEXT:    s_lshr_b32 s5, s4, 16
+; GFX9-GISEL-NEXT:    s_and_b32 s0, s0, 1
+; GFX9-GISEL-NEXT:    s_cmp_lg_u32 s0, 0
+; GFX9-GISEL-NEXT:    s_cselect_b32 s0, s4, 0x7e00
+; GFX9-GISEL-NEXT:    s_and_b32 s2, s2, 1
+; GFX9-GISEL-NEXT:    s_cmp_lg_u32 s2, 0
+; GFX9-GISEL-NEXT:    s_cselect_b32 s2, s5, 0x7e00
+; GFX9-GISEL-NEXT:    v_mov_b32_e32 v0, s3
+; GFX9-GISEL-NEXT:    s_lshr_b32 s3, s3, 16
+; GFX9-GISEL-NEXT:    v_pk_max_f16 v1, s1, v0
+; GFX9-GISEL-NEXT:    s...
[truncated]

``````````

</details>


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


More information about the llvm-commits mailing list