[turbofan] Combine Word32And with Int32Add and negative power of two.

TEST=unittests
R=jarin@chromium.org

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

Cr-Commit-Position: refs/heads/master@{#25479}
This commit is contained in:
Benedikt Meurer 2014-11-24 13:30:20 +01:00
parent 1d0d520e77
commit 94f5b78b96
3 changed files with 36 additions and 0 deletions

View File

@ -137,6 +137,19 @@ Reduction MachineOperatorReducer::Reduce(Node* node) {
return Changed(node);
}
}
if (m.left().IsInt32Add() && m.right().IsNegativePowerOf2()) {
Int32BinopMatcher mleft(m.left().node());
if (mleft.right().HasValue() &&
(mleft.right().Value() & m.right().Value()) ==
mleft.right().Value()) {
// (x + K) & K => (x & K) + K
return Replace(graph()->NewNode(
machine()->Int32Add(),
graph()->NewNode(machine()->Word32And(), mleft.left().node(),
m.right().node()),
mleft.right().node()));
}
}
break;
}
case IrOpcode::kWord32Or: {

View File

@ -80,6 +80,10 @@ struct IntMatcher FINAL : public ValueMatcher<T, kOpcode> {
return this->HasValue() && this->Value() > 0 &&
(this->Value() & (this->Value() - 1)) == 0;
}
bool IsNegativePowerOf2() const {
return this->HasValue() && this->Value() < 0 &&
(-this->Value() & (-this->Value() - 1)) == 0;
}
};
typedef IntMatcher<int32_t, IrOpcode::kInt32Constant> Int32Matcher;

View File

@ -526,6 +526,25 @@ TEST_F(MachineOperatorReducerTest, Word32AndWithWord32AndWithConstant) {
}
TEST_F(MachineOperatorReducerTest, Word32AndWithInt32AddAndConstant) {
Node* const p0 = Parameter(0);
TRACED_FOREACH(int32_t, k, kInt32Values) {
TRACED_FORRANGE(int32_t, l, 1, 31) {
// (x + (K << L)) & (-1 << L) => (x & (-1 << L)) + (K << L)
Reduction const r = Reduce(graph()->NewNode(
machine()->Word32And(),
graph()->NewNode(machine()->Int32Add(), p0, Int32Constant(k << l)),
Int32Constant(-1 << l)));
ASSERT_TRUE(r.Changed());
EXPECT_THAT(r.replacement(),
IsInt32Add(IsWord32And(p0, IsInt32Constant(-1 << l)),
IsInt32Constant(k << l)));
}
}
}
// -----------------------------------------------------------------------------
// Word32Xor