Reviewers: jarin,
Message:
Committed patchset #1 (id:1) manually as 24520 (presubmit successful).
Description:
[turbofan] Optimize Uint32LessThan with Word32Sar.
TEST=unittests
[email protected]
Committed: https://code.google.com/p/v8/source/detail?r=24520
Please review this at https://codereview.chromium.org/648663002/
SVN Base: https://v8.googlecode.com/svn/branches/bleeding_edge
Affected files (+40, -0 lines):
M src/compiler/machine-operator-reducer.cc
M test/unittests/compiler/graph-unittest.h
M test/unittests/compiler/graph-unittest.cc
M test/unittests/compiler/machine-operator-reducer-unittest.cc
Index: src/compiler/machine-operator-reducer.cc
diff --git a/src/compiler/machine-operator-reducer.cc
b/src/compiler/machine-operator-reducer.cc
index
193b033bdab9d8f1882c944ca339240428766873..f728dbffcab0ee253b6719bf0f0ec5878f9c6187
100644
--- a/src/compiler/machine-operator-reducer.cc
+++ b/src/compiler/machine-operator-reducer.cc
@@ -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: {
Index: test/unittests/compiler/graph-unittest.cc
diff --git a/test/unittests/compiler/graph-unittest.cc
b/test/unittests/compiler/graph-unittest.cc
index
7c6232e1f6a68be3833fa6b12b2f10e4194527f6..090d572506b1c43b428e68075372658910b4ea7b
100644
--- a/test/unittests/compiler/graph-unittest.cc
+++ b/test/unittests/compiler/graph-unittest.cc
@@ -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
Index: test/unittests/compiler/graph-unittest.h
diff --git a/test/unittests/compiler/graph-unittest.h
b/test/unittests/compiler/graph-unittest.h
index
bfed062c713e431adca69bcc1afedca243f09811..37fbe8a44183e83056383e3c06686ed5f62c8d20
100644
--- a/test/unittests/compiler/graph-unittest.h
+++ b/test/unittests/compiler/graph-unittest.h
@@ -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);
Index: test/unittests/compiler/machine-operator-reducer-unittest.cc
diff --git a/test/unittests/compiler/machine-operator-reducer-unittest.cc
b/test/unittests/compiler/machine-operator-reducer-unittest.cc
index
3a5eb1af45d1efc30baa43d92e439a8fec86c2ac..6c46a5bd95874848eedc5a327756170c08b2fba6
100644
--- a/test/unittests/compiler/machine-operator-reducer-unittest.cc
+++ b/test/unittests/compiler/machine-operator-reducer-unittest.cc
@@ -656,6 +656,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
--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
---
You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.