@@ -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,15 @@ def CV_HI5: SDNodeXForm<imm, [{
716
718
N->getValueType(0));
717
719
}]>;
718
720
721
+ def powerOf2 : ImmLeaf<XLenVT, [{ return isPowerOf2_32(Imm); }]>;
722
+ def powerOf2Minus1 : ImmLeaf<XLenVT, [{ return isPowerOf2_32(Imm+1); }]>;
723
+ def negativePowerOf2 : ImmLeaf<XLenVT, [{ return isPowerOf2_32(-Imm); }]>;
724
+ def trailing1sPlus1 : SDNodeXForm<imm, [{
725
+ return CurDAG->getTargetConstant(
726
+ llvm::countr_one(N->getZExtValue()) + 1,
727
+ SDLoc(N), N->getValueType(0));
728
+ }]>;
729
+
719
730
multiclass PatCoreVBitManip<Intrinsic intr> {
720
731
def : PatGprGpr<intr, !cast<RVInst>("CV_" # NAME # "R")>;
721
732
def : Pat<(intr GPR:$rs1, cv_uimm10:$imm),
@@ -748,8 +759,54 @@ let Predicates = [HasVendorXCVbitmanip, IsRV32] in {
748
759
def : Pat<(bitreverse (XLenVT GPR:$rs)), (CV_BITREV GPR:$rs, 0, 0)>;
749
760
}
750
761
762
+ class PatCoreVAluGpr<string intr, string asm> :
763
+ PatGpr<!cast<Intrinsic>("int_riscv_cv_alu_" # intr),
764
+ !cast<RVInst>("CV_" # asm)>;
765
+ class PatCoreVAluGprGpr <string intr, string asm> :
766
+ PatGprGpr<!cast<Intrinsic>("int_riscv_cv_alu_" # intr),
767
+ !cast<RVInst>("CV_" # asm)>;
768
+
769
+ multiclass PatCoreVAluGprImm<Intrinsic intr> {
770
+ def : PatGprGpr<intr, !cast<RVInst>("CV_" # NAME # "R")>;
771
+ def : Pat<(intr (XLenVT GPR:$rs1), powerOf2Minus1:$upperBound),
772
+ (!cast<RVInst>("CV_" # NAME) GPR:$rs1,
773
+ (trailing1sPlus1 imm:$upperBound))>;
774
+ }
775
+
776
+ multiclass PatCoreVAluGprGprImm<Intrinsic intr> {
777
+ def : Pat<(intr GPR:$rs1, GPR:$rs2, GPR:$rs3),
778
+ (!cast<RVInst>("CV_" # NAME # "R") GPR:$rs1, GPR:$rs2, GPR:$rs3)>;
779
+ def : Pat<(intr GPR:$rs1, GPR:$rs2, uimm5:$imm),
780
+ (!cast<RVInst>("CV_" # NAME) GPR:$rs1, GPR:$rs2, uimm5:$imm)>;
781
+ }
782
+
783
+ let Predicates = [HasVendorXCValu, IsRV32], AddedComplexity = 1 in {
784
+ def : PatGpr<abs, CV_ABS>;
785
+ def : PatGprGpr<setle, CV_SLET>;
786
+ def : PatGprGpr<setule, CV_SLETU>;
787
+ def : PatGprGpr<smin, CV_MIN>;
788
+ def : PatGprGpr<umin, CV_MINU>;
789
+ def : PatGprGpr<smax, CV_MAX>;
790
+ def : PatGprGpr<umax, CV_MAXU>;
791
+
792
+ def : Pat<(sext_inreg (XLenVT GPR:$rs1), i16), (CV_EXTHS GPR:$rs1)>;
793
+ def : Pat<(sext_inreg (XLenVT GPR:$rs1), i8), (CV_EXTBS GPR:$rs1)>;
794
+ def : Pat<(and (XLenVT GPR:$rs1), 0xffff), (CV_EXTHZ GPR:$rs1)>;
795
+
796
+ defm CLIP : PatCoreVAluGprImm<int_riscv_cv_alu_clip>;
797
+ defm CLIPU : PatCoreVAluGprImm<int_riscv_cv_alu_clipu>;
798
+ defm ADDN : PatCoreVAluGprGprImm<int_riscv_cv_alu_addn>;
799
+ defm ADDUN : PatCoreVAluGprGprImm<int_riscv_cv_alu_addun>;
800
+ defm ADDRN : PatCoreVAluGprGprImm<int_riscv_cv_alu_addrn>;
801
+ defm ADDURN : PatCoreVAluGprGprImm<int_riscv_cv_alu_addurn>;
802
+ defm SUBN : PatCoreVAluGprGprImm<int_riscv_cv_alu_subn>;
803
+ defm SUBUN : PatCoreVAluGprGprImm<int_riscv_cv_alu_subun>;
804
+ defm SUBRN : PatCoreVAluGprGprImm<int_riscv_cv_alu_subrn>;
805
+ defm SUBURN : PatCoreVAluGprGprImm<int_riscv_cv_alu_suburn>;
806
+ } // Predicates = [HasVendorXCValu, IsRV32]
807
+
751
808
//===----------------------------------------------------------------------===//
752
- // Patterns for immediate branching operations
809
+ // Patterns for immediate branching operations
753
810
//===----------------------------------------------------------------------===//
754
811
755
812
let Predicates = [HasVendorXCVbi, IsRV32], AddedComplexity = 2 in {
0 commit comments