[llvm] [AMDGPU][GISel] Fold 'min(min(x,y),z)' and 'max(max(x,y),z)' into min3 and max3 (PR #200410)
Petar Avramovic via llvm-commits
llvm-commits at lists.llvm.org
Thu Jun 4 04:49:59 PDT 2026
================
@@ -0,0 +1,559 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 6
+; RUN: llc -global-isel -new-reg-bank-select -mtriple=amdgcn-amd-mesa3d -mcpu=gfx1010 -verify-machineinstrs < %s | FileCheck -check-prefix=GFX10 %s
+; RUN: llc -global-isel -new-reg-bank-select -mtriple=amdgcn-amd-mesa3d -mcpu=gfx1200 -verify-machineinstrs < %s | FileCheck -check-prefix=GFX12 %s
+define float @test_fmin3(float %a, float %b, float %c) {
+; GFX10-LABEL: test_fmin3:
+; GFX10: ; %bb.0:
+; GFX10-NEXT: s_waitcnt vmcnt(0) expcnt(0) lgkmcnt(0)
+; GFX10-NEXT: v_max_f32_e32 v0, v0, v0
+; GFX10-NEXT: v_max_f32_e32 v1, v1, v1
+; GFX10-NEXT: v_max_f32_e32 v2, v2, v2
+; GFX10-NEXT: v_min3_f32 v0, v0, v1, v2
----------------
petar-avramovic wrote:
In general this looks conservatively correct. Now I was checking what this does on hardware and think it should be safe to drop canonicalize(selects into v_max_f32_e32) of src0 and src1 since `v_max3_f32 = v_max_f32(v_max_f32(src0, src1), src2)` but not on src2.
Should not be concern on newer targets.
If it ends up looking too complex can skip attempting this optimization for now.
https://github.com/llvm/llvm-project/pull/200410
More information about the llvm-commits
mailing list