Commit e1c2c901 authored by Benedikt Meurer's avatar Benedikt Meurer

[turbofan] Strength reduction of Word32And with Int32Mul.

- (x * (K << L)) & (-1 << L) => x * (K << L)
- ((K << L) * x) & (-1 << L) => x * (K << L)

R=dcarney@chromium.org

Review URL: https://codereview.chromium.org/972653002

Cr-Commit-Position: refs/heads/master@{#26942}
parent 7ee31a23
......@@ -906,6 +906,12 @@ Reduction MachineOperatorReducer::ReduceWord32And(Node* node) {
return reduction.Changed() ? reduction : Changed(node);
}
}
} else if (m.left().IsInt32Mul()) {
Int32BinopMatcher mleft(m.left().node());
if (mleft.right().IsMultipleOf(-mask)) {
// (x * (K << L)) & (-1 << L) => x * (K << L)
return Replace(mleft.node());
}
}
}
return NoChange();
......
......@@ -616,6 +616,33 @@ TEST_F(MachineOperatorReducerTest, Word32AndWithInt32AddAndConstant) {
}
TEST_F(MachineOperatorReducerTest, Word32AndWithInt32MulAndConstant) {
Node* const p0 = Parameter(0);
TRACED_FORRANGE(int32_t, l, 1, 31) {
TRACED_FOREACH(int32_t, k, kInt32Values) {
if ((k << l) == 0) continue;
// (x * (K << L)) & (-1 << L) => x * (K << L)
Reduction const r1 = Reduce(graph()->NewNode(
machine()->Word32And(),
graph()->NewNode(machine()->Int32Mul(), p0, Int32Constant(k << l)),
Int32Constant(-1 << l)));
ASSERT_TRUE(r1.Changed());
EXPECT_THAT(r1.replacement(), IsInt32Mul(p0, IsInt32Constant(k << l)));
// ((K << L) * x) & (-1 << L) => x * (K << L)
Reduction const r2 = Reduce(graph()->NewNode(
machine()->Word32And(),
graph()->NewNode(machine()->Int32Mul(), Int32Constant(k << l), p0),
Int32Constant(-1 << l)));
ASSERT_TRUE(r2.Changed());
EXPECT_THAT(r2.replacement(), IsInt32Mul(p0, IsInt32Constant(k << l)));
}
}
}
TEST_F(MachineOperatorReducerTest,
Word32AndWithInt32AddAndInt32MulAndConstant) {
Node* const p0 = Parameter(0);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment