@@ -44,6 +44,10 @@ multiclass ComparisonInt<CondCode cond, string name, bits<32> i32Inst, bits<32>
4444 !strconcat("i64.", name), i64Inst>;
4545}
4646
47+ // ComplexPattern
48+ def shiftMask32 : ComplexPattern<i32, 1, "selectShiftMask32", [], [], 0>;
49+ def shiftMask64 : ComplexPattern<i64, 1, "selectShiftMask64", [], [], 0>;
50+
4751// The spaces after the names are for aesthetic purposes only, to make
4852// operands line up vertically after tab expansion.
4953let isCommutable = 1 in
@@ -94,26 +98,19 @@ defm EQZ_I64 : I<(outs I32:$dst), (ins I64:$src), (outs), (ins),
9498 "i64.eqz \t$dst, $src", "i64.eqz", 0x50>;
9599
96100// Optimize away an explicit mask on a shift count.
97- def : Pat<(shl I32:$lhs, (and I32:$rhs, 31 )), (SHL_I32 I32:$lhs, I32:$rhs)>;
98- def : Pat<(sra I32:$lhs, (and I32:$rhs, 31 )), (SHR_S_I32 I32:$lhs, I32:$rhs)>;
99- def : Pat<(srl I32:$lhs, (and I32:$rhs, 31 )), (SHR_U_I32 I32:$lhs, I32:$rhs)>;
100- def : Pat<(shl I64:$lhs, (and I64:$rhs, 63 )), (SHL_I64 I64:$lhs, I64:$rhs)>;
101- def : Pat<(sra I64:$lhs, (and I64:$rhs, 63 )), (SHR_S_I64 I64:$lhs, I64:$rhs)>;
102- def : Pat<(srl I64:$lhs, (and I64:$rhs, 63 )), (SHR_U_I64 I64:$lhs, I64:$rhs)>;
101+ def : Pat<(shl I32:$lhs, (shiftMask32 I32:$rhs)), (SHL_I32 I32:$lhs, I32:$rhs)>;
102+ def : Pat<(sra I32:$lhs, (shiftMask32 I32:$rhs)), (SHR_S_I32 I32:$lhs, I32:$rhs)>;
103+ def : Pat<(srl I32:$lhs, (shiftMask32 I32:$rhs)), (SHR_U_I32 I32:$lhs, I32:$rhs)>;
104+ def : Pat<(shl I64:$lhs, (shiftMask64 I64:$rhs)), (SHL_I64 I64:$lhs, I64:$rhs)>;
105+ def : Pat<(sra I64:$lhs, (shiftMask64 I64:$rhs)), (SHR_S_I64 I64:$lhs, I64:$rhs)>;
106+ def : Pat<(srl I64:$lhs, (shiftMask64 I64:$rhs)), (SHR_U_I64 I64:$lhs, I64:$rhs)>;
103107
104108// Optimize away an explicit mask on a rotate count.
105109def : Pat<(rotl I32:$lhs, (and I32:$rhs, 31)), (ROTL_I32 I32:$lhs, I32:$rhs)>;
106110def : Pat<(rotr I32:$lhs, (and I32:$rhs, 31)), (ROTR_I32 I32:$lhs, I32:$rhs)>;
107111def : Pat<(rotl I64:$lhs, (and I64:$rhs, 63)), (ROTL_I64 I64:$lhs, I64:$rhs)>;
108112def : Pat<(rotr I64:$lhs, (and I64:$rhs, 63)), (ROTR_I64 I64:$lhs, I64:$rhs)>;
109113
110- def : Pat<(shl I64:$lhs, (zext (and I32:$rhs, 63))),
111- (SHL_I64 I64:$lhs, (I64_EXTEND_U_I32 I32:$rhs))>;
112- def : Pat<(sra I64:$lhs, (zext (and I32:$rhs, 63))),
113- (SHR_S_I64 I64:$lhs, (I64_EXTEND_U_I32 I32:$rhs))>;
114- def : Pat<(srl I64:$lhs, (zext (and I32:$rhs, 63))),
115- (SHR_U_I64 I64:$lhs, (I64_EXTEND_U_I32 I32:$rhs))>;
116-
117114defm SELECT_I32 : I<(outs I32:$dst), (ins I32:$lhs, I32:$rhs, I32:$cond),
118115 (outs), (ins),
119116 [(set I32:$dst, (select I32:$cond, I32:$lhs, I32:$rhs))],
0 commit comments