Skip to content

Commit bf258db

Browse files
[RISCV][VLOPT] support fp sign injection instructions (#124195)
1 parent f402e06 commit bf258db

File tree

2 files changed

+127
-0
lines changed

2 files changed

+127
-0
lines changed

llvm/lib/Target/RISCV/RISCVVLOptimizer.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1022,6 +1022,13 @@ static bool isSupportedInstr(const MachineInstr &MI) {
10221022
case RISCV::VFMIN_VV:
10231023
case RISCV::VFMAX_VF:
10241024
case RISCV::VFMAX_VV:
1025+
// Vector Floating-Point Sign-Injection Instructions
1026+
case RISCV::VFSGNJ_VF:
1027+
case RISCV::VFSGNJ_VV:
1028+
case RISCV::VFSGNJN_VV:
1029+
case RISCV::VFSGNJN_VF:
1030+
case RISCV::VFSGNJX_VF:
1031+
case RISCV::VFSGNJX_VV:
10251032
// Vector Floating-Point Compare Instructions
10261033
case RISCV::VMFEQ_VF:
10271034
case RISCV::VMFEQ_VV:

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

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3911,3 +3911,123 @@ define <vscale x 4 x float> @vfmin_vx(<vscale x 4 x float> %a, float %b, iXLen %
39113911
%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)
39123912
ret <vscale x 4 x float> %2
39133913
}
3914+
3915+
define <vscale x 4 x float> @vfsgnj_vv(<vscale x 4 x float> %a, <vscale x 4 x float> %b, iXLen %vl) {
3916+
; NOVLOPT-LABEL: vfsgnj_vv:
3917+
; NOVLOPT: # %bb.0:
3918+
; NOVLOPT-NEXT: vsetvli a1, zero, e32, m2, ta, ma
3919+
; NOVLOPT-NEXT: vfsgnj.vv v8, v8, v10
3920+
; NOVLOPT-NEXT: vsetvli zero, a0, e32, m2, ta, ma
3921+
; NOVLOPT-NEXT: vfadd.vv v8, v8, v10
3922+
; NOVLOPT-NEXT: ret
3923+
;
3924+
; VLOPT-LABEL: vfsgnj_vv:
3925+
; VLOPT: # %bb.0:
3926+
; VLOPT-NEXT: vsetvli zero, a0, e32, m2, ta, ma
3927+
; VLOPT-NEXT: vfsgnj.vv v8, v8, v10
3928+
; VLOPT-NEXT: vfadd.vv v8, v8, v10
3929+
; VLOPT-NEXT: ret
3930+
%1 = call <vscale x 4 x float> @llvm.riscv.vfsgnj.nxv4f32.nxv4f32(<vscale x 4 x float> poison, <vscale x 4 x float> %a, <vscale x 4 x float> %b, iXLen -1)
3931+
%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)
3932+
ret <vscale x 4 x float> %2
3933+
}
3934+
3935+
define <vscale x 4 x float> @vfsgnj_vf(<vscale x 4 x float> %a, float %b, iXLen %vl) {
3936+
; NOVLOPT-LABEL: vfsgnj_vf:
3937+
; NOVLOPT: # %bb.0:
3938+
; NOVLOPT-NEXT: vsetvli a1, zero, e32, m2, ta, ma
3939+
; NOVLOPT-NEXT: vfsgnj.vf v10, v8, fa0
3940+
; NOVLOPT-NEXT: vsetvli zero, a0, e32, m2, ta, ma
3941+
; NOVLOPT-NEXT: vfadd.vv v8, v10, v8
3942+
; NOVLOPT-NEXT: ret
3943+
;
3944+
; VLOPT-LABEL: vfsgnj_vf:
3945+
; VLOPT: # %bb.0:
3946+
; VLOPT-NEXT: vsetvli zero, a0, e32, m2, ta, ma
3947+
; VLOPT-NEXT: vfsgnj.vf v10, v8, fa0
3948+
; VLOPT-NEXT: vfadd.vv v8, v10, v8
3949+
; VLOPT-NEXT: ret
3950+
%1 = call <vscale x 4 x float> @llvm.riscv.vfsgnj.nxv4f32.nxv4f32(<vscale x 4 x float> poison, <vscale x 4 x float> %a, float %b, iXLen -1)
3951+
%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)
3952+
ret <vscale x 4 x float> %2
3953+
}
3954+
3955+
define <vscale x 4 x float> @vfsgnjn_vv(<vscale x 4 x float> %a, <vscale x 4 x float> %b, iXLen %vl) {
3956+
; NOVLOPT-LABEL: vfsgnjn_vv:
3957+
; NOVLOPT: # %bb.0:
3958+
; NOVLOPT-NEXT: vsetvli a1, zero, e32, m2, ta, ma
3959+
; NOVLOPT-NEXT: vfsgnjn.vv v8, v8, v10
3960+
; NOVLOPT-NEXT: vsetvli zero, a0, e32, m2, ta, ma
3961+
; NOVLOPT-NEXT: vfadd.vv v8, v8, v10
3962+
; NOVLOPT-NEXT: ret
3963+
;
3964+
; VLOPT-LABEL: vfsgnjn_vv:
3965+
; VLOPT: # %bb.0:
3966+
; VLOPT-NEXT: vsetvli zero, a0, e32, m2, ta, ma
3967+
; VLOPT-NEXT: vfsgnjn.vv v8, v8, v10
3968+
; VLOPT-NEXT: vfadd.vv v8, v8, v10
3969+
; VLOPT-NEXT: ret
3970+
%1 = call <vscale x 4 x float> @llvm.riscv.vfsgnjn.nxv4f32.nxv4f32(<vscale x 4 x float> poison, <vscale x 4 x float> %a, <vscale x 4 x float> %b, iXLen -1)
3971+
%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)
3972+
ret <vscale x 4 x float> %2
3973+
}
3974+
3975+
define <vscale x 4 x float> @vfsgnjn_vf(<vscale x 4 x float> %a, float %b, iXLen %vl) {
3976+
; NOVLOPT-LABEL: vfsgnjn_vf:
3977+
; NOVLOPT: # %bb.0:
3978+
; NOVLOPT-NEXT: vsetvli a1, zero, e32, m2, ta, ma
3979+
; NOVLOPT-NEXT: vfsgnjn.vf v10, v8, fa0
3980+
; NOVLOPT-NEXT: vsetvli zero, a0, e32, m2, ta, ma
3981+
; NOVLOPT-NEXT: vfadd.vv v8, v10, v8
3982+
; NOVLOPT-NEXT: ret
3983+
;
3984+
; VLOPT-LABEL: vfsgnjn_vf:
3985+
; VLOPT: # %bb.0:
3986+
; VLOPT-NEXT: vsetvli zero, a0, e32, m2, ta, ma
3987+
; VLOPT-NEXT: vfsgnjn.vf v10, v8, fa0
3988+
; VLOPT-NEXT: vfadd.vv v8, v10, v8
3989+
; VLOPT-NEXT: ret
3990+
%1 = call <vscale x 4 x float> @llvm.riscv.vfsgnjn.nxv4f32.nxv4f32(<vscale x 4 x float> poison, <vscale x 4 x float> %a, float %b, iXLen -1)
3991+
%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)
3992+
ret <vscale x 4 x float> %2
3993+
}
3994+
3995+
define <vscale x 4 x float> @vfsgnjx_vv(<vscale x 4 x float> %a, <vscale x 4 x float> %b, iXLen %vl) {
3996+
; NOVLOPT-LABEL: vfsgnjx_vv:
3997+
; NOVLOPT: # %bb.0:
3998+
; NOVLOPT-NEXT: vsetvli a1, zero, e32, m2, ta, ma
3999+
; NOVLOPT-NEXT: vfsgnjx.vv v8, v8, v10
4000+
; NOVLOPT-NEXT: vsetvli zero, a0, e32, m2, ta, ma
4001+
; NOVLOPT-NEXT: vfadd.vv v8, v8, v10
4002+
; NOVLOPT-NEXT: ret
4003+
;
4004+
; VLOPT-LABEL: vfsgnjx_vv:
4005+
; VLOPT: # %bb.0:
4006+
; VLOPT-NEXT: vsetvli zero, a0, e32, m2, ta, ma
4007+
; VLOPT-NEXT: vfsgnjx.vv v8, v8, v10
4008+
; VLOPT-NEXT: vfadd.vv v8, v8, v10
4009+
; VLOPT-NEXT: ret
4010+
%1 = call <vscale x 4 x float> @llvm.riscv.vfsgnjx.nxv4f32.nxv4f32(<vscale x 4 x float> poison, <vscale x 4 x float> %a, <vscale x 4 x float> %b, iXLen -1)
4011+
%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)
4012+
ret <vscale x 4 x float> %2
4013+
}
4014+
4015+
define <vscale x 4 x float> @vfsgnjx_vf(<vscale x 4 x float> %a, float %b, iXLen %vl) {
4016+
; NOVLOPT-LABEL: vfsgnjx_vf:
4017+
; NOVLOPT: # %bb.0:
4018+
; NOVLOPT-NEXT: vsetvli a1, zero, e32, m2, ta, ma
4019+
; NOVLOPT-NEXT: vfsgnjx.vf v10, v8, fa0
4020+
; NOVLOPT-NEXT: vsetvli zero, a0, e32, m2, ta, ma
4021+
; NOVLOPT-NEXT: vfadd.vv v8, v10, v8
4022+
; NOVLOPT-NEXT: ret
4023+
;
4024+
; VLOPT-LABEL: vfsgnjx_vf:
4025+
; VLOPT: # %bb.0:
4026+
; VLOPT-NEXT: vsetvli zero, a0, e32, m2, ta, ma
4027+
; VLOPT-NEXT: vfsgnjx.vf v10, v8, fa0
4028+
; VLOPT-NEXT: vfadd.vv v8, v10, v8
4029+
; VLOPT-NEXT: ret
4030+
%1 = call <vscale x 4 x float> @llvm.riscv.vfsgnjx.nxv4f32.nxv4f32(<vscale x 4 x float> poison, <vscale x 4 x float> %a, float %b, iXLen -1)
4031+
%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)
4032+
ret <vscale x 4 x float> %2
4033+
}

0 commit comments

Comments
 (0)