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 RISCVSplitF64 : SDNode<"RISCVISD::SplitF64", SDT_RISCVSplitF64>;
28 def AddrRegImmINX : ComplexPattern<iPTR, 2, "SelectAddrRegImmINX">;
30 //===----------------------------------------------------------------------===//
31 // Operand and SDNode transformation definitions.
32 //===----------------------------------------------------------------------===//
36 def GPRPF64AsFPR : AsmOperandClass {
37 let Name = "GPRPF64AsFPR";
38 let ParserMethod = "parseGPRAsFPR";
39 let RenderMethod = "addRegOperands";
42 def GPRF64AsFPR : AsmOperandClass {
43 let Name = "GPRF64AsFPR";
44 let ParserMethod = "parseGPRAsFPR";
45 let RenderMethod = "addRegOperands";
48 def FPR64INX : RegisterOperand<GPR> {
49 let ParserMatchClass = GPRF64AsFPR;
50 let DecoderMethod = "DecodeGPRRegisterClass";
53 def FPR64IN32X : RegisterOperand<GPRPF64> {
54 let ParserMatchClass = GPRPF64AsFPR;
57 def DExt : ExtInfo<"", "", [HasStdExtD], f64, FPR64, FPR32, FPR64, ?>;
59 def ZdinxExt : ExtInfo<"_INX", "RVZfinx", [HasStdExtZdinx, IsRV64],
60 f64, FPR64INX, FPR32INX, FPR64INX, ?>;
61 def Zdinx32Ext : ExtInfo<"_IN32X", "RV32Zdinx", [HasStdExtZdinx, IsRV32],
62 f64, FPR64IN32X, FPR32INX, FPR64IN32X, ?>;
64 defvar DExts = [DExt, ZdinxExt, Zdinx32Ext];
65 defvar DExtsRV64 = [DExt, ZdinxExt];
67 //===----------------------------------------------------------------------===//
69 //===----------------------------------------------------------------------===//
71 let Predicates = [HasStdExtD] in {
72 def FLD : FPLoad_r<0b011, "fld", FPR64, WriteFLD64>;
74 // Operands for stores are in the order srcreg, base, offset rather than
75 // reflecting the order these fields are specified in the instruction
77 def FSD : FPStore_r<0b011, "fsd", FPR64, WriteFST64>;
78 } // Predicates = [HasStdExtD]
80 foreach Ext = DExts in {
81 let SchedRW = [WriteFMA64, ReadFMA64, ReadFMA64, ReadFMA64Addend] in {
82 defm FMADD_D : FPFMA_rrr_frm_m<OPC_MADD, 0b01, "fmadd.d", Ext>;
83 defm FMSUB_D : FPFMA_rrr_frm_m<OPC_MSUB, 0b01, "fmsub.d", Ext>;
84 defm FNMSUB_D : FPFMA_rrr_frm_m<OPC_NMSUB, 0b01, "fnmsub.d", Ext>;
85 defm FNMADD_D : FPFMA_rrr_frm_m<OPC_NMADD, 0b01, "fnmadd.d", Ext>;
88 let SchedRW = [WriteFAdd64, ReadFAdd64, ReadFAdd64] in {
89 defm FADD_D : FPALU_rr_frm_m<0b0000001, "fadd.d", Ext, Commutable=1>;
90 defm FSUB_D : FPALU_rr_frm_m<0b0000101, "fsub.d", Ext>;
92 let SchedRW = [WriteFMul64, ReadFMul64, ReadFMul64] in
93 defm FMUL_D : FPALU_rr_frm_m<0b0001001, "fmul.d", Ext, Commutable=1>;
95 let SchedRW = [WriteFDiv64, ReadFDiv64, ReadFDiv64] in
96 defm FDIV_D : FPALU_rr_frm_m<0b0001101, "fdiv.d", Ext>;
98 defm FSQRT_D : FPUnaryOp_r_frm_m<0b0101101, 0b00000, Ext, Ext.PrimaryTy,
99 Ext.PrimaryTy, "fsqrt.d">,
100 Sched<[WriteFSqrt64, ReadFSqrt64]>;
102 let SchedRW = [WriteFSGNJ64, ReadFSGNJ64, ReadFSGNJ64],
103 mayRaiseFPException = 0 in {
104 defm FSGNJ_D : FPALU_rr_m<0b0010001, 0b000, "fsgnj.d", Ext>;
105 defm FSGNJN_D : FPALU_rr_m<0b0010001, 0b001, "fsgnjn.d", Ext>;
106 defm FSGNJX_D : FPALU_rr_m<0b0010001, 0b010, "fsgnjx.d", Ext>;
109 let SchedRW = [WriteFMinMax64, ReadFMinMax64, ReadFMinMax64] in {
110 defm FMIN_D : FPALU_rr_m<0b0010101, 0b000, "fmin.d", Ext, Commutable=1>;
111 defm FMAX_D : FPALU_rr_m<0b0010101, 0b001, "fmax.d", Ext, Commutable=1>;
114 defm FCVT_S_D : FPUnaryOp_r_frm_m<0b0100000, 0b00001, Ext, Ext.F32Ty,
115 Ext.PrimaryTy, "fcvt.s.d">,
116 Sched<[WriteFCvtF64ToF32, ReadFCvtF64ToF32]>;
118 defm FCVT_D_S : FPUnaryOp_r_frmlegacy_m<0b0100001, 0b00000, Ext, Ext.PrimaryTy,
119 Ext.F32Ty, "fcvt.d.s">,
120 Sched<[WriteFCvtF32ToF64, ReadFCvtF32ToF64]>;
122 let SchedRW = [WriteFCmp64, ReadFCmp64, ReadFCmp64] in {
123 defm FEQ_D : FPCmp_rr_m<0b1010001, 0b010, "feq.d", Ext, Commutable=1>;
124 defm FLT_D : FPCmp_rr_m<0b1010001, 0b001, "flt.d", Ext>;
125 defm FLE_D : FPCmp_rr_m<0b1010001, 0b000, "fle.d", Ext>;
128 let mayRaiseFPException = 0 in
129 defm FCLASS_D : FPUnaryOp_r_m<0b1110001, 0b00000, 0b001, Ext, GPR, Ext.PrimaryTy,
131 Sched<[WriteFClass64, ReadFClass64]>;
133 let IsSignExtendingOpW = 1 in
134 defm FCVT_W_D : FPUnaryOp_r_frm_m<0b1100001, 0b00000, Ext, GPR, Ext.PrimaryTy,
136 Sched<[WriteFCvtF64ToI32, ReadFCvtF64ToI32]>;
138 let IsSignExtendingOpW = 1 in
139 defm FCVT_WU_D : FPUnaryOp_r_frm_m<0b1100001, 0b00001, Ext, GPR, Ext.PrimaryTy,
141 Sched<[WriteFCvtF64ToI32, ReadFCvtF64ToI32]>;
143 defm FCVT_D_W : FPUnaryOp_r_frmlegacy_m<0b1101001, 0b00000, Ext, Ext.PrimaryTy, GPR,
145 Sched<[WriteFCvtI32ToF64, ReadFCvtI32ToF64]>;
147 defm FCVT_D_WU : FPUnaryOp_r_frmlegacy_m<0b1101001, 0b00001, Ext, Ext.PrimaryTy, GPR,
149 Sched<[WriteFCvtI32ToF64, ReadFCvtI32ToF64]>;
150 } // foreach Ext = DExts
152 foreach Ext = DExtsRV64 in {
153 defm FCVT_L_D : FPUnaryOp_r_frm_m<0b1100001, 0b00010, Ext, GPR, Ext.PrimaryTy,
154 "fcvt.l.d", [IsRV64]>,
155 Sched<[WriteFCvtF64ToI64, ReadFCvtF64ToI64]>;
157 defm FCVT_LU_D : FPUnaryOp_r_frm_m<0b1100001, 0b00011, Ext, GPR, Ext.PrimaryTy,
158 "fcvt.lu.d", [IsRV64]>,
159 Sched<[WriteFCvtF64ToI64, ReadFCvtF64ToI64]>;
161 defm FCVT_D_L : FPUnaryOp_r_frm_m<0b1101001, 0b00010, Ext, Ext.PrimaryTy, GPR,
162 "fcvt.d.l", [IsRV64]>,
163 Sched<[WriteFCvtI64ToF64, ReadFCvtI64ToF64]>;
165 defm FCVT_D_LU : FPUnaryOp_r_frm_m<0b1101001, 0b00011, Ext, Ext.PrimaryTy, GPR,
166 "fcvt.d.lu", [IsRV64]>,
167 Sched<[WriteFCvtI64ToF64, ReadFCvtI64ToF64]>;
168 } // foreach Ext = DExts64
170 let Predicates = [HasStdExtD, IsRV64], mayRaiseFPException = 0 in
171 def FMV_X_D : FPUnaryOp_r<0b1110001, 0b00000, 0b000, GPR, FPR64, "fmv.x.d">,
172 Sched<[WriteFMovF64ToI64, ReadFMovF64ToI64]>;
174 let Predicates = [HasStdExtD, IsRV64], mayRaiseFPException = 0 in
175 def FMV_D_X : FPUnaryOp_r<0b1111001, 0b00000, 0b000, FPR64, GPR, "fmv.d.x">,
176 Sched<[WriteFMovI64ToF64, ReadFMovI64ToF64]>;
178 //===----------------------------------------------------------------------===//
179 // Assembler Pseudo Instructions (User-Level ISA, Version 2.2, Chapter 20)
180 //===----------------------------------------------------------------------===//
182 let Predicates = [HasStdExtD] in {
183 def : InstAlias<"fld $rd, (${rs1})", (FLD FPR64:$rd, GPR:$rs1, 0), 0>;
184 def : InstAlias<"fsd $rs2, (${rs1})", (FSD FPR64:$rs2, GPR:$rs1, 0), 0>;
186 def : InstAlias<"fmv.d $rd, $rs", (FSGNJ_D FPR64:$rd, FPR64:$rs, FPR64:$rs)>;
187 def : InstAlias<"fabs.d $rd, $rs", (FSGNJX_D FPR64:$rd, FPR64:$rs, FPR64:$rs)>;
188 def : InstAlias<"fneg.d $rd, $rs", (FSGNJN_D FPR64:$rd, FPR64:$rs, FPR64:$rs)>;
190 // fgt.d/fge.d are recognised by the GNU assembler but the canonical
191 // flt.d/fle.d forms will always be printed. Therefore, set a zero weight.
192 def : InstAlias<"fgt.d $rd, $rs, $rt",
193 (FLT_D GPR:$rd, FPR64:$rt, FPR64:$rs), 0>;
194 def : InstAlias<"fge.d $rd, $rs, $rt",
195 (FLE_D GPR:$rd, FPR64:$rt, FPR64:$rs), 0>;
197 def PseudoFLD : PseudoFloatLoad<"fld", FPR64>;
198 def PseudoFSD : PseudoStore<"fsd", FPR64>;
199 let usesCustomInserter = 1 in {
200 def PseudoQuietFLE_D : PseudoQuietFCMP<FPR64>;
201 def PseudoQuietFLT_D : PseudoQuietFCMP<FPR64>;
203 } // Predicates = [HasStdExtD]
205 let Predicates = [HasStdExtZdinx, IsRV64] in {
206 def : InstAlias<"fabs.d $rd, $rs", (FSGNJX_D_INX FPR64INX:$rd, FPR64INX:$rs, FPR64INX:$rs)>;
207 def : InstAlias<"fneg.d $rd, $rs", (FSGNJN_D_INX FPR64INX:$rd, FPR64INX:$rs, FPR64INX:$rs)>;
209 def : InstAlias<"fgt.d $rd, $rs, $rt",
210 (FLT_D_INX GPR:$rd, FPR64INX:$rt, FPR64INX:$rs), 0>;
211 def : InstAlias<"fge.d $rd, $rs, $rt",
212 (FLE_D_INX GPR:$rd, FPR64INX:$rt, FPR64INX:$rs), 0>;
213 let usesCustomInserter = 1 in {
214 def PseudoQuietFLE_D_INX : PseudoQuietFCMP<FPR64INX>;
215 def PseudoQuietFLT_D_INX : PseudoQuietFCMP<FPR64INX>;
217 } // Predicates = [HasStdExtZdinx, IsRV64]
219 let Predicates = [HasStdExtZdinx, IsRV32] in {
220 def : InstAlias<"fabs.d $rd, $rs", (FSGNJX_D_IN32X FPR64IN32X:$rd, FPR64IN32X:$rs, FPR64IN32X:$rs)>;
221 def : InstAlias<"fneg.d $rd, $rs", (FSGNJN_D_IN32X FPR64IN32X:$rd, FPR64IN32X:$rs, FPR64IN32X:$rs)>;
223 def : InstAlias<"fgt.d $rd, $rs, $rt",
224 (FLT_D_IN32X GPR:$rd, FPR64IN32X:$rt, FPR64IN32X:$rs), 0>;
225 def : InstAlias<"fge.d $rd, $rs, $rt",
226 (FLE_D_IN32X GPR:$rd, FPR64IN32X:$rt, FPR64IN32X:$rs), 0>;
227 let usesCustomInserter = 1 in {
228 def PseudoQuietFLE_D_IN32X : PseudoQuietFCMP<FPR64IN32X>;
229 def PseudoQuietFLT_D_IN32X : PseudoQuietFCMP<FPR64IN32X>;
231 } // Predicates = [HasStdExtZdinx, IsRV32]
233 //===----------------------------------------------------------------------===//
234 // Pseudo-instructions and codegen patterns
235 //===----------------------------------------------------------------------===//
237 let Predicates = [HasStdExtD] in {
239 /// Float conversion operations
241 // f64 -> f32, f32 -> f64
242 def : Pat<(any_fpround FPR64:$rs1), (FCVT_S_D FPR64:$rs1, FRM_DYN)>;
243 def : Pat<(any_fpextend FPR32:$rs1), (FCVT_D_S FPR32:$rs1, FRM_RNE)>;
244 } // Predicates = [HasStdExtD]
246 let Predicates = [HasStdExtZdinx, IsRV64] in {
247 /// Float conversion operations
249 // f64 -> f32, f32 -> f64
250 def : Pat<(any_fpround FPR64INX:$rs1), (FCVT_S_D_INX FPR64INX:$rs1, FRM_DYN)>;
251 def : Pat<(any_fpextend FPR32INX:$rs1), (FCVT_D_S_INX FPR32INX:$rs1, FRM_RNE)>;
252 } // Predicates = [HasStdExtZdinx, IsRV64]
254 let Predicates = [HasStdExtZdinx, IsRV32] in {
255 /// Float conversion operations
257 // f64 -> f32, f32 -> f64
258 def : Pat<(any_fpround FPR64IN32X:$rs1), (FCVT_S_D_IN32X FPR64IN32X:$rs1, FRM_DYN)>;
259 def : Pat<(any_fpextend FPR32INX:$rs1), (FCVT_D_S_IN32X FPR32INX:$rs1, FRM_RNE)>;
260 } // Predicates = [HasStdExtZdinx, IsRV32]
262 // [u]int<->double conversion patterns must be gated on IsRV32 or IsRV64, so
263 // are defined later.
265 /// Float arithmetic operations
267 foreach Ext = DExts in {
268 defm : PatFprFprDynFrm_m<any_fadd, FADD_D, Ext>;
269 defm : PatFprFprDynFrm_m<any_fsub, FSUB_D, Ext>;
270 defm : PatFprFprDynFrm_m<any_fmul, FMUL_D, Ext>;
271 defm : PatFprFprDynFrm_m<any_fdiv, FDIV_D, Ext>;
274 let Predicates = [HasStdExtD] in {
275 def : Pat<(any_fsqrt FPR64:$rs1), (FSQRT_D FPR64:$rs1, FRM_DYN)>;
277 def : Pat<(fneg FPR64:$rs1), (FSGNJN_D $rs1, $rs1)>;
278 def : Pat<(fabs FPR64:$rs1), (FSGNJX_D $rs1, $rs1)>;
280 def : Pat<(riscv_fpclass FPR64:$rs1), (FCLASS_D $rs1)>;
282 def : PatFprFpr<fcopysign, FSGNJ_D, FPR64, f64>;
283 def : Pat<(fcopysign FPR64:$rs1, (fneg FPR64:$rs2)), (FSGNJN_D $rs1, $rs2)>;
284 def : Pat<(fcopysign FPR64:$rs1, FPR32:$rs2), (FSGNJ_D $rs1, (FCVT_D_S $rs2,
286 def : Pat<(fcopysign FPR32:$rs1, FPR64:$rs2), (FSGNJ_S $rs1, (FCVT_S_D $rs2,
289 // fmadd: rs1 * rs2 + rs3
290 def : Pat<(any_fma FPR64:$rs1, FPR64:$rs2, FPR64:$rs3),
291 (FMADD_D $rs1, $rs2, $rs3, FRM_DYN)>;
293 // fmsub: rs1 * rs2 - rs3
294 def : Pat<(any_fma FPR64:$rs1, FPR64:$rs2, (fneg FPR64:$rs3)),
295 (FMSUB_D FPR64:$rs1, FPR64:$rs2, FPR64:$rs3, FRM_DYN)>;
297 // fnmsub: -rs1 * rs2 + rs3
298 def : Pat<(any_fma (fneg FPR64:$rs1), FPR64:$rs2, FPR64:$rs3),
299 (FNMSUB_D FPR64:$rs1, FPR64:$rs2, FPR64:$rs3, FRM_DYN)>;
301 // fnmadd: -rs1 * rs2 - rs3
302 def : Pat<(any_fma (fneg FPR64:$rs1), FPR64:$rs2, (fneg FPR64:$rs3)),
303 (FNMADD_D FPR64:$rs1, FPR64:$rs2, FPR64:$rs3, FRM_DYN)>;
305 // fnmadd: -(rs1 * rs2 + rs3) (the nsz flag on the FMA)
306 def : Pat<(fneg (any_fma_nsz FPR64:$rs1, FPR64:$rs2, FPR64:$rs3)),
307 (FNMADD_D FPR64:$rs1, FPR64:$rs2, FPR64:$rs3, FRM_DYN)>;
308 } // Predicates = [HasStdExtD]
310 let Predicates = [HasStdExtZdinx, IsRV64] in {
311 def : Pat<(any_fsqrt FPR64INX:$rs1), (FSQRT_D_INX FPR64INX:$rs1, FRM_DYN)>;
313 def : Pat<(fneg FPR64INX:$rs1), (FSGNJN_D_INX $rs1, $rs1)>;
314 def : Pat<(fabs FPR64INX:$rs1), (FSGNJX_D_INX $rs1, $rs1)>;
316 def : Pat<(riscv_fpclass FPR64INX:$rs1), (FCLASS_D_INX $rs1)>;
318 def : PatFprFpr<fcopysign, FSGNJ_D_INX, FPR64INX, f64>;
319 def : Pat<(fcopysign FPR64INX:$rs1, (fneg FPR64INX:$rs2)),
320 (FSGNJN_D_INX $rs1, $rs2)>;
321 def : Pat<(fcopysign FPR64INX:$rs1, FPR32INX:$rs2),
322 (FSGNJ_D_INX $rs1, (FCVT_D_S_INX $rs2, FRM_RNE))>;
323 def : Pat<(fcopysign FPR32INX:$rs1, FPR64INX:$rs2),
324 (FSGNJ_S_INX $rs1, (FCVT_S_D_INX $rs2, FRM_DYN))>;
326 // fmadd: rs1 * rs2 + rs3
327 def : Pat<(any_fma FPR64INX:$rs1, FPR64INX:$rs2, FPR64INX:$rs3),
328 (FMADD_D_INX $rs1, $rs2, $rs3, FRM_DYN)>;
330 // fmsub: rs1 * rs2 - rs3
331 def : Pat<(any_fma FPR64INX:$rs1, FPR64INX:$rs2, (fneg FPR64INX:$rs3)),
332 (FMSUB_D_INX FPR64INX:$rs1, FPR64INX:$rs2, FPR64INX:$rs3, FRM_DYN)>;
334 // fnmsub: -rs1 * rs2 + rs3
335 def : Pat<(any_fma (fneg FPR64INX:$rs1), FPR64INX:$rs2, FPR64INX:$rs3),
336 (FNMSUB_D_INX FPR64INX:$rs1, FPR64INX:$rs2, FPR64INX:$rs3, FRM_DYN)>;
338 // fnmadd: -rs1 * rs2 - rs3
339 def : Pat<(any_fma (fneg FPR64INX:$rs1), FPR64INX:$rs2, (fneg FPR64INX:$rs3)),
340 (FNMADD_D_INX FPR64INX:$rs1, FPR64INX:$rs2, FPR64INX:$rs3, FRM_DYN)>;
342 // fnmadd: -(rs1 * rs2 + rs3) (the nsz flag on the FMA)
343 def : Pat<(fneg (any_fma_nsz FPR64INX:$rs1, FPR64INX:$rs2, FPR64INX:$rs3)),
344 (FNMADD_D_INX FPR64INX:$rs1, FPR64INX:$rs2, FPR64INX:$rs3, FRM_DYN)>;
345 } // Predicates = [HasStdExtZdinx, IsRV64]
347 let Predicates = [HasStdExtZdinx, IsRV32] in {
348 def : Pat<(any_fsqrt FPR64IN32X:$rs1), (FSQRT_D_IN32X FPR64IN32X:$rs1, FRM_DYN)>;
350 def : Pat<(fneg FPR64IN32X:$rs1), (FSGNJN_D_IN32X $rs1, $rs1)>;
351 def : Pat<(fabs FPR64IN32X:$rs1), (FSGNJX_D_IN32X $rs1, $rs1)>;
353 def : Pat<(riscv_fpclass FPR64IN32X:$rs1), (FCLASS_D_IN32X $rs1)>;
355 def : PatFprFpr<fcopysign, FSGNJ_D_IN32X, FPR64IN32X, f64>;
356 def : Pat<(fcopysign FPR64IN32X:$rs1, (fneg FPR64IN32X:$rs2)),
357 (FSGNJN_D_IN32X $rs1, $rs2)>;
358 def : Pat<(fcopysign FPR64IN32X:$rs1, FPR32INX:$rs2),
359 (FSGNJ_D_IN32X $rs1, (FCVT_D_S_INX $rs2, FRM_RNE))>;
360 def : Pat<(fcopysign FPR32INX:$rs1, FPR64IN32X:$rs2),
361 (FSGNJ_S_INX $rs1, (FCVT_S_D_IN32X $rs2, FRM_DYN))>;
363 // fmadd: rs1 * rs2 + rs3
364 def : Pat<(any_fma FPR64IN32X:$rs1, FPR64IN32X:$rs2, FPR64IN32X:$rs3),
365 (FMADD_D_IN32X $rs1, $rs2, $rs3, FRM_DYN)>;
367 // fmsub: rs1 * rs2 - rs3
368 def : Pat<(any_fma FPR64IN32X:$rs1, FPR64IN32X:$rs2, (fneg FPR64IN32X:$rs3)),
369 (FMSUB_D_IN32X FPR64IN32X:$rs1, FPR64IN32X:$rs2, FPR64IN32X:$rs3, FRM_DYN)>;
371 // fnmsub: -rs1 * rs2 + rs3
372 def : Pat<(any_fma (fneg FPR64IN32X:$rs1), FPR64IN32X:$rs2, FPR64IN32X:$rs3),
373 (FNMSUB_D_IN32X FPR64IN32X:$rs1, FPR64IN32X:$rs2, FPR64IN32X:$rs3, FRM_DYN)>;
375 // fnmadd: -rs1 * rs2 - rs3
376 def : Pat<(any_fma (fneg FPR64IN32X:$rs1), FPR64IN32X:$rs2, (fneg FPR64IN32X:$rs3)),
377 (FNMADD_D_IN32X FPR64IN32X:$rs1, FPR64IN32X:$rs2, FPR64IN32X:$rs3, FRM_DYN)>;
379 // fnmadd: -(rs1 * rs2 + rs3) (the nsz flag on the FMA)
380 def : Pat<(fneg (any_fma_nsz FPR64IN32X:$rs1, FPR64IN32X:$rs2, FPR64IN32X:$rs3)),
381 (FNMADD_D_IN32X FPR64IN32X:$rs1, FPR64IN32X:$rs2, FPR64IN32X:$rs3, FRM_DYN)>;
382 } // Predicates = [HasStdExtZdinx, IsRV32]
384 // The ratified 20191213 ISA spec defines fmin and fmax in a way that matches
385 // LLVM's fminnum and fmaxnum.
386 // <https://github.com/riscv/riscv-isa-manual/commit/cd20cee7efd9bac7c5aa127ec3b451749d2b3cce>.
387 foreach Ext = DExts in {
388 defm : PatFprFpr_m<fminnum, FMIN_D, Ext>;
389 defm : PatFprFpr_m<fmaxnum, FMAX_D, Ext>;
390 defm : PatFprFpr_m<riscv_fmin, FMIN_D, Ext>;
391 defm : PatFprFpr_m<riscv_fmax, FMAX_D, Ext>;
395 // FIXME: SETEQ/SETLT/SETLE imply nonans, can we pick better instructions for
396 // strict versions of those.
398 // Match non-signaling FEQ_D
399 foreach Ext = DExts in {
400 defm : PatSetCC_m<any_fsetcc, SETEQ, FEQ_D, Ext>;
401 defm : PatSetCC_m<any_fsetcc, SETOEQ, FEQ_D, Ext>;
402 defm : PatSetCC_m<strict_fsetcc, SETLT, PseudoQuietFLT_D, Ext>;
403 defm : PatSetCC_m<strict_fsetcc, SETOLT, PseudoQuietFLT_D, Ext>;
404 defm : PatSetCC_m<strict_fsetcc, SETLE, PseudoQuietFLE_D, Ext>;
405 defm : PatSetCC_m<strict_fsetcc, SETOLE, PseudoQuietFLE_D, Ext>;
408 let Predicates = [HasStdExtD] in {
409 // Match signaling FEQ_D
410 def : Pat<(XLenVT (strict_fsetccs FPR64:$rs1, FPR64:$rs2, SETEQ)),
411 (AND (FLE_D $rs1, $rs2),
412 (FLE_D $rs2, $rs1))>;
413 def : Pat<(XLenVT (strict_fsetccs FPR64:$rs1, FPR64:$rs2, SETOEQ)),
414 (AND (FLE_D $rs1, $rs2),
415 (FLE_D $rs2, $rs1))>;
416 // If both operands are the same, use a single FLE.
417 def : Pat<(XLenVT (strict_fsetccs FPR64:$rs1, FPR64:$rs1, SETEQ)),
419 def : Pat<(XLenVT (strict_fsetccs FPR64:$rs1, FPR64:$rs1, SETOEQ)),
422 def : PatSetCC<FPR64, any_fsetccs, SETLT, FLT_D, f64>;
423 def : PatSetCC<FPR64, any_fsetccs, SETOLT, FLT_D, f64>;
424 def : PatSetCC<FPR64, any_fsetccs, SETLE, FLE_D, f64>;
425 def : PatSetCC<FPR64, any_fsetccs, SETOLE, FLE_D, f64>;
426 } // Predicates = [HasStdExtD]
428 let Predicates = [HasStdExtZdinx, IsRV64] in {
429 // Match signaling FEQ_D
430 def : Pat<(XLenVT (strict_fsetccs (f64 FPR64INX:$rs1), FPR64INX:$rs2, SETEQ)),
431 (AND (FLE_D_INX $rs1, $rs2),
432 (FLE_D_INX $rs2, $rs1))>;
433 def : Pat<(XLenVT (strict_fsetccs (f64 FPR64INX:$rs1), FPR64INX:$rs2, SETOEQ)),
434 (AND (FLE_D_INX $rs1, $rs2),
435 (FLE_D_INX $rs2, $rs1))>;
436 // If both operands are the same, use a single FLE.
437 def : Pat<(XLenVT (strict_fsetccs (f64 FPR64INX:$rs1), FPR64INX:$rs1, SETEQ)),
438 (FLE_D_INX $rs1, $rs1)>;
439 def : Pat<(XLenVT (strict_fsetccs (f64 FPR64INX:$rs1), FPR64INX:$rs1, SETOEQ)),
440 (FLE_D_INX $rs1, $rs1)>;
442 def : PatSetCC<FPR64INX, any_fsetccs, SETLT, FLT_D_INX, f64>;
443 def : PatSetCC<FPR64INX, any_fsetccs, SETOLT, FLT_D_INX, f64>;
444 def : PatSetCC<FPR64INX, any_fsetccs, SETLE, FLE_D_INX, f64>;
445 def : PatSetCC<FPR64INX, any_fsetccs, SETOLE, FLE_D_INX, f64>;
446 } // Predicates = [HasStdExtZdinx, IsRV64]
448 let Predicates = [HasStdExtZdinx, IsRV32] in {
449 // Match signaling FEQ_D
450 def : Pat<(XLenVT (strict_fsetccs FPR64IN32X:$rs1, FPR64IN32X:$rs2, SETEQ)),
451 (AND (FLE_D_IN32X $rs1, $rs2),
452 (FLE_D_IN32X $rs2, $rs1))>;
453 def : Pat<(XLenVT (strict_fsetccs FPR64IN32X:$rs1, FPR64IN32X:$rs2, SETOEQ)),
454 (AND (FLE_D_IN32X $rs1, $rs2),
455 (FLE_D_IN32X $rs2, $rs1))>;
456 // If both operands are the same, use a single FLE.
457 def : Pat<(XLenVT (strict_fsetccs FPR64IN32X:$rs1, FPR64IN32X:$rs1, SETEQ)),
458 (FLE_D_IN32X $rs1, $rs1)>;
459 def : Pat<(XLenVT (strict_fsetccs FPR64IN32X:$rs1, FPR64IN32X:$rs1, SETOEQ)),
460 (FLE_D_IN32X $rs1, $rs1)>;
462 def : PatSetCC<FPR64IN32X, any_fsetccs, SETLT, FLT_D_IN32X, f64>;
463 def : PatSetCC<FPR64IN32X, any_fsetccs, SETOLT, FLT_D_IN32X, f64>;
464 def : PatSetCC<FPR64IN32X, any_fsetccs, SETLE, FLE_D_IN32X, f64>;
465 def : PatSetCC<FPR64IN32X, any_fsetccs, SETOLE, FLE_D_IN32X, f64>;
466 } // Predicates = [HasStdExtZdinx, IsRV32]
468 let Predicates = [HasStdExtD] in {
469 defm Select_FPR64 : SelectCC_GPR_rrirr<FPR64, f64>;
471 def PseudoFROUND_D : PseudoFROUND<FPR64, f64>;
475 def : LdPat<load, FLD, f64>;
479 def : StPat<store, FSD, FPR64, f64>;
481 /// Pseudo-instructions needed for the soft-float ABI with RV32D
483 // Moves two GPRs to an FPR.
484 let usesCustomInserter = 1 in
485 def BuildPairF64Pseudo
486 : Pseudo<(outs FPR64:$dst), (ins GPR:$src1, GPR:$src2),
487 [(set FPR64:$dst, (RISCVBuildPairF64 GPR:$src1, GPR:$src2))]>;
489 // Moves an FPR to two GPRs.
490 let usesCustomInserter = 1 in
492 : Pseudo<(outs GPR:$dst1, GPR:$dst2), (ins FPR64:$src),
493 [(set GPR:$dst1, GPR:$dst2, (RISCVSplitF64 FPR64:$src))]>;
495 } // Predicates = [HasStdExtD]
497 let Predicates = [HasStdExtZdinx, IsRV64] in {
498 defm Select_FPR64INX : SelectCC_GPR_rrirr<FPR64INX, f64>;
500 def PseudoFROUND_D_INX : PseudoFROUND<FPR64INX, f64>;
503 def : LdPat<load, LD, f64>;
506 def : StPat<store, SD, GPR, f64>;
507 } // Predicates = [HasStdExtZdinx, IsRV64]
509 let Predicates = [HasStdExtZdinx, IsRV32] in {
510 defm Select_FPR64IN32X : SelectCC_GPR_rrirr<FPR64IN32X, f64>;
512 def PseudoFROUND_D_IN32X : PseudoFROUND<FPR64IN32X, f64>;
515 let isCall = 0, mayLoad = 1, mayStore = 0, Size = 8, isCodeGenOnly = 1 in
516 def PseudoRV32ZdinxLD : Pseudo<(outs GPRPF64:$dst), (ins GPR:$rs1, simm12:$imm12), []>;
517 def : Pat<(f64 (load (AddrRegImmINX (XLenVT GPR:$rs1), simm12:$imm12))),
518 (PseudoRV32ZdinxLD GPR:$rs1, simm12:$imm12)>;
521 let isCall = 0, mayLoad = 0, mayStore = 1, Size = 8, isCodeGenOnly = 1 in
522 def PseudoRV32ZdinxSD : Pseudo<(outs), (ins GPRPF64:$rs2, GPRNoX0:$rs1, simm12:$imm12), []>;
523 def : Pat<(store (f64 GPRPF64:$rs2), (AddrRegImmINX (XLenVT GPR:$rs1), simm12:$imm12)),
524 (PseudoRV32ZdinxSD GPRPF64:$rs2, GPR:$rs1, simm12:$imm12)>;
526 /// Pseudo-instructions needed for the soft-float ABI with RV32D
528 // Moves two GPRs to an FPR.
529 let usesCustomInserter = 1 in
530 def BuildPairF64Pseudo_INX
531 : Pseudo<(outs FPR64IN32X:$dst), (ins GPR:$src1, GPR:$src2),
532 [(set FPR64IN32X:$dst, (RISCVBuildPairF64 GPR:$src1, GPR:$src2))]>;
534 // Moves an FPR to two GPRs.
535 let usesCustomInserter = 1 in
536 def SplitF64Pseudo_INX
537 : Pseudo<(outs GPR:$dst1, GPR:$dst2), (ins FPR64IN32X:$src),
538 [(set GPR:$dst1, GPR:$dst2, (RISCVSplitF64 FPR64IN32X:$src))]>;
539 } // Predicates = [HasStdExtZdinx, IsRV32]
541 let Predicates = [HasStdExtD] in {
543 // double->[u]int. Round-to-zero must be used.
544 def : Pat<(i32 (any_fp_to_sint FPR64:$rs1)), (FCVT_W_D FPR64:$rs1, FRM_RTZ)>;
545 def : Pat<(i32 (any_fp_to_uint FPR64:$rs1)), (FCVT_WU_D FPR64:$rs1, FRM_RTZ)>;
547 // Saturating double->[u]int32.
548 def : Pat<(i32 (riscv_fcvt_x FPR64:$rs1, timm:$frm)), (FCVT_W_D $rs1, timm:$frm)>;
549 def : Pat<(i32 (riscv_fcvt_xu FPR64:$rs1, timm:$frm)), (FCVT_WU_D $rs1, timm:$frm)>;
551 // float->int32 with current rounding mode.
552 def : Pat<(i32 (any_lrint FPR64:$rs1)), (FCVT_W_D $rs1, FRM_DYN)>;
554 // float->int32 rounded to nearest with ties rounded away from zero.
555 def : Pat<(i32 (any_lround FPR64:$rs1)), (FCVT_W_D $rs1, FRM_RMM)>;
558 def : Pat<(any_sint_to_fp (i32 GPR:$rs1)), (FCVT_D_W GPR:$rs1, FRM_RNE)>;
559 def : Pat<(any_uint_to_fp (i32 GPR:$rs1)), (FCVT_D_WU GPR:$rs1, FRM_RNE)>;
560 } // Predicates = [HasStdExtD]
562 let Predicates = [HasStdExtZdinx, IsRV32] in {
564 // double->[u]int. Round-to-zero must be used.
565 def : Pat<(i32 (any_fp_to_sint FPR64IN32X:$rs1)), (FCVT_W_D_IN32X FPR64IN32X:$rs1, FRM_RTZ)>;
566 def : Pat<(i32 (any_fp_to_uint FPR64IN32X:$rs1)), (FCVT_WU_D_IN32X FPR64IN32X:$rs1, FRM_RTZ)>;
568 // Saturating double->[u]int32.
569 def : Pat<(i32 (riscv_fcvt_x FPR64IN32X:$rs1, timm:$frm)), (FCVT_W_D_IN32X $rs1, timm:$frm)>;
570 def : Pat<(i32 (riscv_fcvt_xu FPR64IN32X:$rs1, timm:$frm)), (FCVT_WU_D_IN32X $rs1, timm:$frm)>;
572 // float->int32 with current rounding mode.
573 def : Pat<(i32 (any_lrint FPR64IN32X:$rs1)), (FCVT_W_D_IN32X $rs1, FRM_DYN)>;
575 // float->int32 rounded to nearest with ties rounded away from zero.
576 def : Pat<(i32 (any_lround FPR64IN32X:$rs1)), (FCVT_W_D_IN32X $rs1, FRM_RMM)>;
579 def : Pat<(any_sint_to_fp (i32 GPR:$rs1)), (FCVT_D_W_IN32X GPR:$rs1, FRM_RNE)>;
580 def : Pat<(any_uint_to_fp (i32 GPR:$rs1)), (FCVT_D_WU_IN32X GPR:$rs1, FRM_RNE)>;
581 } // Predicates = [HasStdExtZdinx, IsRV32]
583 let Predicates = [HasStdExtD, IsRV64] in {
585 // Moves (no conversion)
586 def : Pat<(bitconvert (i64 GPR:$rs1)), (FMV_D_X GPR:$rs1)>;
587 def : Pat<(i64 (bitconvert FPR64:$rs1)), (FMV_X_D FPR64:$rs1)>;
589 // Use target specific isd nodes to help us remember the result is sign
590 // extended. Matching sext_inreg+fptoui/fptosi may cause the conversion to be
591 // duplicated if it has another user that didn't need the sign_extend.
592 def : Pat<(riscv_any_fcvt_w_rv64 FPR64:$rs1, timm:$frm), (FCVT_W_D $rs1, timm:$frm)>;
593 def : Pat<(riscv_any_fcvt_wu_rv64 FPR64:$rs1, timm:$frm), (FCVT_WU_D $rs1, timm:$frm)>;
596 def : Pat<(any_sint_to_fp (i64 (sexti32 (i64 GPR:$rs1)))), (FCVT_D_W $rs1, FRM_RNE)>;
597 def : Pat<(any_uint_to_fp (i64 (zexti32 (i64 GPR:$rs1)))), (FCVT_D_WU $rs1, FRM_RNE)>;
599 // Saturating double->[u]int64.
600 def : Pat<(i64 (riscv_fcvt_x FPR64:$rs1, timm:$frm)), (FCVT_L_D $rs1, timm:$frm)>;
601 def : Pat<(i64 (riscv_fcvt_xu FPR64:$rs1, timm:$frm)), (FCVT_LU_D $rs1, timm:$frm)>;
603 // double->[u]int64. Round-to-zero must be used.
604 def : Pat<(i64 (any_fp_to_sint FPR64:$rs1)), (FCVT_L_D FPR64:$rs1, FRM_RTZ)>;
605 def : Pat<(i64 (any_fp_to_uint FPR64:$rs1)), (FCVT_LU_D FPR64:$rs1, FRM_RTZ)>;
607 // double->int64 with current rounding mode.
608 def : Pat<(i64 (any_lrint FPR64:$rs1)), (FCVT_L_D $rs1, FRM_DYN)>;
609 def : Pat<(i64 (any_llrint FPR64:$rs1)), (FCVT_L_D $rs1, FRM_DYN)>;
611 // double->int64 rounded to nearest with ties rounded away from zero.
612 def : Pat<(i64 (any_lround FPR64:$rs1)), (FCVT_L_D $rs1, FRM_RMM)>;
613 def : Pat<(i64 (any_llround FPR64:$rs1)), (FCVT_L_D $rs1, FRM_RMM)>;
615 // [u]int64->fp. Match GCC and default to using dynamic rounding mode.
616 def : Pat<(any_sint_to_fp (i64 GPR:$rs1)), (FCVT_D_L GPR:$rs1, FRM_DYN)>;
617 def : Pat<(any_uint_to_fp (i64 GPR:$rs1)), (FCVT_D_LU GPR:$rs1, FRM_DYN)>;
618 } // Predicates = [HasStdExtD, IsRV64]
620 let Predicates = [HasStdExtZdinx, IsRV64] in {
622 // Moves (no conversion)
623 def : Pat<(f64 (bitconvert (i64 GPR:$rs1))), (COPY_TO_REGCLASS GPR:$rs1, GPR)>;
624 def : Pat<(i64 (bitconvert (f64 GPR:$rs1))), (COPY_TO_REGCLASS GPR:$rs1, GPR)>;
626 // Use target specific isd nodes to help us remember the result is sign
627 // extended. Matching sext_inreg+fptoui/fptosi may cause the conversion to be
628 // duplicated if it has another user that didn't need the sign_extend.
629 def : Pat<(riscv_any_fcvt_w_rv64 FPR64INX:$rs1, timm:$frm), (FCVT_W_D_INX $rs1, timm:$frm)>;
630 def : Pat<(riscv_any_fcvt_wu_rv64 FPR64INX:$rs1, timm:$frm), (FCVT_WU_D_INX $rs1, timm:$frm)>;
633 def : Pat<(any_sint_to_fp (i64 (sexti32 (i64 GPR:$rs1)))), (FCVT_D_W_INX $rs1, FRM_RNE)>;
634 def : Pat<(any_uint_to_fp (i64 (zexti32 (i64 GPR:$rs1)))), (FCVT_D_WU_INX $rs1, FRM_RNE)>;
636 // Saturating double->[u]int64.
637 def : Pat<(i64 (riscv_fcvt_x FPR64INX:$rs1, timm:$frm)), (FCVT_L_D_INX $rs1, timm:$frm)>;
638 def : Pat<(i64 (riscv_fcvt_xu FPR64INX:$rs1, timm:$frm)), (FCVT_LU_D_INX $rs1, timm:$frm)>;
640 // double->[u]int64. Round-to-zero must be used.
641 def : Pat<(i64 (any_fp_to_sint FPR64INX:$rs1)), (FCVT_L_D_INX FPR64INX:$rs1, FRM_RTZ)>;
642 def : Pat<(i64 (any_fp_to_uint FPR64INX:$rs1)), (FCVT_LU_D_INX FPR64INX:$rs1, FRM_RTZ)>;
644 // double->int64 with current rounding mode.
645 def : Pat<(i64 (any_lrint FPR64INX:$rs1)), (FCVT_L_D_INX $rs1, FRM_DYN)>;
646 def : Pat<(i64 (any_llrint FPR64INX:$rs1)), (FCVT_L_D_INX $rs1, FRM_DYN)>;
648 // double->int64 rounded to nearest with ties rounded away from zero.
649 def : Pat<(i64 (any_lround FPR64INX:$rs1)), (FCVT_L_D_INX $rs1, FRM_RMM)>;
650 def : Pat<(i64 (any_llround FPR64INX:$rs1)), (FCVT_L_D_INX $rs1, FRM_RMM)>;
652 // [u]int64->fp. Match GCC and default to using dynamic rounding mode.
653 def : Pat<(any_sint_to_fp (i64 GPR:$rs1)), (FCVT_D_L_INX GPR:$rs1, FRM_DYN)>;
654 def : Pat<(any_uint_to_fp (i64 GPR:$rs1)), (FCVT_D_LU_INX GPR:$rs1, FRM_DYN)>;
655 } // Predicates = [HasStdExtZdinx, IsRV64]