Skip to content

Commit c281a6a

Browse files
committed
[RISCV] Add isel pattern for int_riscv_vfmv_s_f with scalar FP constant operand.
Use vmv_s_x instead of the constant will be materialized in a GPR. This avoids going from GPR to FPR to vector. We already did this for RISCVISD::VFMV_S_F_VL and probably we should just turn int_riscv_vfmv_s_f into RISCVISD::VFMV_S_F_VL, but I'd like to see some improvements to RISCVInsertVSETVLI first.
1 parent 084f5c2 commit c281a6a

File tree

3 files changed

+12
-9
lines changed

3 files changed

+12
-9
lines changed

llvm/lib/Target/RISCV/RISCVInstrInfoVPseudos.td

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,8 @@ def VLOpFrag : PatFrag<(ops), (XLenVT (VLOp (XLenVT AVL:$vl)))>;
241241
// This must be kept in sync with RISCV::VLMaxSentinel.
242242
def VLMax : OutPatFrag<(ops), (XLenVT -1)>;
243243

244+
def SelectFPImm : ComplexPattern<fAny, 1, "selectFPImm", [], [], 1>;
245+
244246
// List of EEW.
245247
defvar EEWList = [8, 16, 32, 64];
246248

@@ -7425,6 +7427,11 @@ foreach fvti = AllFloatVectors in {
74257427
(fvti.Scalar (fpimm0)), VLOpFrag)),
74267428
(!cast<Instruction>("PseudoVMV_S_X_" # fvti.LMul.MX)
74277429
(fvti.Vector $rs1), (XLenVT X0), GPR:$vl, fvti.Log2SEW)>;
7430+
7431+
def : Pat<(fvti.Vector (int_riscv_vfmv_s_f (fvti.Vector fvti.RegClass:$rs1),
7432+
(fvti.Scalar (SelectFPImm (XLenVT GPR:$imm))), VLOpFrag)),
7433+
(!cast<Instruction>("PseudoVMV_S_X_" # fvti.LMul.MX)
7434+
(fvti.Vector $rs1), GPR:$imm, GPR:$vl, fvti.Log2SEW)>;
74287435
}
74297436
}
74307437

llvm/lib/Target/RISCV/RISCVInstrInfoVVLPatterns.td

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -585,8 +585,6 @@ def SplatPat_simm5_plus1_nonzero
585585
def Low8BitsSplatPat
586586
: ComplexPattern<vAny, 1, "selectLow8BitsVSplat", [], [], 2>;
587587

588-
def SelectFPImm : ComplexPattern<fAny, 1, "selectFPImm", [], [], 1>;
589-
590588
// Ignore the vl operand on vmv_v_f, and vmv_s_f.
591589
def SplatFPOp : PatFrags<(ops node:$op),
592590
[(riscv_vfmv_v_f_vl undef, node:$op, srcvalue),

llvm/test/CodeGen/RISCV/rvv/vfmv.s.f.ll

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -368,9 +368,8 @@ define <vscale x 1 x half> @intrinsic_vfmv.s.f_f_nxv1f16_negzero(<vscale x 1 x h
368368
; CHECK-LABEL: intrinsic_vfmv.s.f_f_nxv1f16_negzero:
369369
; CHECK: # %bb.0: # %entry
370370
; CHECK-NEXT: lui a1, 1048568
371-
; CHECK-NEXT: fmv.h.x fa5, a1
372371
; CHECK-NEXT: vsetvli zero, a0, e16, mf4, tu, ma
373-
; CHECK-NEXT: vfmv.s.f v8, fa5
372+
; CHECK-NEXT: vmv.s.x v8, a1
374373
; CHECK-NEXT: ret
375374
entry:
376375
%a = call <vscale x 1 x half> @llvm.riscv.vfmv.s.f.nxv1f16(<vscale x 1 x half> %0, half -0.0, iXLen %1)
@@ -381,9 +380,8 @@ define <vscale x 1 x float> @intrinsic_vfmv.s.f_f_nxv1f32_negzero(<vscale x 1 x
381380
; CHECK-LABEL: intrinsic_vfmv.s.f_f_nxv1f32_negzero:
382381
; CHECK: # %bb.0: # %entry
383382
; CHECK-NEXT: lui a1, 524288
384-
; CHECK-NEXT: fmv.w.x fa5, a1
385383
; CHECK-NEXT: vsetvli zero, a0, e32, mf2, tu, ma
386-
; CHECK-NEXT: vfmv.s.f v8, fa5
384+
; CHECK-NEXT: vmv.s.x v8, a1
387385
; CHECK-NEXT: ret
388386
entry:
389387
%a = call <vscale x 1 x float> @llvm.riscv.vfmv.s.f.nxv1f32(<vscale x 1 x float> %0, float -0.0, iXLen %1)
@@ -401,10 +399,10 @@ define <vscale x 1 x double> @intrinsic_vfmv.s.f_f_nxv1f64_negzero(<vscale x 1 x
401399
;
402400
; RV64-LABEL: intrinsic_vfmv.s.f_f_nxv1f64_negzero:
403401
; RV64: # %bb.0: # %entry
404-
; RV64-NEXT: fmv.d.x fa5, zero
405-
; RV64-NEXT: fneg.d fa5, fa5
402+
; RV64-NEXT: li a1, -1
403+
; RV64-NEXT: slli a1, a1, 63
406404
; RV64-NEXT: vsetvli zero, a0, e64, m1, tu, ma
407-
; RV64-NEXT: vfmv.s.f v8, fa5
405+
; RV64-NEXT: vmv.s.x v8, a1
408406
; RV64-NEXT: ret
409407
entry:
410408
%a = call <vscale x 1 x double> @llvm.riscv.vfmv.s.f.nxv1f64(<vscale x 1 x double> %0, double -0.0, iXLen %1)

0 commit comments

Comments
 (0)