diff --git a/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp b/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp --- a/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp +++ b/llvm/lib/Target/RISCV/AsmParser/RISCVAsmParser.cpp @@ -3352,16 +3352,21 @@ } unsigned DestReg = Inst.getOperand(0).getReg(); + unsigned Offset = 0; + int TiedOp = MCID.getOperandConstraint(1, MCOI::TIED_TO); + if (TiedOp == 0) + Offset = 1; + // Operands[1] will be the first operand, DestReg. SMLoc Loc = Operands[1]->getStartLoc(); if (MCID.TSFlags & RISCVII::VS2Constraint) { - unsigned CheckReg = Inst.getOperand(1).getReg(); + unsigned CheckReg = Inst.getOperand(Offset + 1).getReg(); if (DestReg == CheckReg) return Error(Loc, "The destination vector register group cannot overlap" " the source vector register group."); } - if ((MCID.TSFlags & RISCVII::VS1Constraint) && (Inst.getOperand(2).isReg())) { - unsigned CheckReg = Inst.getOperand(2).getReg(); + if ((MCID.TSFlags & RISCVII::VS1Constraint) && Inst.getOperand(Offset + 2).isReg()) { + unsigned CheckReg = Inst.getOperand(Offset + 2).getReg(); if (DestReg == CheckReg) return Error(Loc, "The destination vector register group cannot overlap" " the source vector register group."); diff --git a/llvm/lib/Target/RISCV/RISCVInstrInfoV.td b/llvm/lib/Target/RISCV/RISCVInstrInfoV.td --- a/llvm/lib/Target/RISCV/RISCVInstrInfoV.td +++ b/llvm/lib/Target/RISCV/RISCVInstrInfoV.td @@ -162,6 +162,9 @@ class SchedTernary: SchedNary; +class SchedTernaryMC: + SchedNary; // For reduction instructions. class SchedReduction: @@ -438,10 +441,14 @@ } // op vd, vs1, vs2, vm (reverse the order of vs1 and vs2) -class VALUrVV funct6, RISCVVFormat opv, string opcodestr> - : RVInstVV; +class VALUrVV funct6, RISCVVFormat opv, string opcodestr, + bit EarlyClobber = 0> + : RVInstVV { + let Constraints = !if(EarlyClobber, "@earlyclobber $vd_wb, $vd = $vd_wb", + "$vd = $vd_wb"); +} // op vd, vs2, vs1 class VALUVVNoVm funct6, RISCVVFormat opv, string opcodestr> @@ -466,10 +473,14 @@ } // op vd, rs1, vs2, vm (reverse the order of rs1 and vs2) -class VALUrVX funct6, RISCVVFormat opv, string opcodestr> - : RVInstVX; +class VALUrVX funct6, RISCVVFormat opv, string opcodestr, + bit EarlyClobber = 0> + : RVInstVX { + let Constraints = !if(EarlyClobber, "@earlyclobber $vd_wb, $vd = $vd_wb", + "$vd = $vd_wb"); +} // op vd, vs1, vs2 class VALUVXNoVm funct6, RISCVVFormat opv, string opcodestr> @@ -508,10 +519,14 @@ opcodestr, "$vd, $vs2, $rs1$vm">; // op vd, rs1, vs2, vm (Float) (with mask, reverse the order of rs1 and vs2) -class VALUrVF funct6, RISCVVFormat opv, string opcodestr> - : RVInstVX; +class VALUrVF funct6, RISCVVFormat opv, string opcodestr, + bit EarlyClobber = 0> + : RVInstVX { + let Constraints = !if(EarlyClobber, "@earlyclobber $vd_wb, $vd = $vd_wb", + "$vd = $vd_wb"); +} // op vd, vs2, vm (use vs1 as instruction encoding) class VALUVs2 funct6, bits<5> vs1, RISCVVFormat opv, string opcodestr> @@ -590,20 +605,26 @@ multiclass VMAC_MV_V_X funct6> { def V : VALUrVV, - SchedBinaryMC<"WriteVIMulAddV", "ReadVIMulAddV", "ReadVIMulAddV">; + SchedTernaryMC<"WriteVIMulAddV", "ReadVIMulAddV", "ReadVIMulAddV", + "ReadVIMulAddV">; def X : VALUrVX, - SchedBinaryMC<"WriteVIMulAddX", "ReadVIMulAddV", "ReadVIMulAddX">; + SchedTernaryMC<"WriteVIMulAddX", "ReadVIMulAddV", "ReadVIMulAddX", + "ReadVIMulAddV">; } multiclass VWMAC_MV_X funct6> { + let RVVConstraint = WidenV in def X : VALUrVX, - SchedBinaryMC<"WriteVIWMulAddX", "ReadVIWMulAddV", "ReadVIWMulAddX">; + SchedTernaryMC<"WriteVIWMulAddX", "ReadVIWMulAddV", "ReadVIWMulAddX", + "ReadVIWMulAddV">; } multiclass VWMAC_MV_V_X funct6> : VWMAC_MV_X { - def V : VALUrVV, - SchedBinaryMC<"WriteVIWMulAddV", "ReadVIWMulAddV", "ReadVIWMulAddV">; + let RVVConstraint = WidenV in + def V : VALUrVV, + SchedTernaryMC<"WriteVIWMulAddV", "ReadVIWMulAddV", "ReadVIWMulAddV", + "ReadVIWMulAddV">; } multiclass VALU_MV_VS2 funct6, bits<5> vs1> { @@ -693,16 +714,22 @@ multiclass VMAC_FV_V_F funct6> { def V : VALUrVV, - SchedBinaryMC<"WriteVFMulAddV", "ReadVFMulAddV", "ReadVFMulAddV">; + SchedTernaryMC<"WriteVFMulAddV", "ReadVFMulAddV", "ReadVFMulAddV", + "ReadVFMulAddV">; def F : VALUrVF, - SchedBinaryMC<"WriteVFMulAddF", "ReadVFMulAddV", "ReadVFMulAddF">; + SchedTernaryMC<"WriteVFMulAddF", "ReadVFMulAddV", "ReadVFMulAddF", + "ReadVFMulAddV">; } multiclass VWMAC_FV_V_F funct6> { - def V : VALUrVV, - SchedBinaryMC<"WriteVFWMulAddV", "ReadVFWMulAddV", "ReadVFWMulAddV">; - def F : VALUrVF, - SchedBinaryMC<"WriteVFWMulAddF", "ReadVFWMulAddV", "ReadVFWMulAddF">; + let RVVConstraint = WidenV in { + def V : VALUrVV, + SchedTernaryMC<"WriteVFWMulAddV", "ReadVFWMulAddV", "ReadVFWMulAddV", + "ReadVFWMulAddV">; + def F : VALUrVF, + SchedTernaryMC<"WriteVFWMulAddF", "ReadVFWMulAddV", "ReadVFWMulAddF", + "ReadVFWMulAddV">; + } } multiclass VSQR_FV_VS2 funct6, bits<5> vs1> { @@ -1289,12 +1316,10 @@ defm VNMSUB_V : VMAC_MV_V_X<"vnmsub", 0b101011>; // Vector Widening Integer Multiply-Add Instructions -let Constraints = "@earlyclobber $vd", RVVConstraint = WidenV in { defm VWMACCU_V : VWMAC_MV_V_X<"vwmaccu", 0b111100>; defm VWMACC_V : VWMAC_MV_V_X<"vwmacc", 0b111101>; defm VWMACCSU_V : VWMAC_MV_V_X<"vwmaccsu", 0b111111>; defm VWMACCUS_V : VWMAC_MV_X<"vwmaccus", 0b111110>; -} // Constraints = "@earlyclobber $vd", RVVConstraint = WidenV // Vector Integer Merge Instructions defm VMERGE_V : VMRG_IV_V_X_I<"vmerge", 0b010111>; @@ -1394,8 +1419,7 @@ } // Vector Widening Floating-Point Fused Multiply-Add Instructions -let Constraints = "@earlyclobber $vd", RVVConstraint = WidenV, - Uses = [FRM], mayRaiseFPException = true in { +let Uses = [FRM], mayRaiseFPException = true in { defm VFWMACC_V : VWMAC_FV_V_F<"vfwmacc", 0b111100>; defm VFWNMACC_V : VWMAC_FV_V_F<"vfwnmacc", 0b111101>; defm VFWMSAC_V : VWMAC_FV_V_F<"vfwmsac", 0b111110>; diff --git a/llvm/lib/Target/RISCV/RISCVInstrInfoVPseudos.td b/llvm/lib/Target/RISCV/RISCVInstrInfoVPseudos.td --- a/llvm/lib/Target/RISCV/RISCVInstrInfoVPseudos.td +++ b/llvm/lib/Target/RISCV/RISCVInstrInfoVPseudos.td @@ -3138,8 +3138,8 @@ SchedTernary<"WriteVIMulAddV", "ReadVIMulAddV", "ReadVIMulAddV", "ReadVIMulAddV", mx>; defm "" : VPseudoTernaryV_VX_AAXA, - SchedTernary<"WriteVIMulAddX", "ReadVIMulAddV", "ReadVIMulAddV", - "ReadVIMulAddX", mx>; + SchedTernary<"WriteVIMulAddX", "ReadVIMulAddV", "ReadVIMulAddX", + "ReadVIMulAddV", mx>; } } @@ -3153,8 +3153,8 @@ foreach f = FPList in { foreach m = f.MxList in { defm "" : VPseudoTernaryV_VF_AAXA, - SchedTernary<"WriteVFMulAddF", "ReadVFMulAddV", "ReadVFMulAddV", - "ReadVFMulAddF", m.MX>; + SchedTernary<"WriteVFMulAddF", "ReadVFMulAddV", "ReadVFMulAddF", + "ReadVFMulAddV", m.MX>; } } } @@ -3169,8 +3169,8 @@ foreach f = FPList in { foreach m = f.MxList in { defm "" : VPseudoTernaryV_VF_AAXA_RM, - SchedTernary<"WriteVFMulAddF", "ReadVFMulAddV", "ReadVFMulAddV", - "ReadVFMulAddF", m.MX>; + SchedTernary<"WriteVFMulAddF", "ReadVFMulAddV", "ReadVFMulAddF", + "ReadVFMulAddV", m.MX>; } } } @@ -3193,16 +3193,16 @@ SchedTernary<"WriteVIWMulAddV", "ReadVIWMulAddV", "ReadVIWMulAddV", "ReadVIWMulAddV", mx>; defm "" : VPseudoTernaryW_VX, - SchedTernary<"WriteVIWMulAddX", "ReadVIWMulAddV", "ReadVIWMulAddV", - "ReadVIWMulAddX", mx>; + SchedTernary<"WriteVIWMulAddX", "ReadVIWMulAddV", "ReadVIWMulAddX", + "ReadVIWMulAddV", mx>; } } multiclass VPseudoVWMAC_VX { foreach m = MxListW in { defm "" : VPseudoTernaryW_VX, - SchedTernary<"WriteVIWMulAddX", "ReadVIWMulAddV", "ReadVIWMulAddV", - "ReadVIWMulAddX", m.MX>; + SchedTernary<"WriteVIWMulAddX", "ReadVIWMulAddV", "ReadVIWMulAddX", + "ReadVIWMulAddV", m.MX>; } } @@ -3217,7 +3217,7 @@ foreach m = f.MxListFW in { defm "" : VPseudoTernaryW_VF_RM, SchedTernary<"WriteVFWMulAddF", "ReadVFWMulAddV", - "ReadVFWMulAddV", "ReadVFWMulAddF", m.MX>; + "ReadVFWMulAddF", "ReadVFWMulAddV", m.MX>; } } } @@ -3242,7 +3242,7 @@ defm "" : VPseudoTernaryW_VF_BF_RM, Sched<[WriteVFWMulAddF_MX, ReadVFWMulAddV_MX, - ReadVFWMulAddV_MX, ReadVFWMulAddF_MX, ReadVMask]>; + ReadVFWMulAddF_MX, ReadVFWMulAddV_MX, ReadVMask]>; } } } diff --git a/llvm/lib/Target/RISCV/RISCVInstrInfoXTHead.td b/llvm/lib/Target/RISCV/RISCVInstrInfoXTHead.td --- a/llvm/lib/Target/RISCV/RISCVInstrInfoXTHead.td +++ b/llvm/lib/Target/RISCV/RISCVInstrInfoXTHead.td @@ -56,16 +56,24 @@ let hasSideEffects = 0, mayLoad = 0, mayStore = 0 in { // op vd, vs1, vs2, vm (reverse the order of vs1 and vs2) -class THVdotALUrVV funct6, RISCVVFormat opv, string opcodestr> - : THInstVdotVV; +class THVdotALUrVV funct6, RISCVVFormat opv, string opcodestr, + bit EarlyClobber> + : THInstVdotVV { + let Constraints = !if(EarlyClobber, "@earlyclobber $vd_wb, $vd = $vd_wb", + "$vd = $vd_wb"); +} // op vd, rs1, vs2, vm (reverse the order of rs1 and vs2) -class THVdotALUrVX funct6, RISCVVFormat opv, string opcodestr> - : THInstVdotVX; +class THVdotALUrVX funct6, RISCVVFormat opv, string opcodestr, + bit EarlyClobber> + : THInstVdotVX { + let Constraints = !if(EarlyClobber, "@earlyclobber $vd_wb, $vd = $vd_wb", + "$vd = $vd_wb"); +} } // hasSideEffects = 0, mayLoad = 0, mayStore = 0 let Predicates = [HasVendorXTHeadBa], DecoderNamespace = "XTHeadBa", @@ -227,12 +235,14 @@ //===----------------------------------------------------------------------===// multiclass THVdotVMAQA_VX funct6> { - def _VX : THVdotALUrVX; + let RVVConstraint = WidenV in + def _VX : THVdotALUrVX; } -multiclass THVdotVMAQA funct6> { - def _VV : THVdotALUrVV; - defm "" : THVdotVMAQA_VX; +multiclass THVdotVMAQA funct6> + : THVdotVMAQA_VX { + let RVVConstraint = WidenV in + def _VV : THVdotALUrVV; } //===----------------------------------------------------------------------===// @@ -448,9 +458,7 @@ Sched<[WriteFST64, ReadFStoreData, ReadFMemBase]>; } -let Predicates = [HasVendorXTHeadVdot], - Constraints = "@earlyclobber $vd", - RVVConstraint = WidenV in { +let Predicates = [HasVendorXTHeadVdot] in { defm THVdotVMAQA : THVdotVMAQA<"th.vmaqa", 0b100000>; defm THVdotVMAQAU : THVdotVMAQA<"th.vmaqau", 0b100010>; defm THVdotVMAQASU : THVdotVMAQA<"th.vmaqasu", 0b100100>; diff --git a/llvm/lib/Target/RISCV/RISCVInstrInfoZvfbf.td b/llvm/lib/Target/RISCV/RISCVInstrInfoZvfbf.td --- a/llvm/lib/Target/RISCV/RISCVInstrInfoZvfbf.td +++ b/llvm/lib/Target/RISCV/RISCVInstrInfoZvfbf.td @@ -25,7 +25,8 @@ defm VFNCVTBF16_F_F_W : VNCVTF_FV_VS2<"vfncvtbf16.f.f.w", 0b010010, 0b11101>; } -let Predicates = [HasStdExtZvfbfwma], Constraints = "@earlyclobber $vd", +let Predicates = [HasStdExtZvfbfwma], + Constraints = "@earlyclobber $vd_wb, $vd = $vd_wb", RVVConstraint = WidenV, Uses = [FRM], mayRaiseFPException = true in { defm VFWMACCBF16_V : VWMAC_FV_V_F<"vfwmaccbf16", 0b111011>; }