@@ -51,6 +51,8 @@ def loongarch_ret : SDNode<"LoongArchISD::RET", SDTNone,
51
51
def loongarch_sll_w : SDNode<"LoongArchISD::SLL_W", SDT_LoongArchIntBinOpW>;
52
52
def loongarch_sra_w : SDNode<"LoongArchISD::SRA_W", SDT_LoongArchIntBinOpW>;
53
53
def loongarch_srl_w : SDNode<"LoongArchISD::SRL_W", SDT_LoongArchIntBinOpW>;
54
+ def loongarch_rotr_w : SDNode<"LoongArchISD::ROTR_W", SDT_LoongArchIntBinOpW>;
55
+ def loongarch_rotl_w : SDNode<"LoongArchISD::ROTL_W", SDT_LoongArchIntBinOpW>;
54
56
def loongarch_bstrins
55
57
: SDNode<"LoongArchISD::BSTRINS", SDT_LoongArchBStrIns>;
56
58
def loongarch_bstrpick
@@ -178,6 +180,12 @@ def fpimm0 : PatLeaf<(fpimm), [{return N->isExactlyValue(+0.0);}]>;
178
180
def fpimm0neg : PatLeaf<(fpimm), [{return N->isExactlyValue(-0.0);}]>;
179
181
def fpimm1 : PatLeaf<(fpimm), [{return N->isExactlyValue(+1.0);}]>;
180
182
183
+ // Return an immediate subtracted from 32.
184
+ def ImmSubFrom32 : SDNodeXForm<imm, [{
185
+ return CurDAG->getTargetConstant(32 - N->getZExtValue(), SDLoc(N),
186
+ N->getValueType(0));
187
+ }]>;
188
+
181
189
def CallSymbol: AsmOperandClass {
182
190
let Name = "CallSymbol";
183
191
let RenderMethod = "addImmOperands";
@@ -626,6 +634,8 @@ def : PatGprGpr<urem, MOD_WU>;
626
634
def : PatGprGpr<mul, MUL_W>;
627
635
def : PatGprGpr<mulhs, MULH_W>;
628
636
def : PatGprGpr<mulhu, MULH_WU>;
637
+ def : PatGprGpr<rotr, ROTR_W>;
638
+ def : PatGprImm<rotr, ROTRI_W, uimm5>;
629
639
} // Predicates = [IsLA32]
630
640
631
641
let Predicates = [IsLA64] in {
@@ -639,6 +649,14 @@ def : PatGprGpr<sdiv, DIV_D>;
639
649
def : PatGprGpr<udiv, DIV_DU>;
640
650
def : PatGprGpr<srem, MOD_D>;
641
651
def : PatGprGpr<urem, MOD_DU>;
652
+ def : PatGprGpr<rotr, ROTR_D>;
653
+ def : PatGprGpr<loongarch_rotr_w, ROTR_W>;
654
+ def : PatGprImm<rotr, ROTRI_D, uimm6>;
655
+ def : PatGprImm_32<rotr, ROTRI_W, uimm5>;
656
+ def : Pat<(loongarch_rotl_w GPR:$rj, uimm5:$imm),
657
+ (ROTRI_W GPR:$rj, (ImmSubFrom32 uimm5:$imm))>;
658
+ def : Pat<(sext_inreg (loongarch_rotl_w GPR:$rj, uimm5:$imm), i32),
659
+ (ROTRI_W GPR:$rj, (ImmSubFrom32 uimm5:$imm))>;
642
660
// TODO: Select "_W[U]" instructions for i32xi32 if only lower 32 bits of the
643
661
// product are used.
644
662
def : PatGprGpr<mul, MUL_D>;
0 commit comments