Index: src/compiler/mips/instruction-selector-mips.cc |
diff --git a/src/compiler/mips/instruction-selector-mips.cc b/src/compiler/mips/instruction-selector-mips.cc |
index 961213afee9401e190ee85506e0e81f672ca43c5..9df0af6cb989f264532ea4e228bc77c9ffcdecf4 100644 |
--- a/src/compiler/mips/instruction-selector-mips.cc |
+++ b/src/compiler/mips/instruction-selector-mips.cc |
@@ -252,6 +252,38 @@ void InstructionSelector::VisitStore(Node* node) { |
void InstructionSelector::VisitWord32And(Node* node) { |
+ MipsOperandGenerator g(this); |
+ Int32BinopMatcher m(node); |
+ if (m.left().IsWord32Shr() && CanCover(node, m.left().node()) && |
+ m.right().HasValue()) { |
+ uint32_t mask = m.right().Value(); |
+ uint32_t mask_width = base::bits::CountPopulation32(mask); |
+ uint32_t mask_msb = base::bits::CountLeadingZeros32(mask); |
+ if ((mask_width != 0) && (mask_msb + mask_width == 32)) { |
+ // The mask must be contiguous, and occupy the least-significant bits. |
+ DCHECK_EQ(0u, base::bits::CountTrailingZeros32(mask)); |
+ |
+ // Select Ext for And(Shr(x, imm), mask) where the mask is in the least |
+ // significant bits. |
+ Int32BinopMatcher mleft(m.left().node()); |
+ if (mleft.right().HasValue()) { |
+ // Any shift value can match; int32 shifts use `value % 32`. |
+ uint32_t lsb = mleft.right().Value() & 0x1f; |
+ |
+ // Ext cannot extract bits past the register size, however since |
+ // shifting the original value would have introduced some zeros we can |
+ // still use Ext with a smaller mask and the remaining bits will be |
+ // zeros. |
+ if (lsb + mask_width > 32) mask_width = 32 - lsb; |
+ |
+ Emit(kMipsExt, g.DefineAsRegister(node), |
+ g.UseRegister(mleft.left().node()), g.TempImmediate(lsb), |
+ g.TempImmediate(mask_width)); |
+ return; |
+ } |
+ // Other cases fall through to the normal And operation. |
+ } |
+ } |
VisitBinop(this, node, kMipsAnd); |
} |
@@ -272,6 +304,26 @@ void InstructionSelector::VisitWord32Shl(Node* node) { |
void InstructionSelector::VisitWord32Shr(Node* node) { |
+ Int32BinopMatcher m(node); |
+ if (m.left().IsWord32And() && m.right().HasValue()) { |
+ uint32_t lsb = m.right().Value() & 0x1f; |
+ Int32BinopMatcher mleft(m.left().node()); |
+ if (mleft.right().HasValue()) { |
+ // Select Ext for Shr(And(x, mask), imm) where the result of the mask is |
+ // shifted into the least-significant bits. |
+ uint32_t mask = (mleft.right().Value() >> lsb) << lsb; |
+ unsigned mask_width = base::bits::CountPopulation32(mask); |
+ unsigned mask_msb = base::bits::CountLeadingZeros32(mask); |
+ if ((mask_msb + mask_width + lsb) == 32) { |
+ MipsOperandGenerator g(this); |
+ DCHECK_EQ(lsb, base::bits::CountTrailingZeros32(mask)); |
+ Emit(kMipsExt, g.DefineAsRegister(node), |
+ g.UseRegister(mleft.left().node()), g.TempImmediate(lsb), |
+ g.TempImmediate(mask_width)); |
+ return; |
+ } |
+ } |
+ } |
VisitRRO(this, kMipsShr, node); |
} |