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 @@ -3361,16 +3361,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 @@ -327,10 +327,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> @@ -355,10 +359,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> @@ -397,10 +405,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> @@ -485,21 +497,23 @@ multiclass VMAC_MV_V_X funct6> { def V : VALUrVV, Sched<[WriteVIMulAddV_WorstCase, ReadVIMulAddV_WorstCase, - ReadVIMulAddV_WorstCase, ReadVMask]>; + ReadVIMulAddV_WorstCase, ReadVIMulAddV_WorstCase, ReadVMask]>; def X : VALUrVX, Sched<[WriteVIMulAddX_WorstCase, ReadVIMulAddV_WorstCase, - ReadVIMulAddX_WorstCase, ReadVMask]>; + ReadVIMulAddX_WorstCase, ReadVIMulAddV_WorstCase, ReadVMask]>; } multiclass VWMAC_MV_X funct6> { - def X : VALUrVX, + let RVVConstraint = WidenV in + def X : VALUrVX, Sched<[WriteVIWMulAddX_WorstCase, ReadVIWMulAddV_WorstCase, ReadVIWMulAddX_WorstCase, ReadVMask]>; } multiclass VWMAC_MV_V_X funct6> : VWMAC_MV_X { - def V : VALUrVV, + let RVVConstraint = WidenV in + def V : VALUrVV, Sched<[WriteVIWMulAddV_WorstCase, ReadVIWMulAddV_WorstCase, ReadVIWMulAddV_WorstCase, ReadVMask]>; } @@ -608,19 +622,21 @@ multiclass VMAC_FV_V_F funct6> { def V : VALUrVV, Sched<[WriteVFMulAddV_WorstCase, ReadVFMulAddV_WorstCase, - ReadVFMulAddV_WorstCase, ReadVMask]>; + ReadVFMulAddV_WorstCase, ReadVFMulAddV_WorstCase, ReadVMask]>; def F : VALUrVF, Sched<[WriteVFMulAddF_WorstCase, ReadVFMulAddV_WorstCase, - ReadVFMulAddF_WorstCase, ReadVMask]>; + ReadVFMulAddF_WorstCase, ReadVFMulAddV_WorstCase, ReadVMask]>; } multiclass VWMAC_FV_V_F funct6> { - def V : VALUrVV, + let RVVConstraint = WidenV in { + def V : VALUrVV, Sched<[WriteVFWMulAddV_WorstCase, ReadVFWMulAddV_WorstCase, - ReadVFWMulAddV_WorstCase, ReadVMask]>; - def F : VALUrVF, + ReadVFWMulAddV_WorstCase, ReadVFWMulAddV_WorstCase, ReadVMask]>; + def F : VALUrVF, Sched<[WriteVFWMulAddF_WorstCase, ReadVFWMulAddV_WorstCase, - ReadVFWMulAddF_WorstCase, ReadVMask]>; + ReadVFWMulAddF_WorstCase, ReadVFWMulAddV_WorstCase, ReadVMask]>; + } } multiclass VSQR_FV_VS2 funct6, bits<5> vs1> { @@ -1256,12 +1272,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>; @@ -1361,8 +1375,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 @@ -3080,19 +3080,20 @@ multiclass VPseudoTernaryW_VV { defvar constraint = "@earlyclobber $rd"; defm _VV : VPseudoTernaryWithPolicy; + constraint, /*Commutable*/0>; } multiclass VPseudoTernaryW_VX { defvar constraint = "@earlyclobber $rd"; defm "_VX" : VPseudoTernaryWithPolicy; + constraint, /*Commutable*/0>; } multiclass VPseudoTernaryW_VF { defvar constraint = "@earlyclobber $rd"; defm "_V" # f.FX : VPseudoTernaryWithPolicy; + m.vrclass, m, constraint, + /*Commutable*/0>; } multiclass VPseudoVSLDVWithPolicy; defm "" : VPseudoTernaryV_VX_AAXA, - Sched<[WriteVIMulAddX_MX, ReadVIMulAddV_MX, ReadVIMulAddV_MX, - ReadVIMulAddX_MX, ReadVMask]>; + Sched<[WriteVIMulAddX_MX, ReadVIMulAddV_MX, ReadVIMulAddX_MX, + ReadVIMulAddV_MX, ReadVMask]>; } } @@ -3149,7 +3150,7 @@ defvar ReadVFMulAddF_MX = !cast("ReadVFMulAddF_" # mx); defm "" : VPseudoTernaryV_VF_AAXA, - Sched<[WriteVFMulAddF_MX, ReadVFMulAddV_MX, ReadVFMulAddV_MX, ReadVFMulAddF_MX, ReadVMask]>; + Sched<[WriteVFMulAddF_MX, ReadVFMulAddV_MX, ReadVFMulAddF_MX, ReadVFMulAddV_MX, ReadVMask]>; } } } @@ -3182,8 +3183,8 @@ Sched<[WriteVIWMulAddV_MX, ReadVIWMulAddV_MX, ReadVIWMulAddV_MX, ReadVIWMulAddV_MX, ReadVMask]>; defm "" : VPseudoTernaryW_VX, - Sched<[WriteVIWMulAddX_MX, ReadVIWMulAddV_MX, ReadVIWMulAddV_MX, - ReadVIWMulAddX_MX, ReadVMask]>; + Sched<[WriteVIWMulAddX_MX, ReadVIWMulAddV_MX, ReadVIWMulAddX_MX, + ReadVIWMulAddV_MX, ReadVMask]>; } } @@ -3195,8 +3196,8 @@ defvar ReadVIWMulAddX_MX = !cast("ReadVIWMulAddX_" # mx); defm "" : VPseudoTernaryW_VX, - Sched<[WriteVIWMulAddX_MX, ReadVIWMulAddV_MX, ReadVIWMulAddV_MX, - ReadVIWMulAddX_MX, ReadVMask]>; + Sched<[WriteVIWMulAddX_MX, ReadVIWMulAddV_MX, ReadVIWMulAddX_MX, + ReadVIWMulAddV_MX, ReadVMask]>; } } @@ -3220,7 +3221,7 @@ defm "" : VPseudoTernaryW_VF, 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 @@ -51,16 +51,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 = "THeadBa", @@ -221,12 +229,14 @@ // Use these multiclasses to define instructions more easily. //===----------------------------------------------------------------------===// 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; } //===----------------------------------------------------------------------===// @@ -443,9 +453,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", 0b100011>; }