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