Skip to content

Commit f402e06

Browse files
[RISCV][VLOPT] Add vector fp min/max instructions to isSupportedInstr (#124196)
1 parent d87441a commit f402e06

File tree

2 files changed

+85
-0
lines changed

2 files changed

+85
-0
lines changed

llvm/lib/Target/RISCV/RISCVVLOptimizer.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1017,6 +1017,11 @@ static bool isSupportedInstr(const MachineInstr &MI) {
10171017
// Vector Widening Floating-Point Multiply
10181018
case RISCV::VFWMUL_VF:
10191019
case RISCV::VFWMUL_VV:
1020+
// Vector Floating-Point MIN/MAX Instructions
1021+
case RISCV::VFMIN_VF:
1022+
case RISCV::VFMIN_VV:
1023+
case RISCV::VFMAX_VF:
1024+
case RISCV::VFMAX_VV:
10201025
// Vector Floating-Point Compare Instructions
10211026
case RISCV::VMFEQ_VF:
10221027
case RISCV::VMFEQ_VV:

llvm/test/CodeGen/RISCV/rvv/vl-opt-instrs.ll

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3831,3 +3831,83 @@ define <vscale x 4 x i32> @vasubu_vx(<vscale x 4 x i32> %a, i32 %b, iXLen %vl) {
38313831
%2 = call <vscale x 4 x i32> @llvm.riscv.vadd.nxv4i32.nxv4i32(<vscale x 4 x i32> poison, <vscale x 4 x i32> %1, <vscale x 4 x i32> %a, iXLen %vl)
38323832
ret <vscale x 4 x i32> %2
38333833
}
3834+
3835+
define <vscale x 4 x float> @vfmax_vv(<vscale x 4 x float> %a, <vscale x 4 x float> %b, iXLen %vl) {
3836+
; NOVLOPT-LABEL: vfmax_vv:
3837+
; NOVLOPT: # %bb.0:
3838+
; NOVLOPT-NEXT: vsetvli a1, zero, e32, m2, ta, ma
3839+
; NOVLOPT-NEXT: vfmax.vv v8, v8, v10
3840+
; NOVLOPT-NEXT: vsetvli zero, a0, e32, m2, ta, ma
3841+
; NOVLOPT-NEXT: vfadd.vv v8, v8, v10
3842+
; NOVLOPT-NEXT: ret
3843+
;
3844+
; VLOPT-LABEL: vfmax_vv:
3845+
; VLOPT: # %bb.0:
3846+
; VLOPT-NEXT: vsetvli zero, a0, e32, m2, ta, ma
3847+
; VLOPT-NEXT: vfmax.vv v8, v8, v10
3848+
; VLOPT-NEXT: vfadd.vv v8, v8, v10
3849+
; VLOPT-NEXT: ret
3850+
%1 = call <vscale x 4 x float> @llvm.riscv.vfmax.nxv4f32.nxv4f32(<vscale x 4 x float> poison, <vscale x 4 x float> %a, <vscale x 4 x float> %b, iXLen -1)
3851+
%2 = call <vscale x 4 x float> @llvm.riscv.vfadd.nxv4f32.nxv4f32(<vscale x 4 x float> poison, <vscale x 4 x float> %1, <vscale x 4 x float> %b, iXLen 7, iXLen %vl)
3852+
ret <vscale x 4 x float> %2
3853+
}
3854+
3855+
define <vscale x 4 x float> @vfmax_vx(<vscale x 4 x float> %a, float %b, iXLen %vl) {
3856+
; NOVLOPT-LABEL: vfmax_vx:
3857+
; NOVLOPT: # %bb.0:
3858+
; NOVLOPT-NEXT: vsetvli a1, zero, e32, m2, ta, ma
3859+
; NOVLOPT-NEXT: vfmax.vf v10, v8, fa0
3860+
; NOVLOPT-NEXT: vsetvli zero, a0, e32, m2, ta, ma
3861+
; NOVLOPT-NEXT: vfadd.vv v8, v10, v8
3862+
; NOVLOPT-NEXT: ret
3863+
;
3864+
; VLOPT-LABEL: vfmax_vx:
3865+
; VLOPT: # %bb.0:
3866+
; VLOPT-NEXT: vsetvli zero, a0, e32, m2, ta, ma
3867+
; VLOPT-NEXT: vfmax.vf v10, v8, fa0
3868+
; VLOPT-NEXT: vfadd.vv v8, v10, v8
3869+
; VLOPT-NEXT: ret
3870+
%1 = call <vscale x 4 x float> @llvm.riscv.vfmax.nxv4f32.f32(<vscale x 4 x float> poison, <vscale x 4 x float> %a, float %b, iXLen -1)
3871+
%2 = call <vscale x 4 x float> @llvm.riscv.vfadd.nxv4f32.nxv4f32(<vscale x 4 x float> poison, <vscale x 4 x float> %1, <vscale x 4 x float> %a, iXLen 7, iXLen %vl)
3872+
ret <vscale x 4 x float> %2
3873+
}
3874+
3875+
define <vscale x 4 x float> @vfmin_vv(<vscale x 4 x float> %a, <vscale x 4 x float> %b, iXLen %vl) {
3876+
; NOVLOPT-LABEL: vfmin_vv:
3877+
; NOVLOPT: # %bb.0:
3878+
; NOVLOPT-NEXT: vsetvli a1, zero, e32, m2, ta, ma
3879+
; NOVLOPT-NEXT: vfmin.vv v8, v8, v10
3880+
; NOVLOPT-NEXT: vsetvli zero, a0, e32, m2, ta, ma
3881+
; NOVLOPT-NEXT: vfadd.vv v8, v8, v10
3882+
; NOVLOPT-NEXT: ret
3883+
;
3884+
; VLOPT-LABEL: vfmin_vv:
3885+
; VLOPT: # %bb.0:
3886+
; VLOPT-NEXT: vsetvli zero, a0, e32, m2, ta, ma
3887+
; VLOPT-NEXT: vfmin.vv v8, v8, v10
3888+
; VLOPT-NEXT: vfadd.vv v8, v8, v10
3889+
; VLOPT-NEXT: ret
3890+
%1 = call <vscale x 4 x float> @llvm.riscv.vfmin.nxv4f32.nxv4f32(<vscale x 4 x float> poison, <vscale x 4 x float> %a, <vscale x 4 x float> %b, iXLen -1)
3891+
%2 = call <vscale x 4 x float> @llvm.riscv.vfadd.nxv4f32.nxv4f32(<vscale x 4 x float> poison, <vscale x 4 x float> %1, <vscale x 4 x float> %b, iXLen 7, iXLen %vl)
3892+
ret <vscale x 4 x float> %2
3893+
}
3894+
3895+
define <vscale x 4 x float> @vfmin_vx(<vscale x 4 x float> %a, float %b, iXLen %vl) {
3896+
; NOVLOPT-LABEL: vfmin_vx:
3897+
; NOVLOPT: # %bb.0:
3898+
; NOVLOPT-NEXT: vsetvli a1, zero, e32, m2, ta, ma
3899+
; NOVLOPT-NEXT: vfmin.vf v10, v8, fa0
3900+
; NOVLOPT-NEXT: vsetvli zero, a0, e32, m2, ta, ma
3901+
; NOVLOPT-NEXT: vfadd.vv v8, v10, v8
3902+
; NOVLOPT-NEXT: ret
3903+
;
3904+
; VLOPT-LABEL: vfmin_vx:
3905+
; VLOPT: # %bb.0:
3906+
; VLOPT-NEXT: vsetvli zero, a0, e32, m2, ta, ma
3907+
; VLOPT-NEXT: vfmin.vf v10, v8, fa0
3908+
; VLOPT-NEXT: vfadd.vv v8, v10, v8
3909+
; VLOPT-NEXT: ret
3910+
%1 = call <vscale x 4 x float> @llvm.riscv.vfmin.nxv4f32.f32(<vscale x 4 x float> poison, <vscale x 4 x float> %a, float %b, iXLen -1)
3911+
%2 = call <vscale x 4 x float> @llvm.riscv.vfadd.nxv4f32.nxv4f32(<vscale x 4 x float> poison, <vscale x 4 x float> %1, <vscale x 4 x float> %a, iXLen 7, iXLen %vl)
3912+
ret <vscale x 4 x float> %2
3913+
}

0 commit comments

Comments
 (0)