1 //===-- RISCVInstrInfoD.td - RISC-V 'D' instructions -------*- tablegen -*-===//
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
7 //===----------------------------------------------------------------------===//
9 // This file describes the RISC-V instructions from the standard 'D',
10 // Double-Precision Floating-Point instruction set extension.
12 //===----------------------------------------------------------------------===//
14 //===----------------------------------------------------------------------===//
15 // RISC-V specific DAG Nodes.
16 //===----------------------------------------------------------------------===//
18 def SDT_RISCVBuildPairF64 : SDTypeProfile<1, 2, [SDTCisVT<0, f64>,
21 def SDT_RISCVSplitF64 : SDTypeProfile<2, 1, [SDTCisVT<0, i32>,
25 def RISCVBuildPairF64 : SDNode<"RISCVISD::BuildPairF64", SDT_RISCVBuildPairF64>;
26 def : GINodeEquiv<G_MERGE_VALUES, RISCVBuildPairF64>;
27 def RISCVSplitF64 : SDNode<"RISCVISD::SplitF64", SDT_RISCVSplitF64>;
28 def : GINodeEquiv<G_UNMERGE_VALUES, RISCVSplitF64>;
30 def AddrRegImmINX : ComplexPattern<iPTR, 2, "SelectAddrRegImmRV32Zdinx">;
32 //===----------------------------------------------------------------------===//
33 // Operand and SDNode transformation definitions.
34 //===----------------------------------------------------------------------===//
38 def GPRPairAsFPR : AsmOperandClass {
39 let Name = "GPRPairAsFPR";
40 let ParserMethod = "parseGPRPairAsFPR64";
41 let PredicateMethod = "isGPRPairAsFPR64";
42 let RenderMethod = "addRegOperands";
45 def GPRF64AsFPR : AsmOperandClass {
46 let Name = "GPRF64AsFPR";
47 let PredicateMethod = "isGPRAsFPR";
48 let ParserMethod = "parseGPRAsFPR64";
49 let RenderMethod = "addRegOperands";
52 def FPR64INX : RegisterOperand<GPR> {
53 let ParserMatchClass = GPRF64AsFPR;
54 let DecoderMethod = "DecodeGPRRegisterClass";
57 def FPR64IN32X : RegisterOperand<GPRPair> {
58 let ParserMatchClass = GPRPairAsFPR;
61 def DExt : ExtInfo<"", "", [HasStdExtD], f64, FPR64, FPR32, FPR64, ?>;
63 def ZdinxExt : ExtInfo<"_INX", "RVZfinx", [HasStdExtZdinx, IsRV64],
64 f64, FPR64INX, FPR32INX, FPR64INX, ?>;
65 def Zdinx32Ext : ExtInfo<"_IN32X", "RV32Zdinx", [HasStdExtZdinx, IsRV32],
66 f64, FPR64IN32X, FPR32INX, FPR64IN32X, ?>;
68 defvar DExts = [DExt, ZdinxExt, Zdinx32Ext];
69 defvar DExtsRV64 = [DExt, ZdinxExt];
71 //===----------------------------------------------------------------------===//
73 //===----------------------------------------------------------------------===//
75 let Predicates = [HasStdExtD] in {
76 def FLD : FPLoad_r<0b011, "fld", FPR64, WriteFLD64>;
78 // Operands for stores are in the order srcreg, base, offset rather than
79 // reflecting the order these fields are specified in the instruction
81 def FSD : FPStore_r<0b011, "fsd", FPR64, WriteFST64>;
82 } // Predicates = [HasStdExtD]
84 foreach Ext = DExts in {
85 let SchedRW = [WriteFMA64, ReadFMA64, ReadFMA64, ReadFMA64Addend] in {
86 defm FMADD_D : FPFMA_rrr_frm_m<OPC_MADD, 0b01, "fmadd.d", Ext>;
87 defm FMSUB_D : FPFMA_rrr_frm_m<OPC_MSUB, 0b01, "fmsub.d", Ext>;
88 defm FNMSUB_D : FPFMA_rrr_frm_m<OPC_NMSUB, 0b01, "fnmsub.d", Ext>;
89 defm FNMADD_D : FPFMA_rrr_frm_m<OPC_NMADD, 0b01, "fnmadd.d", Ext>;
92 let SchedRW = [WriteFAdd64, ReadFAdd64, ReadFAdd64] in {
93 defm FADD_D : FPALU_rr_frm_m<0b0000001, "fadd.d", Ext, Commutable=1>;
94 defm FSUB_D : FPALU_rr_frm_m<0b0000101, "fsub.d", Ext>;
96 let SchedRW = [WriteFMul64, ReadFMul64, ReadFMul64] in
97 defm FMUL_D : FPALU_rr_frm_m<0b0001001, "fmul.d", Ext, Commutable=1>;
99 let SchedRW = [WriteFDiv64, ReadFDiv64, ReadFDiv64] in
100 defm FDIV_D : FPALU_rr_frm_m<0b0001101, "fdiv.d", Ext>;
102 defm FSQRT_D : FPUnaryOp_r_frm_m<0b0101101, 0b00000, Ext, Ext.PrimaryTy,
103 Ext.PrimaryTy, "fsqrt.d">,
104 Sched<[WriteFSqrt64, ReadFSqrt64]>;
106 let SchedRW = [WriteFSGNJ64, ReadFSGNJ64, ReadFSGNJ64],
107 mayRaiseFPException = 0 in {
108 defm FSGNJ_D : FPALU_rr_m<0b0010001, 0b000, "fsgnj.d", Ext>;
109 defm FSGNJN_D : FPALU_rr_m<0b0010001, 0b001, "fsgnjn.d", Ext>;
110 defm FSGNJX_D : FPALU_rr_m<0b0010001, 0b010, "fsgnjx.d", Ext>;
113 let SchedRW = [WriteFMinMax64, ReadFMinMax64, ReadFMinMax64] in {
114 defm FMIN_D : FPALU_rr_m<0b0010101, 0b000, "fmin.d", Ext, Commutable=1>;
115 defm FMAX_D : FPALU_rr_m<0b0010101, 0b001, "fmax.d", Ext, Commutable=1>;
118 defm FCVT_S_D : FPUnaryOp_r_frm_m<0b0100000, 0b00001, Ext, Ext.F32Ty,
119 Ext.PrimaryTy, "fcvt.s.d">,
120 Sched<[WriteFCvtF64ToF32, ReadFCvtF64ToF32]>;
122 defm FCVT_D_S : FPUnaryOp_r_frmlegacy_m<0b0100001, 0b00000, Ext, Ext.PrimaryTy,
123 Ext.F32Ty, "fcvt.d.s">,
124 Sched<[WriteFCvtF32ToF64, ReadFCvtF32ToF64]>;
126 let SchedRW = [WriteFCmp64, ReadFCmp64, ReadFCmp64] in {
127 defm FEQ_D : FPCmp_rr_m<0b1010001, 0b010, "feq.d", Ext, Commutable=1>;
128 defm FLT_D : FPCmp_rr_m<0b1010001, 0b001, "flt.d", Ext>;
129 defm FLE_D : FPCmp_rr_m<0b1010001, 0b000, "fle.d", Ext>;
132 let mayRaiseFPException = 0 in
133 defm FCLASS_D : FPUnaryOp_r_m<0b1110001, 0b00000, 0b001, Ext, GPR, Ext.PrimaryTy,
135 Sched<[WriteFClass64, ReadFClass64]>;
137 let IsSignExtendingOpW = 1 in
138 defm FCVT_W_D : FPUnaryOp_r_frm_m<0b1100001, 0b00000, Ext, GPR, Ext.PrimaryTy,
140 Sched<[WriteFCvtF64ToI32, ReadFCvtF64ToI32]>;
142 let IsSignExtendingOpW = 1 in
143 defm FCVT_WU_D : FPUnaryOp_r_frm_m<0b1100001, 0b00001, Ext, GPR, Ext.PrimaryTy,
145 Sched<[WriteFCvtF64ToI32, ReadFCvtF64ToI32]>;
147 defm FCVT_D_W : FPUnaryOp_r_frmlegacy_m<0b1101001, 0b00000, Ext, Ext.PrimaryTy, GPR,
149 Sched<[WriteFCvtI32ToF64, ReadFCvtI32ToF64]>;
151 defm FCVT_D_WU : FPUnaryOp_r_frmlegacy_m<0b1101001, 0b00001, Ext, Ext.PrimaryTy, GPR,
153 Sched<[WriteFCvtI32ToF64, ReadFCvtI32ToF64]>;
154 } // foreach Ext = DExts
156 foreach Ext = DExtsRV64 in {
157 defm FCVT_L_D : FPUnaryOp_r_frm_m<0b1100001, 0b00010, Ext, GPR, Ext.PrimaryTy,
158 "fcvt.l.d", [IsRV64]>,
159 Sched<[WriteFCvtF64ToI64, ReadFCvtF64ToI64]>;
161 defm FCVT_LU_D : FPUnaryOp_r_frm_m<0b1100001, 0b00011, Ext, GPR, Ext.PrimaryTy,
162 "fcvt.lu.d", [IsRV64]>,
163 Sched<[WriteFCvtF64ToI64, ReadFCvtF64ToI64]>;
165 defm FCVT_D_L : FPUnaryOp_r_frm_m<0b1101001, 0b00010, Ext, Ext.PrimaryTy, GPR,
166 "fcvt.d.l", [IsRV64]>,
167 Sched<[WriteFCvtI64ToF64, ReadFCvtI64ToF64]>;
169 defm FCVT_D_LU : FPUnaryOp_r_frm_m<0b1101001, 0b00011, Ext, Ext.PrimaryTy, GPR,
170 "fcvt.d.lu", [IsRV64]>,
171 Sched<[WriteFCvtI64ToF64, ReadFCvtI64ToF64]>;
172 } // foreach Ext = DExts64
174 let Predicates = [HasStdExtD, IsRV64], mayRaiseFPException = 0 in
175 def FMV_X_D : FPUnaryOp_r<0b1110001, 0b00000, 0b000, GPR, FPR64, "fmv.x.d">,
176 Sched<[WriteFMovF64ToI64, ReadFMovF64ToI64]>;
178 let Predicates = [HasStdExtD, IsRV64], mayRaiseFPException = 0 in
179 def FMV_D_X : FPUnaryOp_r<0b1111001, 0b00000, 0b000, FPR64, GPR, "fmv.d.x">,
180 Sched<[WriteFMovI64ToF64, ReadFMovI64ToF64]>;
182 //===----------------------------------------------------------------------===//
183 // Assembler Pseudo Instructions (User-Level ISA, Version 2.2, Chapter 20)
184 //===----------------------------------------------------------------------===//
186 let Predicates = [HasStdExtD] in {
187 def : InstAlias<"fld $rd, (${rs1})", (FLD FPR64:$rd, GPR:$rs1, 0), 0>;
188 def : InstAlias<"fsd $rs2, (${rs1})", (FSD FPR64:$rs2, GPR:$rs1, 0), 0>;
190 def : InstAlias<"fmv.d $rd, $rs", (FSGNJ_D FPR64:$rd, FPR64:$rs, FPR64:$rs)>;
191 def : InstAlias<"fabs.d $rd, $rs", (FSGNJX_D FPR64:$rd, FPR64:$rs, FPR64:$rs)>;
192 def : InstAlias<"fneg.d $rd, $rs", (FSGNJN_D FPR64:$rd, FPR64:$rs, FPR64:$rs)>;
194 // fgt.d/fge.d are recognised by the GNU assembler but the canonical
195 // flt.d/fle.d forms will always be printed. Therefore, set a zero weight.
196 def : InstAlias<"fgt.d $rd, $rs, $rt",
197 (FLT_D GPR:$rd, FPR64:$rt, FPR64:$rs), 0>;
198 def : InstAlias<"fge.d $rd, $rs, $rt",
199 (FLE_D GPR:$rd, FPR64:$rt, FPR64:$rs), 0>;
201 def PseudoFLD : PseudoFloatLoad<"fld", FPR64>;
202 def PseudoFSD : PseudoStore<"fsd", FPR64>;
203 let usesCustomInserter = 1 in {
204 def PseudoQuietFLE_D : PseudoQuietFCMP<FPR64>;
205 def PseudoQuietFLT_D : PseudoQuietFCMP<FPR64>;
207 } // Predicates = [HasStdExtD]
209 let Predicates = [HasStdExtZdinx, IsRV64] in {
210 def : InstAlias<"fmv.d $rd, $rs", (FSGNJ_D_INX FPR64INX:$rd, FPR64INX:$rs, FPR64INX:$rs)>;
211 def : InstAlias<"fabs.d $rd, $rs", (FSGNJX_D_INX FPR64INX:$rd, FPR64INX:$rs, FPR64INX:$rs)>;
212 def : InstAlias<"fneg.d $rd, $rs", (FSGNJN_D_INX FPR64INX:$rd, FPR64INX:$rs, FPR64INX:$rs)>;
214 def : InstAlias<"fgt.d $rd, $rs, $rt",
215 (FLT_D_INX GPR:$rd, FPR64INX:$rt, FPR64INX:$rs), 0>;
216 def : InstAlias<"fge.d $rd, $rs, $rt",
217 (FLE_D_INX GPR:$rd, FPR64INX:$rt, FPR64INX:$rs), 0>;
218 let usesCustomInserter = 1 in {
219 def PseudoQuietFLE_D_INX : PseudoQuietFCMP<FPR64INX>;
220 def PseudoQuietFLT_D_INX : PseudoQuietFCMP<FPR64INX>;
222 } // Predicates = [HasStdExtZdinx, IsRV64]
224 let Predicates = [HasStdExtZdinx, IsRV32] in {
225 def : InstAlias<"fmv.d $rd, $rs", (FSGNJ_D_IN32X FPR64IN32X:$rd, FPR64IN32X:$rs, FPR64IN32X:$rs)>;
226 def : InstAlias<"fabs.d $rd, $rs", (FSGNJX_D_IN32X FPR64IN32X:$rd, FPR64IN32X:$rs, FPR64IN32X:$rs)>;
227 def : InstAlias<"fneg.d $rd, $rs", (FSGNJN_D_IN32X FPR64IN32X:$rd, FPR64IN32X:$rs, FPR64IN32X:$rs)>;
229 def : InstAlias<"fgt.d $rd, $rs, $rt",
230 (FLT_D_IN32X GPR:$rd, FPR64IN32X:$rt, FPR64IN32X:$rs), 0>;
231 def : InstAlias<"fge.d $rd, $rs, $rt",
232 (FLE_D_IN32X GPR:$rd, FPR64IN32X:$rt, FPR64IN32X:$rs), 0>;
233 let usesCustomInserter = 1 in {
234 def PseudoQuietFLE_D_IN32X : PseudoQuietFCMP<FPR64IN32X>;
235 def PseudoQuietFLT_D_IN32X : PseudoQuietFCMP<FPR64IN32X>;
237 } // Predicates = [HasStdExtZdinx, IsRV32]
239 //===----------------------------------------------------------------------===//
240 // Pseudo-instructions and codegen patterns
241 //===----------------------------------------------------------------------===//
243 let Predicates = [HasStdExtD] in {
245 /// Float conversion operations
247 // f64 -> f32, f32 -> f64
248 def : Pat<(any_fpround FPR64:$rs1), (FCVT_S_D FPR64:$rs1, FRM_DYN)>;
249 def : Pat<(any_fpextend FPR32:$rs1), (FCVT_D_S FPR32:$rs1, FRM_RNE)>;
250 } // Predicates = [HasStdExtD]
252 let Predicates = [HasStdExtZdinx, IsRV64] in {
253 /// Float conversion operations
255 // f64 -> f32, f32 -> f64
256 def : Pat<(any_fpround FPR64INX:$rs1), (FCVT_S_D_INX FPR64INX:$rs1, FRM_DYN)>;
257 def : Pat<(any_fpextend FPR32INX:$rs1), (FCVT_D_S_INX FPR32INX:$rs1, FRM_RNE)>;
258 } // Predicates = [HasStdExtZdinx, IsRV64]
260 let Predicates = [HasStdExtZdinx, IsRV32] in {
261 /// Float conversion operations
263 // f64 -> f32, f32 -> f64
264 def : Pat<(any_fpround FPR64IN32X:$rs1), (FCVT_S_D_IN32X FPR64IN32X:$rs1, FRM_DYN)>;
265 def : Pat<(any_fpextend FPR32INX:$rs1), (FCVT_D_S_IN32X FPR32INX:$rs1, FRM_RNE)>;
266 } // Predicates = [HasStdExtZdinx, IsRV32]
268 // [u]int<->double conversion patterns must be gated on IsRV32 or IsRV64, so
269 // are defined later.
271 /// Float arithmetic operations
273 foreach Ext = DExts in {
274 defm : PatFprFprDynFrm_m<any_fadd, FADD_D, Ext>;
275 defm : PatFprFprDynFrm_m<any_fsub, FSUB_D, Ext>;
276 defm : PatFprFprDynFrm_m<any_fmul, FMUL_D, Ext>;
277 defm : PatFprFprDynFrm_m<any_fdiv, FDIV_D, Ext>;
280 let Predicates = [HasStdExtD] in {
281 def : Pat<(any_fsqrt FPR64:$rs1), (FSQRT_D FPR64:$rs1, FRM_DYN)>;
283 def : Pat<(fneg FPR64:$rs1), (FSGNJN_D $rs1, $rs1)>;
284 def : Pat<(fabs FPR64:$rs1), (FSGNJX_D $rs1, $rs1)>;
286 def : Pat<(riscv_fclass FPR64:$rs1), (FCLASS_D $rs1)>;
288 def : PatFprFpr<fcopysign, FSGNJ_D, FPR64, f64>;
289 def : PatFprFpr<riscv_fsgnjx, FSGNJX_D, FPR64, f64>;
290 def : Pat<(fcopysign FPR64:$rs1, (fneg FPR64:$rs2)),
291 (FSGNJN_D FPR64:$rs1, FPR64:$rs2)>;
292 def : Pat<(fcopysign FPR64:$rs1, FPR32:$rs2), (FSGNJ_D $rs1, (FCVT_D_S $rs2,
294 def : Pat<(fcopysign FPR32:$rs1, FPR64:$rs2), (FSGNJ_S $rs1, (FCVT_S_D $rs2,
297 // fmadd: rs1 * rs2 + rs3
298 def : Pat<(any_fma FPR64:$rs1, FPR64:$rs2, FPR64:$rs3),
299 (FMADD_D $rs1, $rs2, $rs3, FRM_DYN)>;
301 // fmsub: rs1 * rs2 - rs3
302 def : Pat<(any_fma FPR64:$rs1, FPR64:$rs2, (fneg FPR64:$rs3)),
303 (FMSUB_D FPR64:$rs1, FPR64:$rs2, FPR64:$rs3, FRM_DYN)>;
305 // fnmsub: -rs1 * rs2 + rs3
306 def : Pat<(any_fma (fneg FPR64:$rs1), FPR64:$rs2, FPR64:$rs3),
307 (FNMSUB_D FPR64:$rs1, FPR64:$rs2, FPR64:$rs3, FRM_DYN)>;
309 // fnmadd: -rs1 * rs2 - rs3
310 def : Pat<(any_fma (fneg FPR64:$rs1), FPR64:$rs2, (fneg FPR64:$rs3)),
311 (FNMADD_D FPR64:$rs1, FPR64:$rs2, FPR64:$rs3, FRM_DYN)>;
313 // fnmadd: -(rs1 * rs2 + rs3) (the nsz flag on the FMA)
314 def : Pat<(fneg (any_fma_nsz FPR64:$rs1, FPR64:$rs2, FPR64:$rs3)),
315 (FNMADD_D FPR64:$rs1, FPR64:$rs2, FPR64:$rs3, FRM_DYN)>;
316 } // Predicates = [HasStdExtD]
318 let Predicates = [HasStdExtZdinx, IsRV64] in {
319 def : Pat<(any_fsqrt FPR64INX:$rs1), (FSQRT_D_INX FPR64INX:$rs1, FRM_DYN)>;
321 def : Pat<(fneg FPR64INX:$rs1), (FSGNJN_D_INX $rs1, $rs1)>;
322 def : Pat<(fabs FPR64INX:$rs1), (FSGNJX_D_INX $rs1, $rs1)>;
324 def : Pat<(riscv_fclass FPR64INX:$rs1), (FCLASS_D_INX $rs1)>;
326 def : PatFprFpr<fcopysign, FSGNJ_D_INX, FPR64INX, f64>;
327 def : PatFprFpr<riscv_fsgnjx, FSGNJX_D_INX, FPR64INX, f64>;
328 def : Pat<(fcopysign FPR64INX:$rs1, (fneg FPR64INX:$rs2)),
329 (FSGNJN_D_INX FPR64INX:$rs1, FPR64INX:$rs2)>;
330 def : Pat<(fcopysign FPR64INX:$rs1, FPR32INX:$rs2),
331 (FSGNJ_D_INX $rs1, (f64 (FCVT_D_S_INX $rs2, FRM_RNE)))>;
332 def : Pat<(fcopysign FPR32INX:$rs1, FPR64INX:$rs2),
333 (FSGNJ_S_INX $rs1, (FCVT_S_D_INX $rs2, FRM_DYN))>;
335 // fmadd: rs1 * rs2 + rs3
336 def : Pat<(any_fma FPR64INX:$rs1, FPR64INX:$rs2, FPR64INX:$rs3),
337 (FMADD_D_INX $rs1, $rs2, $rs3, FRM_DYN)>;
339 // fmsub: rs1 * rs2 - rs3
340 def : Pat<(any_fma FPR64INX:$rs1, FPR64INX:$rs2, (fneg FPR64INX:$rs3)),
341 (FMSUB_D_INX FPR64INX:$rs1, FPR64INX:$rs2, FPR64INX:$rs3, FRM_DYN)>;
343 // fnmsub: -rs1 * rs2 + rs3
344 def : Pat<(any_fma (fneg FPR64INX:$rs1), FPR64INX:$rs2, FPR64INX:$rs3),
345 (FNMSUB_D_INX FPR64INX:$rs1, FPR64INX:$rs2, FPR64INX:$rs3, FRM_DYN)>;
347 // fnmadd: -rs1 * rs2 - rs3
348 def : Pat<(any_fma (fneg FPR64INX:$rs1), FPR64INX:$rs2, (fneg FPR64INX:$rs3)),
349 (FNMADD_D_INX FPR64INX:$rs1, FPR64INX:$rs2, FPR64INX:$rs3, FRM_DYN)>;
351 // fnmadd: -(rs1 * rs2 + rs3) (the nsz flag on the FMA)
352 def : Pat<(fneg (any_fma_nsz FPR64INX:$rs1, FPR64INX:$rs2, FPR64INX:$rs3)),
353 (FNMADD_D_INX FPR64INX:$rs1, FPR64INX:$rs2, FPR64INX:$rs3, FRM_DYN)>;
354 } // Predicates = [HasStdExtZdinx, IsRV64]
356 let Predicates = [HasStdExtZdinx, IsRV32] in {
357 def : Pat<(any_fsqrt FPR64IN32X:$rs1), (FSQRT_D_IN32X FPR64IN32X:$rs1, FRM_DYN)>;
359 def : Pat<(fneg FPR64IN32X:$rs1), (FSGNJN_D_IN32X $rs1, $rs1)>;
360 def : Pat<(fabs FPR64IN32X:$rs1), (FSGNJX_D_IN32X $rs1, $rs1)>;
362 def : Pat<(riscv_fclass FPR64IN32X:$rs1), (FCLASS_D_IN32X $rs1)>;
364 def : PatFprFpr<fcopysign, FSGNJ_D_IN32X, FPR64IN32X, f64>;
365 def : PatFprFpr<riscv_fsgnjx, FSGNJX_D_IN32X, FPR64IN32X, f64>;
366 def : Pat<(fcopysign FPR64IN32X:$rs1, (fneg FPR64IN32X:$rs2)),
367 (FSGNJN_D_IN32X FPR64IN32X:$rs1, FPR64IN32X:$rs2)>;
368 def : Pat<(fcopysign FPR64IN32X:$rs1, FPR32INX:$rs2),
369 (FSGNJ_D_IN32X $rs1, (FCVT_D_S_IN32X $rs2, FRM_RNE))>;
370 def : Pat<(fcopysign FPR32INX:$rs1, FPR64IN32X:$rs2),
371 (FSGNJ_S_INX $rs1, (FCVT_S_D_IN32X $rs2, FRM_DYN))>;
373 // fmadd: rs1 * rs2 + rs3
374 def : Pat<(any_fma FPR64IN32X:$rs1, FPR64IN32X:$rs2, FPR64IN32X:$rs3),
375 (FMADD_D_IN32X $rs1, $rs2, $rs3, FRM_DYN)>;
377 // fmsub: rs1 * rs2 - rs3
378 def : Pat<(any_fma FPR64IN32X:$rs1, FPR64IN32X:$rs2, (fneg FPR64IN32X:$rs3)),
379 (FMSUB_D_IN32X FPR64IN32X:$rs1, FPR64IN32X:$rs2, FPR64IN32X:$rs3, FRM_DYN)>;
381 // fnmsub: -rs1 * rs2 + rs3
382 def : Pat<(any_fma (fneg FPR64IN32X:$rs1), FPR64IN32X:$rs2, FPR64IN32X:$rs3),
383 (FNMSUB_D_IN32X FPR64IN32X:$rs1, FPR64IN32X:$rs2, FPR64IN32X:$rs3, FRM_DYN)>;
385 // fnmadd: -rs1 * rs2 - rs3
386 def : Pat<(any_fma (fneg FPR64IN32X:$rs1), FPR64IN32X:$rs2, (fneg FPR64IN32X:$rs3)),
387 (FNMADD_D_IN32X FPR64IN32X:$rs1, FPR64IN32X:$rs2, FPR64IN32X:$rs3, FRM_DYN)>;
389 // fnmadd: -(rs1 * rs2 + rs3) (the nsz flag on the FMA)
390 def : Pat<(fneg (any_fma_nsz FPR64IN32X:$rs1, FPR64IN32X:$rs2, FPR64IN32X:$rs3)),
391 (FNMADD_D_IN32X FPR64IN32X:$rs1, FPR64IN32X:$rs2, FPR64IN32X:$rs3, FRM_DYN)>;
392 } // Predicates = [HasStdExtZdinx, IsRV32]
394 // The ratified 20191213 ISA spec defines fmin and fmax in a way that matches
395 // LLVM's fminnum and fmaxnum.
396 // <https://github.com/riscv/riscv-isa-manual/commit/cd20cee7efd9bac7c5aa127ec3b451749d2b3cce>.
397 foreach Ext = DExts in {
398 defm : PatFprFpr_m<fminnum, FMIN_D, Ext>;
399 defm : PatFprFpr_m<fmaxnum, FMAX_D, Ext>;
400 defm : PatFprFpr_m<fminimumnum, FMIN_D, Ext>;
401 defm : PatFprFpr_m<fmaximumnum, FMAX_D, Ext>;
402 defm : PatFprFpr_m<riscv_fmin, FMIN_D, Ext>;
403 defm : PatFprFpr_m<riscv_fmax, FMAX_D, Ext>;
404 def : Pat<(f64 (fcanonicalize FPR64:$rs1)), (FMIN_D $rs1, $rs1)>;
408 // FIXME: SETEQ/SETLT/SETLE imply nonans, can we pick better instructions for
409 // strict versions of those.
411 // Match non-signaling FEQ_D
412 foreach Ext = DExts in {
413 defm : PatSetCC_m<any_fsetcc, SETEQ, FEQ_D, Ext>;
414 defm : PatSetCC_m<any_fsetcc, SETOEQ, FEQ_D, Ext>;
415 defm : PatSetCC_m<strict_fsetcc, SETLT, PseudoQuietFLT_D, Ext>;
416 defm : PatSetCC_m<strict_fsetcc, SETOLT, PseudoQuietFLT_D, Ext>;
417 defm : PatSetCC_m<strict_fsetcc, SETLE, PseudoQuietFLE_D, Ext>;
418 defm : PatSetCC_m<strict_fsetcc, SETOLE, PseudoQuietFLE_D, Ext>;
421 let Predicates = [HasStdExtD] in {
422 // Match signaling FEQ_D
423 def : Pat<(XLenVT (strict_fsetccs FPR64:$rs1, FPR64:$rs2, SETEQ)),
424 (AND (XLenVT (FLE_D $rs1, $rs2)),
425 (XLenVT (FLE_D $rs2, $rs1)))>;
426 def : Pat<(XLenVT (strict_fsetccs FPR64:$rs1, FPR64:$rs2, SETOEQ)),
427 (AND (XLenVT (FLE_D $rs1, $rs2)),
428 (XLenVT (FLE_D $rs2, $rs1)))>;
429 // If both operands are the same, use a single FLE.
430 def : Pat<(XLenVT (strict_fsetccs FPR64:$rs1, FPR64:$rs1, SETEQ)),
432 def : Pat<(XLenVT (strict_fsetccs FPR64:$rs1, FPR64:$rs1, SETOEQ)),
435 def : PatSetCC<FPR64, any_fsetccs, SETLT, FLT_D, f64>;
436 def : PatSetCC<FPR64, any_fsetccs, SETOLT, FLT_D, f64>;
437 def : PatSetCC<FPR64, any_fsetccs, SETLE, FLE_D, f64>;
438 def : PatSetCC<FPR64, any_fsetccs, SETOLE, FLE_D, f64>;
439 } // Predicates = [HasStdExtD]
441 let Predicates = [HasStdExtZdinx, IsRV64] in {
442 // Match signaling FEQ_D
443 def : Pat<(XLenVT (strict_fsetccs (f64 FPR64INX:$rs1), FPR64INX:$rs2, SETEQ)),
444 (AND (XLenVT (FLE_D_INX $rs1, $rs2)),
445 (XLenVT (FLE_D_INX $rs2, $rs1)))>;
446 def : Pat<(XLenVT (strict_fsetccs (f64 FPR64INX:$rs1), FPR64INX:$rs2, SETOEQ)),
447 (AND (XLenVT (FLE_D_INX $rs1, $rs2)),
448 (XLenVT (FLE_D_INX $rs2, $rs1)))>;
449 // If both operands are the same, use a single FLE.
450 def : Pat<(XLenVT (strict_fsetccs (f64 FPR64INX:$rs1), FPR64INX:$rs1, SETEQ)),
451 (FLE_D_INX $rs1, $rs1)>;
452 def : Pat<(XLenVT (strict_fsetccs (f64 FPR64INX:$rs1), FPR64INX:$rs1, SETOEQ)),
453 (FLE_D_INX $rs1, $rs1)>;
455 def : PatSetCC<FPR64INX, any_fsetccs, SETLT, FLT_D_INX, f64>;
456 def : PatSetCC<FPR64INX, any_fsetccs, SETOLT, FLT_D_INX, f64>;
457 def : PatSetCC<FPR64INX, any_fsetccs, SETLE, FLE_D_INX, f64>;
458 def : PatSetCC<FPR64INX, any_fsetccs, SETOLE, FLE_D_INX, f64>;
459 } // Predicates = [HasStdExtZdinx, IsRV64]
461 let Predicates = [HasStdExtZdinx, IsRV32] in {
462 // Match signaling FEQ_D
463 def : Pat<(XLenVT (strict_fsetccs (f64 FPR64IN32X:$rs1), FPR64IN32X:$rs2, SETEQ)),
464 (AND (XLenVT (FLE_D_IN32X $rs1, $rs2)),
465 (XLenVT (FLE_D_IN32X $rs2, $rs1)))>;
466 def : Pat<(XLenVT (strict_fsetccs (f64 FPR64IN32X:$rs1), FPR64IN32X:$rs2, SETOEQ)),
467 (AND (XLenVT (FLE_D_IN32X $rs1, $rs2)),
468 (XLenVT (FLE_D_IN32X $rs2, $rs1)))>;
469 // If both operands are the same, use a single FLE.
470 def : Pat<(XLenVT (strict_fsetccs (f64 FPR64IN32X:$rs1), FPR64IN32X:$rs1, SETEQ)),
471 (FLE_D_IN32X $rs1, $rs1)>;
472 def : Pat<(XLenVT (strict_fsetccs (f64 FPR64IN32X:$rs1), FPR64IN32X:$rs1, SETOEQ)),
473 (FLE_D_IN32X $rs1, $rs1)>;
475 def : PatSetCC<FPR64IN32X, any_fsetccs, SETLT, FLT_D_IN32X, f64>;
476 def : PatSetCC<FPR64IN32X, any_fsetccs, SETOLT, FLT_D_IN32X, f64>;
477 def : PatSetCC<FPR64IN32X, any_fsetccs, SETLE, FLE_D_IN32X, f64>;
478 def : PatSetCC<FPR64IN32X, any_fsetccs, SETOLE, FLE_D_IN32X, f64>;
479 } // Predicates = [HasStdExtZdinx, IsRV32]
481 let Predicates = [HasStdExtD] in {
482 defm Select_FPR64 : SelectCC_GPR_rrirr<FPR64, f64>;
484 def PseudoFROUND_D : PseudoFROUND<FPR64, f64>;
488 def : LdPat<load, FLD, f64>;
492 def : StPat<store, FSD, FPR64, f64>;
493 } // Predicates = [HasStdExtD]
495 let Predicates = [HasStdExtD, NoStdExtZfa, IsRV32] in {
496 /// Pseudo-instructions needed for the soft-float ABI with RV32D
498 // Moves two GPRs to an FPR.
499 let usesCustomInserter = 1 in
500 def BuildPairF64Pseudo
501 : Pseudo<(outs FPR64:$dst), (ins GPR:$src1, GPR:$src2),
502 [(set FPR64:$dst, (RISCVBuildPairF64 GPR:$src1, GPR:$src2))]>;
504 // Moves an FPR to two GPRs.
505 let usesCustomInserter = 1 in
507 : Pseudo<(outs GPR:$dst1, GPR:$dst2), (ins FPR64:$src),
508 [(set GPR:$dst1, GPR:$dst2, (RISCVSplitF64 FPR64:$src))]>;
510 } // Predicates = [HasStdExtD, NoStdExtZfa, IsRV32]
512 let Predicates = [HasStdExtZdinx, IsRV64] in {
513 defm Select_FPR64INX : SelectCC_GPR_rrirr<FPR64INX, f64>;
515 def PseudoFROUND_D_INX : PseudoFROUND<FPR64INX, f64>;
518 def : LdPat<load, LD, f64>;
521 def : StPat<store, SD, GPR, f64>;
522 } // Predicates = [HasStdExtZdinx, IsRV64]
524 let Predicates = [HasStdExtZdinx, IsRV32] in {
525 defm Select_FPR64IN32X : SelectCC_GPR_rrirr<FPR64IN32X, f64>;
527 def PseudoFROUND_D_IN32X : PseudoFROUND<FPR64IN32X, f64>;
530 let isCall = 0, mayLoad = 1, mayStore = 0, Size = 8, isCodeGenOnly = 1 in
531 def PseudoRV32ZdinxLD : Pseudo<(outs GPRPair:$dst), (ins GPR:$rs1, simm12:$imm12), []>;
532 def : Pat<(f64 (load (AddrRegImmINX (XLenVT GPR:$rs1), simm12:$imm12))),
533 (PseudoRV32ZdinxLD GPR:$rs1, simm12:$imm12)>;
536 let isCall = 0, mayLoad = 0, mayStore = 1, Size = 8, isCodeGenOnly = 1 in
537 def PseudoRV32ZdinxSD : Pseudo<(outs), (ins GPRPair:$rs2, GPRNoX0:$rs1, simm12:$imm12), []>;
538 def : Pat<(store (f64 GPRPair:$rs2), (AddrRegImmINX (XLenVT GPR:$rs1), simm12:$imm12)),
539 (PseudoRV32ZdinxSD GPRPair:$rs2, GPR:$rs1, simm12:$imm12)>;
540 } // Predicates = [HasStdExtZdinx, IsRV32]
542 let Predicates = [HasStdExtD, IsRV32] in {
544 // double->[u]int. Round-to-zero must be used.
545 def : Pat<(i32 (any_fp_to_sint FPR64:$rs1)), (FCVT_W_D FPR64:$rs1, FRM_RTZ)>;
546 def : Pat<(i32 (any_fp_to_uint FPR64:$rs1)), (FCVT_WU_D FPR64:$rs1, FRM_RTZ)>;
548 // Saturating double->[u]int32.
549 def : Pat<(i32 (riscv_fcvt_x FPR64:$rs1, timm:$frm)), (FCVT_W_D $rs1, timm:$frm)>;
550 def : Pat<(i32 (riscv_fcvt_xu FPR64:$rs1, timm:$frm)), (FCVT_WU_D $rs1, timm:$frm)>;
552 // float->int32 with current rounding mode.
553 def : Pat<(i32 (any_lrint FPR64:$rs1)), (FCVT_W_D $rs1, FRM_DYN)>;
555 // float->int32 rounded to nearest with ties rounded away from zero.
556 def : Pat<(i32 (any_lround FPR64:$rs1)), (FCVT_W_D $rs1, FRM_RMM)>;
559 def : Pat<(any_sint_to_fp (i32 GPR:$rs1)), (FCVT_D_W GPR:$rs1, FRM_RNE)>;
560 def : Pat<(any_uint_to_fp (i32 GPR:$rs1)), (FCVT_D_WU GPR:$rs1, FRM_RNE)>;
561 } // Predicates = [HasStdExtD, IsRV32]
563 let Predicates = [HasStdExtZdinx, IsRV32] in {
565 // double->[u]int. Round-to-zero must be used.
566 def : Pat<(i32 (any_fp_to_sint FPR64IN32X:$rs1)), (FCVT_W_D_IN32X FPR64IN32X:$rs1, FRM_RTZ)>;
567 def : Pat<(i32 (any_fp_to_uint FPR64IN32X:$rs1)), (FCVT_WU_D_IN32X FPR64IN32X:$rs1, FRM_RTZ)>;
569 // Saturating double->[u]int32.
570 def : Pat<(i32 (riscv_fcvt_x FPR64IN32X:$rs1, timm:$frm)), (FCVT_W_D_IN32X $rs1, timm:$frm)>;
571 def : Pat<(i32 (riscv_fcvt_xu FPR64IN32X:$rs1, timm:$frm)), (FCVT_WU_D_IN32X $rs1, timm:$frm)>;
573 // float->int32 with current rounding mode.
574 def : Pat<(i32 (any_lrint FPR64IN32X:$rs1)), (FCVT_W_D_IN32X $rs1, FRM_DYN)>;
576 // float->int32 rounded to nearest with ties rounded away from zero.
577 def : Pat<(i32 (any_lround FPR64IN32X:$rs1)), (FCVT_W_D_IN32X $rs1, FRM_RMM)>;
580 def : Pat<(any_sint_to_fp (i32 GPR:$rs1)), (FCVT_D_W_IN32X GPR:$rs1, FRM_RNE)>;
581 def : Pat<(any_uint_to_fp (i32 GPR:$rs1)), (FCVT_D_WU_IN32X GPR:$rs1, FRM_RNE)>;
582 } // Predicates = [HasStdExtZdinx, IsRV32]
584 let Predicates = [HasStdExtD, IsRV64] in {
586 // Moves (no conversion)
587 def : Pat<(bitconvert (i64 GPR:$rs1)), (FMV_D_X GPR:$rs1)>;
588 def : Pat<(i64 (bitconvert FPR64:$rs1)), (FMV_X_D FPR64:$rs1)>;
590 // Use target specific isd nodes to help us remember the result is sign
591 // extended. Matching sext_inreg+fptoui/fptosi may cause the conversion to be
592 // duplicated if it has another user that didn't need the sign_extend.
593 def : Pat<(riscv_any_fcvt_w_rv64 FPR64:$rs1, timm:$frm), (FCVT_W_D $rs1, timm:$frm)>;
594 def : Pat<(riscv_any_fcvt_wu_rv64 FPR64:$rs1, timm:$frm), (FCVT_WU_D $rs1, timm:$frm)>;
597 def : Pat<(any_sint_to_fp (i64 (sexti32 (i64 GPR:$rs1)))), (FCVT_D_W $rs1, FRM_RNE)>;
598 def : Pat<(any_uint_to_fp (i64 (zexti32 (i64 GPR:$rs1)))), (FCVT_D_WU $rs1, FRM_RNE)>;
600 // Saturating double->[u]int64.
601 def : Pat<(i64 (riscv_fcvt_x FPR64:$rs1, timm:$frm)), (FCVT_L_D $rs1, timm:$frm)>;
602 def : Pat<(i64 (riscv_fcvt_xu FPR64:$rs1, timm:$frm)), (FCVT_LU_D $rs1, timm:$frm)>;
604 // double->[u]int64. Round-to-zero must be used.
605 def : Pat<(i64 (any_fp_to_sint FPR64:$rs1)), (FCVT_L_D FPR64:$rs1, FRM_RTZ)>;
606 def : Pat<(i64 (any_fp_to_uint FPR64:$rs1)), (FCVT_LU_D FPR64:$rs1, FRM_RTZ)>;
608 // double->int64 with current rounding mode.
609 def : Pat<(i64 (any_lrint FPR64:$rs1)), (FCVT_L_D $rs1, FRM_DYN)>;
610 def : Pat<(i64 (any_llrint FPR64:$rs1)), (FCVT_L_D $rs1, FRM_DYN)>;
612 // double->int64 rounded to nearest with ties rounded away from zero.
613 def : Pat<(i64 (any_lround FPR64:$rs1)), (FCVT_L_D $rs1, FRM_RMM)>;
614 def : Pat<(i64 (any_llround FPR64:$rs1)), (FCVT_L_D $rs1, FRM_RMM)>;
616 // [u]int64->fp. Match GCC and default to using dynamic rounding mode.
617 def : Pat<(any_sint_to_fp (i64 GPR:$rs1)), (FCVT_D_L GPR:$rs1, FRM_DYN)>;
618 def : Pat<(any_uint_to_fp (i64 GPR:$rs1)), (FCVT_D_LU GPR:$rs1, FRM_DYN)>;
619 } // Predicates = [HasStdExtD, IsRV64]
621 let Predicates = [HasStdExtZdinx, IsRV64] in {
623 // Moves (no conversion)
624 def : Pat<(f64 (bitconvert (i64 GPR:$rs1))), (COPY_TO_REGCLASS GPR:$rs1, GPR)>;
625 def : Pat<(i64 (bitconvert (f64 GPR:$rs1))), (COPY_TO_REGCLASS GPR:$rs1, GPR)>;
627 // Use target specific isd nodes to help us remember the result is sign
628 // extended. Matching sext_inreg+fptoui/fptosi may cause the conversion to be
629 // duplicated if it has another user that didn't need the sign_extend.
630 def : Pat<(riscv_any_fcvt_w_rv64 FPR64INX:$rs1, timm:$frm), (FCVT_W_D_INX $rs1, timm:$frm)>;
631 def : Pat<(riscv_any_fcvt_wu_rv64 FPR64INX:$rs1, timm:$frm), (FCVT_WU_D_INX $rs1, timm:$frm)>;
634 def : Pat<(any_sint_to_fp (i64 (sexti32 (i64 GPR:$rs1)))), (FCVT_D_W_INX $rs1, FRM_RNE)>;
635 def : Pat<(any_uint_to_fp (i64 (zexti32 (i64 GPR:$rs1)))), (FCVT_D_WU_INX $rs1, FRM_RNE)>;
637 // Saturating double->[u]int64.
638 def : Pat<(i64 (riscv_fcvt_x FPR64INX:$rs1, timm:$frm)), (FCVT_L_D_INX $rs1, timm:$frm)>;
639 def : Pat<(i64 (riscv_fcvt_xu FPR64INX:$rs1, timm:$frm)), (FCVT_LU_D_INX $rs1, timm:$frm)>;
641 // double->[u]int64. Round-to-zero must be used.
642 def : Pat<(i64 (any_fp_to_sint FPR64INX:$rs1)), (FCVT_L_D_INX FPR64INX:$rs1, FRM_RTZ)>;
643 def : Pat<(i64 (any_fp_to_uint FPR64INX:$rs1)), (FCVT_LU_D_INX FPR64INX:$rs1, FRM_RTZ)>;
645 // double->int64 with current rounding mode.
646 def : Pat<(i64 (any_lrint FPR64INX:$rs1)), (FCVT_L_D_INX $rs1, FRM_DYN)>;
647 def : Pat<(i64 (any_llrint FPR64INX:$rs1)), (FCVT_L_D_INX $rs1, FRM_DYN)>;
649 // double->int64 rounded to nearest with ties rounded away from zero.
650 def : Pat<(i64 (any_lround FPR64INX:$rs1)), (FCVT_L_D_INX $rs1, FRM_RMM)>;
651 def : Pat<(i64 (any_llround FPR64INX:$rs1)), (FCVT_L_D_INX $rs1, FRM_RMM)>;
653 // [u]int64->fp. Match GCC and default to using dynamic rounding mode.
654 def : Pat<(any_sint_to_fp (i64 GPR:$rs1)), (FCVT_D_L_INX GPR:$rs1, FRM_DYN)>;
655 def : Pat<(any_uint_to_fp (i64 GPR:$rs1)), (FCVT_D_LU_INX GPR:$rs1, FRM_DYN)>;
656 } // Predicates = [HasStdExtZdinx, IsRV64]