RISCVInstrInfoD.td 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433
  1. //===-- RISCVInstrInfoD.td - RISC-V 'D' instructions -------*- tablegen -*-===//
  2. //
  3. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  4. // See https://llvm.org/LICENSE.txt for license information.
  5. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. //
  7. //===----------------------------------------------------------------------===//
  8. //
  9. // This file describes the RISC-V instructions from the standard 'D',
  10. // Double-Precision Floating-Point instruction set extension.
  11. //
  12. //===----------------------------------------------------------------------===//
  13. //===----------------------------------------------------------------------===//
  14. // RISC-V specific DAG Nodes.
  15. //===----------------------------------------------------------------------===//
  16. def SDT_RISCVBuildPairF64 : SDTypeProfile<1, 2, [SDTCisVT<0, f64>,
  17. SDTCisVT<1, i32>,
  18. SDTCisSameAs<1, 2>]>;
  19. def SDT_RISCVSplitF64 : SDTypeProfile<2, 1, [SDTCisVT<0, i32>,
  20. SDTCisVT<1, i32>,
  21. SDTCisVT<2, f64>]>;
  22. def RISCVBuildPairF64 : SDNode<"RISCVISD::BuildPairF64", SDT_RISCVBuildPairF64>;
  23. def RISCVSplitF64 : SDNode<"RISCVISD::SplitF64", SDT_RISCVSplitF64>;
  24. //===----------------------------------------------------------------------===//
  25. // Operand and SDNode transformation definitions.
  26. //===----------------------------------------------------------------------===//
  27. // Zdinx
  28. def GPRPF64AsFPR : AsmOperandClass {
  29. let Name = "GPRPF64AsFPR";
  30. let ParserMethod = "parseGPRAsFPR";
  31. let RenderMethod = "addRegOperands";
  32. }
  33. def GPRF64AsFPR : AsmOperandClass {
  34. let Name = "GPRF64AsFPR";
  35. let ParserMethod = "parseGPRAsFPR";
  36. let RenderMethod = "addRegOperands";
  37. }
  38. def FPR64INX : RegisterOperand<GPRF64> {
  39. let ParserMatchClass = GPRF64AsFPR;
  40. let DecoderMethod = "DecodeGPRRegisterClass";
  41. }
  42. def FPR64IN32X : RegisterOperand<GPRPF64> {
  43. let ParserMatchClass = GPRPF64AsFPR;
  44. }
  45. def DExt : ExtInfo<0, [HasStdExtD]>;
  46. def D64Ext : ExtInfo<0, [HasStdExtD, IsRV64]>;
  47. def ZdinxExt : ExtInfo<1, [HasStdExtZdinx, IsRV64]>;
  48. def Zdinx32Ext : ExtInfo<2, [HasStdExtZdinx, IsRV32]>;
  49. def D : ExtInfo_r<DExt, FPR64>;
  50. def D_INX : ExtInfo_r<ZdinxExt, FPR64INX>;
  51. def D_IN32X : ExtInfo_r<Zdinx32Ext, FPR64IN32X>;
  52. def DD : ExtInfo_rr<DExt, FPR64, FPR64>;
  53. def DD_INX : ExtInfo_rr<ZdinxExt, FPR64INX, FPR64INX>;
  54. def DD_IN32X : ExtInfo_rr<Zdinx32Ext, FPR64IN32X, FPR64IN32X>;
  55. def DF : ExtInfo_rr<DExt, FPR64, FPR32>;
  56. def DF_INX : ExtInfo_rr<ZdinxExt, FPR64INX, FPR32INX>;
  57. def DF_IN32X : ExtInfo_rr<Zdinx32Ext, FPR64IN32X, FPR32INX>;
  58. def DX : ExtInfo_rr<DExt, FPR64, GPR>;
  59. def DX_INX : ExtInfo_rr<ZdinxExt, FPR64INX, GPR>;
  60. def DX_IN32X : ExtInfo_rr<Zdinx32Ext, FPR64IN32X, GPR>;
  61. def DX_64 : ExtInfo_rr<D64Ext, FPR64, GPR>;
  62. def FD : ExtInfo_rr<DExt, FPR32, FPR64>;
  63. def FD_INX : ExtInfo_rr<ZdinxExt, FPR32INX, FPR64INX>;
  64. def FD_IN32X : ExtInfo_rr<Zdinx32Ext, FPR32INX, FPR64IN32X>;
  65. def XD : ExtInfo_rr<DExt, GPR, FPR64>;
  66. def XD_INX : ExtInfo_rr<ZdinxExt, GPR, FPR64INX>;
  67. def XD_IN32X : ExtInfo_rr<Zdinx32Ext, GPR, FPR64IN32X>;
  68. def XD_64 : ExtInfo_rr<D64Ext, GPR, FPR64>;
  69. defvar DINX = [D, D_INX, D_IN32X];
  70. defvar DDINX = [DD, DD_INX, DD_IN32X];
  71. defvar DXINX = [DX, DX_INX, DX_IN32X];
  72. defvar DFINX = [DF, DF_INX, DF_IN32X];
  73. defvar FDINX = [FD, FD_INX, FD_IN32X];
  74. defvar XDINX = [XD, XD_INX, XD_IN32X];
  75. defvar DXIN64X = [DX_64, DX_INX];
  76. defvar XDIN64X = [XD_64, XD_INX];
  77. //===----------------------------------------------------------------------===//
  78. // Instructions
  79. //===----------------------------------------------------------------------===//
  80. let Predicates = [HasStdExtD] in {
  81. def FLD : FPLoad_r<0b011, "fld", FPR64, WriteFLD64>;
  82. // Operands for stores are in the order srcreg, base, offset rather than
  83. // reflecting the order these fields are specified in the instruction
  84. // encoding.
  85. def FSD : FPStore_r<0b011, "fsd", FPR64, WriteFST64>;
  86. } // Predicates = [HasStdExtD]
  87. let SchedRW = [WriteFMA64, ReadFMA64, ReadFMA64, ReadFMA64] in {
  88. defm FMADD_D : FPFMA_rrr_frm_m<OPC_MADD, 0b01, "fmadd.d", DINX>;
  89. defm FMSUB_D : FPFMA_rrr_frm_m<OPC_MSUB, 0b01, "fmsub.d", DINX>;
  90. defm FNMSUB_D : FPFMA_rrr_frm_m<OPC_NMSUB, 0b01, "fnmsub.d", DINX>;
  91. defm FNMADD_D : FPFMA_rrr_frm_m<OPC_NMADD, 0b01, "fnmadd.d", DINX>;
  92. }
  93. defm : FPFMADynFrmAlias_m<FMADD_D, "fmadd.d", DINX>;
  94. defm : FPFMADynFrmAlias_m<FMSUB_D, "fmsub.d", DINX>;
  95. defm : FPFMADynFrmAlias_m<FNMSUB_D, "fnmsub.d", DINX>;
  96. defm : FPFMADynFrmAlias_m<FNMADD_D, "fnmadd.d", DINX>;
  97. let SchedRW = [WriteFAdd64, ReadFAdd64, ReadFAdd64] in {
  98. defm FADD_D : FPALU_rr_frm_m<0b0000001, "fadd.d", DINX, /*Commutable*/1>;
  99. defm FSUB_D : FPALU_rr_frm_m<0b0000101, "fsub.d", DINX>;
  100. }
  101. let SchedRW = [WriteFMul64, ReadFMul64, ReadFMul64] in
  102. defm FMUL_D : FPALU_rr_frm_m<0b0001001, "fmul.d", DINX, /*Commutable*/1>;
  103. let SchedRW = [WriteFDiv64, ReadFDiv64, ReadFDiv64] in
  104. defm FDIV_D : FPALU_rr_frm_m<0b0001101, "fdiv.d", DINX>;
  105. defm : FPALUDynFrmAlias_m<FADD_D, "fadd.d", DINX>;
  106. defm : FPALUDynFrmAlias_m<FSUB_D, "fsub.d", DINX>;
  107. defm : FPALUDynFrmAlias_m<FMUL_D, "fmul.d", DINX>;
  108. defm : FPALUDynFrmAlias_m<FDIV_D, "fdiv.d", DINX>;
  109. defm FSQRT_D : FPUnaryOp_r_frm_m<0b0101101, 0b00000, DDINX, "fsqrt.d">,
  110. Sched<[WriteFSqrt64, ReadFSqrt64]>;
  111. defm : FPUnaryOpDynFrmAlias_m<FSQRT_D, "fsqrt.d", DDINX>;
  112. let SchedRW = [WriteFSGNJ64, ReadFSGNJ64, ReadFSGNJ64],
  113. mayRaiseFPException = 0 in {
  114. defm FSGNJ_D : FPALU_rr_m<0b0010001, 0b000, "fsgnj.d", DINX>;
  115. defm FSGNJN_D : FPALU_rr_m<0b0010001, 0b001, "fsgnjn.d", DINX>;
  116. defm FSGNJX_D : FPALU_rr_m<0b0010001, 0b010, "fsgnjx.d", DINX>;
  117. }
  118. let SchedRW = [WriteFMinMax64, ReadFMinMax64, ReadFMinMax64] in {
  119. defm FMIN_D : FPALU_rr_m<0b0010101, 0b000, "fmin.d", DINX, /*Commutable*/1>;
  120. defm FMAX_D : FPALU_rr_m<0b0010101, 0b001, "fmax.d", DINX, /*Commutable*/1>;
  121. }
  122. defm FCVT_S_D : FPUnaryOp_r_frm_m<0b0100000, 0b00001, FDINX, "fcvt.s.d">,
  123. Sched<[WriteFCvtF64ToF32, ReadFCvtF64ToF32]>;
  124. defm : FPUnaryOpDynFrmAlias_m<FCVT_S_D, "fcvt.s.d", FDINX>;
  125. defm FCVT_D_S : FPUnaryOp_r_m<0b0100001, 0b00000, 0b000, DFINX, "fcvt.d.s">,
  126. Sched<[WriteFCvtF32ToF64, ReadFCvtF32ToF64]>;
  127. let SchedRW = [WriteFCmp64, ReadFCmp64, ReadFCmp64] in {
  128. defm FEQ_D : FPCmp_rr_m<0b1010001, 0b010, "feq.d", DINX, /*Commutable*/1>;
  129. defm FLT_D : FPCmp_rr_m<0b1010001, 0b001, "flt.d", DINX>;
  130. defm FLE_D : FPCmp_rr_m<0b1010001, 0b000, "fle.d", DINX>;
  131. }
  132. defm FCLASS_D : FPUnaryOp_r_m<0b1110001, 0b00000, 0b001, XDINX, "fclass.d">,
  133. Sched<[WriteFClass64, ReadFClass64]>;
  134. let IsSignExtendingOpW = 1 in
  135. defm FCVT_W_D : FPUnaryOp_r_frm_m<0b1100001, 0b00000, XDINX, "fcvt.w.d">,
  136. Sched<[WriteFCvtF64ToI32, ReadFCvtF64ToI32]>;
  137. defm : FPUnaryOpDynFrmAlias_m<FCVT_W_D, "fcvt.w.d", XDINX>;
  138. let IsSignExtendingOpW = 1 in
  139. defm FCVT_WU_D : FPUnaryOp_r_frm_m<0b1100001, 0b00001, XDINX, "fcvt.wu.d">,
  140. Sched<[WriteFCvtF64ToI32, ReadFCvtF64ToI32]>;
  141. defm : FPUnaryOpDynFrmAlias_m<FCVT_WU_D, "fcvt.wu.d", XDINX>;
  142. defm FCVT_D_W : FPUnaryOp_r_m<0b1101001, 0b00000, 0b000, DXINX, "fcvt.d.w">,
  143. Sched<[WriteFCvtI32ToF64, ReadFCvtI32ToF64]>;
  144. defm FCVT_D_WU : FPUnaryOp_r_m<0b1101001, 0b00001, 0b000, DXINX, "fcvt.d.wu">,
  145. Sched<[WriteFCvtI32ToF64, ReadFCvtI32ToF64]>;
  146. defm FCVT_L_D : FPUnaryOp_r_frm_m<0b1100001, 0b00010, XDIN64X, "fcvt.l.d">,
  147. Sched<[WriteFCvtF64ToI64, ReadFCvtF64ToI64]>;
  148. defm : FPUnaryOpDynFrmAlias_m<FCVT_L_D, "fcvt.l.d", XDIN64X>;
  149. defm FCVT_LU_D : FPUnaryOp_r_frm_m<0b1100001, 0b00011, XDIN64X, "fcvt.lu.d">,
  150. Sched<[WriteFCvtF64ToI64, ReadFCvtF64ToI64]>;
  151. defm : FPUnaryOpDynFrmAlias_m<FCVT_LU_D, "fcvt.lu.d", XDIN64X>;
  152. let Predicates = [HasStdExtD, IsRV64], mayRaiseFPException = 0 in
  153. def FMV_X_D : FPUnaryOp_r<0b1110001, 0b00000, 0b000, GPR, FPR64, "fmv.x.d">,
  154. Sched<[WriteFMovF64ToI64, ReadFMovF64ToI64]>;
  155. defm FCVT_D_L : FPUnaryOp_r_frm_m<0b1101001, 0b00010, DXIN64X, "fcvt.d.l">,
  156. Sched<[WriteFCvtI64ToF64, ReadFCvtI64ToF64]>;
  157. defm : FPUnaryOpDynFrmAlias_m<FCVT_D_L, "fcvt.d.l", DXIN64X>;
  158. defm FCVT_D_LU : FPUnaryOp_r_frm_m<0b1101001, 0b00011, DXIN64X, "fcvt.d.lu">,
  159. Sched<[WriteFCvtI64ToF64, ReadFCvtI64ToF64]>;
  160. defm : FPUnaryOpDynFrmAlias_m<FCVT_D_LU, "fcvt.d.lu", DXIN64X>;
  161. let Predicates = [HasStdExtD, IsRV64], mayRaiseFPException = 0 in
  162. def FMV_D_X : FPUnaryOp_r<0b1111001, 0b00000, 0b000, FPR64, GPR, "fmv.d.x">,
  163. Sched<[WriteFMovI64ToF64, ReadFMovI64ToF64]>;
  164. //===----------------------------------------------------------------------===//
  165. // Assembler Pseudo Instructions (User-Level ISA, Version 2.2, Chapter 20)
  166. //===----------------------------------------------------------------------===//
  167. let Predicates = [HasStdExtD] in {
  168. def : InstAlias<"fld $rd, (${rs1})", (FLD FPR64:$rd, GPR:$rs1, 0), 0>;
  169. def : InstAlias<"fsd $rs2, (${rs1})", (FSD FPR64:$rs2, GPR:$rs1, 0), 0>;
  170. def : InstAlias<"fmv.d $rd, $rs", (FSGNJ_D FPR64:$rd, FPR64:$rs, FPR64:$rs)>;
  171. def : InstAlias<"fabs.d $rd, $rs", (FSGNJX_D FPR64:$rd, FPR64:$rs, FPR64:$rs)>;
  172. def : InstAlias<"fneg.d $rd, $rs", (FSGNJN_D FPR64:$rd, FPR64:$rs, FPR64:$rs)>;
  173. // fgt.d/fge.d are recognised by the GNU assembler but the canonical
  174. // flt.d/fle.d forms will always be printed. Therefore, set a zero weight.
  175. def : InstAlias<"fgt.d $rd, $rs, $rt",
  176. (FLT_D GPR:$rd, FPR64:$rt, FPR64:$rs), 0>;
  177. def : InstAlias<"fge.d $rd, $rs, $rt",
  178. (FLE_D GPR:$rd, FPR64:$rt, FPR64:$rs), 0>;
  179. def PseudoFLD : PseudoFloatLoad<"fld", FPR64>;
  180. def PseudoFSD : PseudoStore<"fsd", FPR64>;
  181. let usesCustomInserter = 1 in {
  182. def PseudoQuietFLE_D : PseudoQuietFCMP<FPR64>;
  183. def PseudoQuietFLT_D : PseudoQuietFCMP<FPR64>;
  184. }
  185. } // Predicates = [HasStdExtD]
  186. let Predicates = [HasStdExtZdinx, IsRV64] in {
  187. def : InstAlias<"fabs.d $rd, $rs", (FSGNJX_D_INX FPR64INX:$rd, FPR64INX:$rs, FPR64INX:$rs)>;
  188. def : InstAlias<"fneg.d $rd, $rs", (FSGNJN_D_INX FPR64INX:$rd, FPR64INX:$rs, FPR64INX:$rs)>;
  189. def : InstAlias<"fgt.d $rd, $rs, $rt",
  190. (FLT_D_INX GPR:$rd, FPR64INX:$rt, FPR64INX:$rs), 0>;
  191. def : InstAlias<"fge.d $rd, $rs, $rt",
  192. (FLE_D_INX GPR:$rd, FPR64INX:$rt, FPR64INX:$rs), 0>;
  193. } // Predicates = [HasStdExtZdinx, IsRV64]
  194. let Predicates = [HasStdExtZdinx, IsRV32] in {
  195. def : InstAlias<"fabs.d $rd, $rs", (FSGNJX_D_IN32X FPR64IN32X:$rd, FPR64IN32X:$rs, FPR64IN32X:$rs)>;
  196. def : InstAlias<"fneg.d $rd, $rs", (FSGNJN_D_IN32X FPR64IN32X:$rd, FPR64IN32X:$rs, FPR64IN32X:$rs)>;
  197. def : InstAlias<"fgt.d $rd, $rs, $rt",
  198. (FLT_D_IN32X GPR:$rd, FPR64IN32X:$rt, FPR64IN32X:$rs), 0>;
  199. def : InstAlias<"fge.d $rd, $rs, $rt",
  200. (FLE_D_IN32X GPR:$rd, FPR64IN32X:$rt, FPR64IN32X:$rs), 0>;
  201. } // Predicates = [HasStdExtZdinx, IsRV32]
  202. //===----------------------------------------------------------------------===//
  203. // Pseudo-instructions and codegen patterns
  204. //===----------------------------------------------------------------------===//
  205. let Predicates = [HasStdExtD] in {
  206. /// Float conversion operations
  207. // f64 -> f32, f32 -> f64
  208. def : Pat<(any_fpround FPR64:$rs1), (FCVT_S_D FPR64:$rs1, 0b111)>;
  209. def : Pat<(any_fpextend FPR32:$rs1), (FCVT_D_S FPR32:$rs1)>;
  210. // [u]int<->double conversion patterns must be gated on IsRV32 or IsRV64, so
  211. // are defined later.
  212. /// Float arithmetic operations
  213. def : PatFprFprDynFrm<any_fadd, FADD_D, FPR64>;
  214. def : PatFprFprDynFrm<any_fsub, FSUB_D, FPR64>;
  215. def : PatFprFprDynFrm<any_fmul, FMUL_D, FPR64>;
  216. def : PatFprFprDynFrm<any_fdiv, FDIV_D, FPR64>;
  217. def : Pat<(any_fsqrt FPR64:$rs1), (FSQRT_D FPR64:$rs1, 0b111)>;
  218. def : Pat<(fneg FPR64:$rs1), (FSGNJN_D $rs1, $rs1)>;
  219. def : Pat<(fabs FPR64:$rs1), (FSGNJX_D $rs1, $rs1)>;
  220. def : PatFprFpr<fcopysign, FSGNJ_D, FPR64>;
  221. def : Pat<(fcopysign FPR64:$rs1, (fneg FPR64:$rs2)), (FSGNJN_D $rs1, $rs2)>;
  222. def : Pat<(fcopysign FPR64:$rs1, FPR32:$rs2), (FSGNJ_D $rs1, (FCVT_D_S $rs2))>;
  223. def : Pat<(fcopysign FPR32:$rs1, FPR64:$rs2), (FSGNJ_S $rs1, (FCVT_S_D $rs2,
  224. 0b111))>;
  225. // fmadd: rs1 * rs2 + rs3
  226. def : Pat<(any_fma FPR64:$rs1, FPR64:$rs2, FPR64:$rs3),
  227. (FMADD_D $rs1, $rs2, $rs3, 0b111)>;
  228. // fmsub: rs1 * rs2 - rs3
  229. def : Pat<(any_fma FPR64:$rs1, FPR64:$rs2, (fneg FPR64:$rs3)),
  230. (FMSUB_D FPR64:$rs1, FPR64:$rs2, FPR64:$rs3, 0b111)>;
  231. // fnmsub: -rs1 * rs2 + rs3
  232. def : Pat<(any_fma (fneg FPR64:$rs1), FPR64:$rs2, FPR64:$rs3),
  233. (FNMSUB_D FPR64:$rs1, FPR64:$rs2, FPR64:$rs3, 0b111)>;
  234. // fnmadd: -rs1 * rs2 - rs3
  235. def : Pat<(any_fma (fneg FPR64:$rs1), FPR64:$rs2, (fneg FPR64:$rs3)),
  236. (FNMADD_D FPR64:$rs1, FPR64:$rs2, FPR64:$rs3, 0b111)>;
  237. // fnmadd: -(rs1 * rs2 + rs3) (the nsz flag on the FMA)
  238. def : Pat<(fneg (any_fma_nsz FPR64:$rs1, FPR64:$rs2, FPR64:$rs3)),
  239. (FNMADD_D FPR64:$rs1, FPR64:$rs2, FPR64:$rs3, 0b111)>;
  240. // The ratified 20191213 ISA spec defines fmin and fmax in a way that matches
  241. // LLVM's fminnum and fmaxnum.
  242. // <https://github.com/riscv/riscv-isa-manual/commit/cd20cee7efd9bac7c5aa127ec3b451749d2b3cce>.
  243. def : PatFprFpr<fminnum, FMIN_D, FPR64>;
  244. def : PatFprFpr<fmaxnum, FMAX_D, FPR64>;
  245. /// Setcc
  246. // FIXME: SETEQ/SETLT/SETLE imply nonans, can we pick better instructions for
  247. // strict versions of those.
  248. // Match non-signaling FEQ_D
  249. def : PatSetCC<FPR64, any_fsetcc, SETEQ, FEQ_D>;
  250. def : PatSetCC<FPR64, any_fsetcc, SETOEQ, FEQ_D>;
  251. def : PatSetCC<FPR64, strict_fsetcc, SETLT, PseudoQuietFLT_D>;
  252. def : PatSetCC<FPR64, strict_fsetcc, SETOLT, PseudoQuietFLT_D>;
  253. def : PatSetCC<FPR64, strict_fsetcc, SETLE, PseudoQuietFLE_D>;
  254. def : PatSetCC<FPR64, strict_fsetcc, SETOLE, PseudoQuietFLE_D>;
  255. // Match signaling FEQ_D
  256. def : Pat<(strict_fsetccs FPR64:$rs1, FPR64:$rs2, SETEQ),
  257. (AND (FLE_D $rs1, $rs2),
  258. (FLE_D $rs2, $rs1))>;
  259. def : Pat<(strict_fsetccs FPR64:$rs1, FPR64:$rs2, SETOEQ),
  260. (AND (FLE_D $rs1, $rs2),
  261. (FLE_D $rs2, $rs1))>;
  262. // If both operands are the same, use a single FLE.
  263. def : Pat<(strict_fsetccs FPR64:$rs1, FPR64:$rs1, SETEQ),
  264. (FLE_D $rs1, $rs1)>;
  265. def : Pat<(strict_fsetccs FPR64:$rs1, FPR64:$rs1, SETOEQ),
  266. (FLE_D $rs1, $rs1)>;
  267. def : PatSetCC<FPR64, any_fsetccs, SETLT, FLT_D>;
  268. def : PatSetCC<FPR64, any_fsetccs, SETOLT, FLT_D>;
  269. def : PatSetCC<FPR64, any_fsetccs, SETLE, FLE_D>;
  270. def : PatSetCC<FPR64, any_fsetccs, SETOLE, FLE_D>;
  271. defm Select_FPR64 : SelectCC_GPR_rrirr<FPR64>;
  272. def PseudoFROUND_D : PseudoFROUND<FPR64>;
  273. /// Loads
  274. defm : LdPat<load, FLD, f64>;
  275. /// Stores
  276. defm : StPat<store, FSD, FPR64, f64>;
  277. /// Pseudo-instructions needed for the soft-float ABI with RV32D
  278. // Moves two GPRs to an FPR.
  279. let usesCustomInserter = 1 in
  280. def BuildPairF64Pseudo
  281. : Pseudo<(outs FPR64:$dst), (ins GPR:$src1, GPR:$src2),
  282. [(set FPR64:$dst, (RISCVBuildPairF64 GPR:$src1, GPR:$src2))]>;
  283. // Moves an FPR to two GPRs.
  284. let usesCustomInserter = 1 in
  285. def SplitF64Pseudo
  286. : Pseudo<(outs GPR:$dst1, GPR:$dst2), (ins FPR64:$src),
  287. [(set GPR:$dst1, GPR:$dst2, (RISCVSplitF64 FPR64:$src))]>;
  288. } // Predicates = [HasStdExtD]
  289. let Predicates = [HasStdExtD, IsRV32] in {
  290. /// Float constants
  291. def : Pat<(f64 (fpimm0)), (FCVT_D_W (i32 X0))>;
  292. def : Pat<(f64 (fpimmneg0)), (FSGNJN_D (FCVT_D_W (i32 X0)),
  293. (FCVT_D_W (i32 X0)))>;
  294. // double->[u]int. Round-to-zero must be used.
  295. def : Pat<(i32 (any_fp_to_sint FPR64:$rs1)), (FCVT_W_D FPR64:$rs1, 0b001)>;
  296. def : Pat<(i32 (any_fp_to_uint FPR64:$rs1)), (FCVT_WU_D FPR64:$rs1, 0b001)>;
  297. // Saturating double->[u]int32.
  298. def : Pat<(i32 (riscv_fcvt_x FPR64:$rs1, timm:$frm)), (FCVT_W_D $rs1, timm:$frm)>;
  299. def : Pat<(i32 (riscv_fcvt_xu FPR64:$rs1, timm:$frm)), (FCVT_WU_D $rs1, timm:$frm)>;
  300. // float->int32 with current rounding mode.
  301. def : Pat<(i32 (any_lrint FPR64:$rs1)), (FCVT_W_D $rs1, 0b111)>;
  302. // float->int32 rounded to nearest with ties rounded away from zero.
  303. def : Pat<(i32 (any_lround FPR64:$rs1)), (FCVT_W_D $rs1, 0b100)>;
  304. // [u]int->double.
  305. def : Pat<(any_sint_to_fp (i32 GPR:$rs1)), (FCVT_D_W GPR:$rs1)>;
  306. def : Pat<(any_uint_to_fp (i32 GPR:$rs1)), (FCVT_D_WU GPR:$rs1)>;
  307. } // Predicates = [HasStdExtD, IsRV32]
  308. let Predicates = [HasStdExtD, IsRV64] in {
  309. /// Float constants
  310. def : Pat<(f64 (fpimm0)), (FMV_D_X (i64 X0))>;
  311. def : Pat<(f64 (fpimmneg0)), (FSGNJN_D (FMV_D_X (i64 X0)),
  312. (FMV_D_X (i64 X0)))>;
  313. // Moves (no conversion)
  314. def : Pat<(bitconvert (i64 GPR:$rs1)), (FMV_D_X GPR:$rs1)>;
  315. def : Pat<(i64 (bitconvert FPR64:$rs1)), (FMV_X_D FPR64:$rs1)>;
  316. // Use target specific isd nodes to help us remember the result is sign
  317. // extended. Matching sext_inreg+fptoui/fptosi may cause the conversion to be
  318. // duplicated if it has another user that didn't need the sign_extend.
  319. def : Pat<(riscv_any_fcvt_w_rv64 FPR64:$rs1, timm:$frm), (FCVT_W_D $rs1, timm:$frm)>;
  320. def : Pat<(riscv_any_fcvt_wu_rv64 FPR64:$rs1, timm:$frm), (FCVT_WU_D $rs1, timm:$frm)>;
  321. // [u]int32->fp
  322. def : Pat<(any_sint_to_fp (i64 (sexti32 (i64 GPR:$rs1)))), (FCVT_D_W $rs1)>;
  323. def : Pat<(any_uint_to_fp (i64 (zexti32 (i64 GPR:$rs1)))), (FCVT_D_WU $rs1)>;
  324. // Saturating double->[u]int64.
  325. def : Pat<(i64 (riscv_fcvt_x FPR64:$rs1, timm:$frm)), (FCVT_L_D $rs1, timm:$frm)>;
  326. def : Pat<(i64 (riscv_fcvt_xu FPR64:$rs1, timm:$frm)), (FCVT_LU_D $rs1, timm:$frm)>;
  327. // double->[u]int64. Round-to-zero must be used.
  328. def : Pat<(i64 (any_fp_to_sint FPR64:$rs1)), (FCVT_L_D FPR64:$rs1, 0b001)>;
  329. def : Pat<(i64 (any_fp_to_uint FPR64:$rs1)), (FCVT_LU_D FPR64:$rs1, 0b001)>;
  330. // double->int64 with current rounding mode.
  331. def : Pat<(i64 (any_lrint FPR64:$rs1)), (FCVT_L_D $rs1, 0b111)>;
  332. def : Pat<(i64 (any_llrint FPR64:$rs1)), (FCVT_L_D $rs1, 0b111)>;
  333. // double->int64 rounded to nearest with ties rounded away from zero.
  334. def : Pat<(i64 (any_lround FPR64:$rs1)), (FCVT_L_D $rs1, 0b100)>;
  335. def : Pat<(i64 (any_llround FPR64:$rs1)), (FCVT_L_D $rs1, 0b100)>;
  336. // [u]int64->fp. Match GCC and default to using dynamic rounding mode.
  337. def : Pat<(any_sint_to_fp (i64 GPR:$rs1)), (FCVT_D_L GPR:$rs1, 0b111)>;
  338. def : Pat<(any_uint_to_fp (i64 GPR:$rs1)), (FCVT_D_LU GPR:$rs1, 0b111)>;
  339. } // Predicates = [HasStdExtD, IsRV64]