[turbofan] Optimize Uint32LessThan with Word32Sar.

TEST=unittests
R=jarin@chromium.org

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

git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@24520 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
This commit is contained in:
bmeurer@chromium.org 2014-10-10 10:23:04 +00:00
parent 52575220d4
commit 059e4c206e
4 changed files with 40 additions and 0 deletions

View File

@ -339,6 +339,20 @@ Reduction MachineOperatorReducer::Reduce(Node* node) {
return ReplaceBool(m.left().Value() < m.right().Value());
}
if (m.LeftEqualsRight()) return ReplaceBool(false); // x < x => false
if (m.left().IsWord32Sar() && m.right().HasValue()) {
Int32BinopMatcher mleft(m.left().node());
if (mleft.right().HasValue()) {
// (x >> K) < C => x < (C << K) | (2^K - 1)
// when C < (M >> K)
const uint32_t c = m.right().Value();
const uint32_t k = mleft.right().Value() & 0x1f;
if (c < static_cast<uint32_t>(kMaxInt >> k)) {
node->ReplaceInput(0, mleft.left().node());
node->ReplaceInput(1, Uint32Constant((c << k) | ((1 << k) - 1)));
return Changed(node);
}
}
}
break;
}
case IrOpcode::kUint32LessThanOrEqual: {

View File

@ -949,6 +949,7 @@ IS_BINOP_MATCHER(Word64Shl)
IS_BINOP_MATCHER(Word64Equal)
IS_BINOP_MATCHER(Int32AddWithOverflow)
IS_BINOP_MATCHER(Int32Mul)
IS_BINOP_MATCHER(Uint32LessThan)
IS_BINOP_MATCHER(Uint32LessThanOrEqual)
#undef IS_BINOP_MATCHER

View File

@ -150,6 +150,8 @@ Matcher<Node*> IsInt32AddWithOverflow(const Matcher<Node*>& lhs_matcher,
const Matcher<Node*>& rhs_matcher);
Matcher<Node*> IsInt32Mul(const Matcher<Node*>& lhs_matcher,
const Matcher<Node*>& rhs_matcher);
Matcher<Node*> IsUint32LessThan(const Matcher<Node*>& lhs_matcher,
const Matcher<Node*>& rhs_matcher);
Matcher<Node*> IsUint32LessThanOrEqual(const Matcher<Node*>& lhs_matcher,
const Matcher<Node*>& rhs_matcher);
Matcher<Node*> IsChangeFloat64ToInt32(const Matcher<Node*>& input_matcher);

View File

@ -655,6 +655,29 @@ TEST_F(MachineOperatorReducerTest, Int32SubWithOverflowWithConstant) {
}
// -----------------------------------------------------------------------------
// Uint32LessThan
TEST_F(MachineOperatorReducerTest, Uint32LessThanWithWord32Sar) {
Node* const p0 = Parameter(0);
TRACED_FORRANGE(uint32_t, shift, 1, 3) {
const uint32_t limit = (kMaxInt >> shift) - 1;
Node* const node = graph()->NewNode(
machine()->Uint32LessThan(),
graph()->NewNode(machine()->Word32Sar(), p0, Uint32Constant(shift)),
Uint32Constant(limit));
Reduction r = Reduce(node);
ASSERT_TRUE(r.Changed());
EXPECT_THAT(
r.replacement(),
IsUint32LessThan(p0, IsInt32Constant(bit_cast<int32_t>(
(limit << shift) | ((1u << shift) - 1)))));
}
}
// -----------------------------------------------------------------------------
// Store