@@ -198,7 +198,7 @@ let DecoderNamespace = "XCValu" in {
198
198
199
199
} // DecoderNamespace = "XCValu"
200
200
201
- let Predicates = [HasVendorXCValu],
201
+ let Predicates = [HasVendorXCValu, IsRV32 ],
202
202
hasSideEffects = 0, mayLoad = 0, mayStore = 0 in {
203
203
// General ALU Operations
204
204
def CV_ABS : CVInstAluR<0b0101000, 0b011, "cv.abs">,
@@ -249,10 +249,10 @@ let Predicates = [HasVendorXCValu],
249
249
Sched<[]>;
250
250
def CV_SUBURN : CVInstAluRRI<0b11, 0b011, "cv.suburn">,
251
251
Sched<[]>;
252
- } // Predicates = [HasVendorXCValu],
252
+ } // Predicates = [HasVendorXCValu, IsRV32 ],
253
253
// hasSideEffects = 0, mayLoad = 0, mayStore = 0
254
254
255
- let Predicates = [HasVendorXCValu],
255
+ let Predicates = [HasVendorXCValu, IsRV32 ],
256
256
hasSideEffects = 0, mayLoad = 0, mayStore = 0,
257
257
Constraints = "$rd = $rd_wb" in {
258
258
def CV_ADDNR : CVInstAluRRNR<0b1000000, 0b011, "cv.addnr">,
@@ -272,7 +272,7 @@ let Predicates = [HasVendorXCValu],
272
272
def CV_SUBURNR : CVInstAluRRNR<0b1000111, 0b011, "cv.suburnr">,
273
273
Sched<[]>;
274
274
275
- } // Predicates = [HasVendorXCValu],
275
+ } // Predicates = [HasVendorXCValu, IsRV32 ],
276
276
// hasSideEffects = 0, mayLoad = 0, mayStore = 0,
277
277
// Constraints = "$rd = $rd_wb"
278
278
@@ -705,6 +705,8 @@ let Predicates = [HasVendorXCVmem, IsRV32], AddedComplexity = 1 in {
705
705
def cv_tuimm2 : TImmLeaf<XLenVT, [{return isUInt<2>(Imm);}]>;
706
706
def cv_tuimm5 : TImmLeaf<XLenVT, [{return isUInt<5>(Imm);}]>;
707
707
def cv_uimm10 : ImmLeaf<XLenVT, [{return isUInt<10>(Imm);}]>;
708
+ def cv_uimm_pow2: Operand<XLenVT>,
709
+ ImmLeaf<XLenVT, [{return isPowerOf2_32(Imm + 1);}]>;
708
710
709
711
def CV_LO5: SDNodeXForm<imm, [{
710
712
return CurDAG->getTargetConstant(N->getZExtValue() & 0x1f, SDLoc(N),
@@ -716,6 +718,14 @@ def CV_HI5: SDNodeXForm<imm, [{
716
718
N->getValueType(0));
717
719
}]>;
718
720
721
+ def powerOf2Minus1 : ImmLeaf<XLenVT, [{ return isPowerOf2_32(Imm+1); }]>;
722
+ def negativePowerOf2 : ImmLeaf<XLenVT, [{ return isPowerOf2_32(-Imm); }]>;
723
+ def trailing1sPlus1 : SDNodeXForm<imm, [{
724
+ return CurDAG->getTargetConstant(
725
+ llvm::countr_one(N->getZExtValue()) + 1,
726
+ SDLoc(N), N->getValueType(0));
727
+ }]>;
728
+
719
729
multiclass PatCoreVBitManip<Intrinsic intr> {
720
730
def : PatGprGpr<intr, !cast<RVInst>("CV_" # NAME # "R")>;
721
731
def : Pat<(intr GPR:$rs1, cv_uimm10:$imm),
@@ -748,8 +758,54 @@ let Predicates = [HasVendorXCVbitmanip, IsRV32] in {
748
758
def : Pat<(bitreverse (XLenVT GPR:$rs)), (CV_BITREV GPR:$rs, 0, 0)>;
749
759
}
750
760
761
+ class PatCoreVAluGpr<string intr, string asm> :
762
+ PatGpr<!cast<Intrinsic>("int_riscv_cv_alu_" # intr),
763
+ !cast<RVInst>("CV_" # asm)>;
764
+ class PatCoreVAluGprGpr <string intr, string asm> :
765
+ PatGprGpr<!cast<Intrinsic>("int_riscv_cv_alu_" # intr),
766
+ !cast<RVInst>("CV_" # asm)>;
767
+
768
+ multiclass PatCoreVAluGprImm<Intrinsic intr> {
769
+ def : PatGprGpr<intr, !cast<RVInst>("CV_" # NAME # "R")>;
770
+ def : Pat<(intr (XLenVT GPR:$rs1), powerOf2Minus1:$upperBound),
771
+ (!cast<RVInst>("CV_" # NAME) GPR:$rs1,
772
+ (trailing1sPlus1 imm:$upperBound))>;
773
+ }
774
+
775
+ multiclass PatCoreVAluGprGprImm<Intrinsic intr> {
776
+ def : Pat<(intr GPR:$rs1, GPR:$rs2, GPR:$rs3),
777
+ (!cast<RVInst>("CV_" # NAME # "R") GPR:$rs1, GPR:$rs2, GPR:$rs3)>;
778
+ def : Pat<(intr GPR:$rs1, GPR:$rs2, uimm5:$imm),
779
+ (!cast<RVInst>("CV_" # NAME) GPR:$rs1, GPR:$rs2, uimm5:$imm)>;
780
+ }
781
+
782
+ let Predicates = [HasVendorXCValu, IsRV32], AddedComplexity = 1 in {
783
+ def : PatGpr<abs, CV_ABS>;
784
+ def : PatGprGpr<setle, CV_SLET>;
785
+ def : PatGprGpr<setule, CV_SLETU>;
786
+ def : PatGprGpr<smin, CV_MIN>;
787
+ def : PatGprGpr<umin, CV_MINU>;
788
+ def : PatGprGpr<smax, CV_MAX>;
789
+ def : PatGprGpr<umax, CV_MAXU>;
790
+
791
+ def : Pat<(sext_inreg (XLenVT GPR:$rs1), i16), (CV_EXTHS GPR:$rs1)>;
792
+ def : Pat<(sext_inreg (XLenVT GPR:$rs1), i8), (CV_EXTBS GPR:$rs1)>;
793
+ def : Pat<(and (XLenVT GPR:$rs1), 0xffff), (CV_EXTHZ GPR:$rs1)>;
794
+
795
+ defm CLIP : PatCoreVAluGprImm<int_riscv_cv_alu_clip>;
796
+ defm CLIPU : PatCoreVAluGprImm<int_riscv_cv_alu_clipu>;
797
+ defm ADDN : PatCoreVAluGprGprImm<int_riscv_cv_alu_addn>;
798
+ defm ADDUN : PatCoreVAluGprGprImm<int_riscv_cv_alu_addun>;
799
+ defm ADDRN : PatCoreVAluGprGprImm<int_riscv_cv_alu_addrn>;
800
+ defm ADDURN : PatCoreVAluGprGprImm<int_riscv_cv_alu_addurn>;
801
+ defm SUBN : PatCoreVAluGprGprImm<int_riscv_cv_alu_subn>;
802
+ defm SUBUN : PatCoreVAluGprGprImm<int_riscv_cv_alu_subun>;
803
+ defm SUBRN : PatCoreVAluGprGprImm<int_riscv_cv_alu_subrn>;
804
+ defm SUBURN : PatCoreVAluGprGprImm<int_riscv_cv_alu_suburn>;
805
+ } // Predicates = [HasVendorXCValu, IsRV32]
806
+
751
807
//===----------------------------------------------------------------------===//
752
- // Patterns for immediate branching operations
808
+ // Patterns for immediate branching operations
753
809
//===----------------------------------------------------------------------===//
754
810
755
811
let Predicates = [HasVendorXCVbi, IsRV32], AddedComplexity = 2 in {
0 commit comments