Skip to content

Commit 46a40c4

Browse files
committed
[RISCV] Add intrinsics for vfmv.f.s and vfmv.s.f
Similar to D93365, but for floating point. No need for special ISD opcodes though. We can directly isel these from intrinsics. I had to use anyfloat_ty instead of anyvector_ty in the intrinsics to make LLVMVectorElementType not crash when imported into the -gen-dag-isel tablegen backend. Differential Revision: https://reviews.llvm.org/D93426
1 parent 0e94ba9 commit 46a40c4

File tree

3 files changed

+68
-3
lines changed

3 files changed

+68
-3
lines changed

llvm/include/llvm/IR/IntrinsicsRISCV.td

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,4 +349,12 @@ let TargetPrefix = "riscv" in {
349349
[IntrNoMem]>, RISCVVIntrinsic {
350350
let ExtendOperand = 2;
351351
}
352+
353+
def int_riscv_vfmv_f_s : Intrinsic<[LLVMVectorElementType<0>],
354+
[llvm_anyfloat_ty],
355+
[IntrNoMem]>, RISCVVIntrinsic;
356+
def int_riscv_vfmv_s_f : Intrinsic<[llvm_anyfloat_ty],
357+
[LLVMMatchType<0>, LLVMVectorElementType<0>,
358+
llvm_anyint_ty],
359+
[IntrNoMem]>, RISCVVIntrinsic;
352360
} // TargetPrefix = "riscv"

llvm/lib/Target/RISCV/RISCVInstrInfoV.td

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -980,8 +980,9 @@ let hasSideEffects = 0, mayLoad = 0, mayStore = 0, vm = 1 in {
980980
// Floating-Point Scalar Move Instructions
981981
def VFMV_F_S : RVInstV<0b010000, 0b00000, OPFVV, (outs FPR32:$vd),
982982
(ins VR:$vs2), "vfmv.f.s", "$vd, $vs2">;
983-
def VFMV_S_F : RVInstV2<0b010000, 0b00000, OPFVF, (outs VR:$vd),
984-
(ins FPR32:$rs1), "vfmv.s.f", "$vd, $rs1">;
983+
let Constraints = "$vd = $vd_wb" in
984+
def VFMV_S_F : RVInstV2<0b010000, 0b00000, OPFVF, (outs VR:$vd_wb),
985+
(ins VR:$vd, FPR32:$rs1), "vfmv.s.f", "$vd, $rs1">;
985986

986987
} // hasSideEffects = 0, mayLoad = 0, mayStore = 0, vm = 1
987988
} // Predicates = [HasStdExtV, HasStdExtF]

llvm/lib/Target/RISCV/RISCVInstrInfoVPseudos.td

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1370,12 +1370,37 @@ let mayLoad = 0, mayStore = 0, hasSideEffects = 0, usesCustomInserter = 1,
13701370
Constraints = "$rd = $rs1" in
13711371
def PseudoVMV_S_X # "_" # m.MX: Pseudo<(outs m.vrclass:$rd),
13721372
(ins m.vrclass:$rs1, GPR:$rs2,
1373-
GPR:$vl, ixlenimm:$sew),
1373+
GPR:$vl, ixlenimm:$sew),
13741374
[]>, RISCVVPseudo;
13751375
}
13761376
}
13771377
}
1378+
} // Predicates = [HasStdExtV]
1379+
1380+
//===----------------------------------------------------------------------===//
1381+
// 17.2. Floating-Point Scalar Move Instructions
1382+
//===----------------------------------------------------------------------===//
1383+
1384+
let Predicates = [HasStdExtV, HasStdExtF] in {
1385+
let mayLoad = 0, mayStore = 0, hasSideEffects = 0, usesCustomInserter = 1,
1386+
Uses = [VL, VTYPE] in {
1387+
foreach m = MxList.m in {
1388+
let VLMul = m.value in {
1389+
let SEWIndex = 2, BaseInstr = VFMV_F_S in
1390+
def PseudoVFMV_F_S # "_" # m.MX : Pseudo<(outs FPR32:$rd),
1391+
(ins m.vrclass:$rs2,
1392+
ixlenimm:$sew),
1393+
[]>, RISCVVPseudo;
1394+
let VLIndex = 3, SEWIndex = 4, BaseInstr = VFMV_S_F,
1395+
Constraints = "$rd = $rs1" in
1396+
def PseudoVFMV_S_F # "_" # m.MX : Pseudo<(outs m.vrclass:$rd),
1397+
(ins m.vrclass:$rs1, FPR32:$rs2,
1398+
GPR:$vl, ixlenimm:$sew),
1399+
[]>, RISCVVPseudo;
1400+
}
1401+
}
13781402
}
1403+
} // Predicates = [HasStdExtV, HasStdExtF]
13791404

13801405
//===----------------------------------------------------------------------===//
13811406
// Patterns.
@@ -1557,3 +1582,34 @@ foreach vti = AllIntegerVectors in {
15571582
(vti.Vector $rs1), $rs2, (NoX0 GPR:$vl), vti.SEW)>;
15581583
}
15591584
} // Predicates = [HasStdExtV]
1585+
1586+
//===----------------------------------------------------------------------===//
1587+
// 17.2. Floating-Point Scalar Move Instructions
1588+
//===----------------------------------------------------------------------===//
1589+
1590+
let Predicates = [HasStdExtV, HasStdExtF] in {
1591+
foreach fvti = AllFloatVectors in {
1592+
defvar instr = !cast<Instruction>("PseudoVFMV_F_S_" # fvti.LMul.MX);
1593+
def : Pat<(fvti.Scalar (int_riscv_vfmv_f_s (fvti.Vector fvti.RegClass:$rs2))),
1594+
// Floating point instructions with a scalar result will always
1595+
// generate the result in a register of class FPR32. When dealing
1596+
// with the f64 variant of a pattern we need to promote the FPR32
1597+
// subregister generated by the instruction to the FPR64 base
1598+
// register expected by the type in the pattern
1599+
!cond(!eq(!cast<string>(fvti.ScalarRegClass),
1600+
!cast<string>(FPR64)):
1601+
(SUBREG_TO_REG (i32 -1),
1602+
(instr $rs2, fvti.SEW), sub_32),
1603+
!eq(!cast<string>(fvti.ScalarRegClass),
1604+
!cast<string>(FPR16)):
1605+
(EXTRACT_SUBREG (instr $rs2, fvti.SEW), sub_16),
1606+
!eq(1, 1):
1607+
(instr $rs2, fvti.SEW))>;
1608+
1609+
def : Pat<(fvti.Vector (int_riscv_vfmv_s_f (fvti.Vector fvti.RegClass:$rs1),
1610+
(fvti.Scalar fvti.ScalarRegClass:$rs2), GPR:$vl)),
1611+
(!cast<Instruction>("PseudoVFMV_S_F_" # fvti.LMul.MX)
1612+
(fvti.Vector $rs1), ToFPR32<fvti.Scalar, fvti.ScalarRegClass, "rs2">.ret,
1613+
(NoX0 GPR:$vl), fvti.SEW)>;
1614+
}
1615+
} // Predicates = [HasStdExtV, HasStdExtF]

0 commit comments

Comments
 (0)