Revision: 24520
Author: [email protected]
Date: Fri Oct 10 10:23:04 2014 UTC
Log: [turbofan] Optimize Uint32LessThan with Word32Sar.
TEST=unittests
[email protected]
Review URL: https://codereview.chromium.org/648663002
https://code.google.com/p/v8/source/detail?r=24520
Modified:
/branches/bleeding_edge/src/compiler/machine-operator-reducer.cc
/branches/bleeding_edge/test/unittests/compiler/graph-unittest.cc
/branches/bleeding_edge/test/unittests/compiler/graph-unittest.h
/branches/bleeding_edge/test/unittests/compiler/machine-operator-reducer-unittest.cc
=======================================
--- /branches/bleeding_edge/src/compiler/machine-operator-reducer.cc Thu
Oct 9 12:20:45 2014 UTC
+++ /branches/bleeding_edge/src/compiler/machine-operator-reducer.cc Fri
Oct 10 10:23:04 2014 UTC
@@ -339,6 +339,20 @@
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: {
=======================================
--- /branches/bleeding_edge/test/unittests/compiler/graph-unittest.cc Thu
Oct 9 12:20:45 2014 UTC
+++ /branches/bleeding_edge/test/unittests/compiler/graph-unittest.cc Fri
Oct 10 10:23:04 2014 UTC
@@ -949,6 +949,7 @@
IS_BINOP_MATCHER(Word64Equal)
IS_BINOP_MATCHER(Int32AddWithOverflow)
IS_BINOP_MATCHER(Int32Mul)
+IS_BINOP_MATCHER(Uint32LessThan)
IS_BINOP_MATCHER(Uint32LessThanOrEqual)
#undef IS_BINOP_MATCHER
=======================================
--- /branches/bleeding_edge/test/unittests/compiler/graph-unittest.h Thu
Oct 9 12:20:45 2014 UTC
+++ /branches/bleeding_edge/test/unittests/compiler/graph-unittest.h Fri
Oct 10 10:23:04 2014 UTC
@@ -150,6 +150,8 @@
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);
=======================================
---
/branches/bleeding_edge/test/unittests/compiler/machine-operator-reducer-unittest.cc
Thu Oct 9 12:20:45 2014 UTC
+++
/branches/bleeding_edge/test/unittests/compiler/machine-operator-reducer-unittest.cc
Fri Oct 10 10:23:04 2014 UTC
@@ -653,6 +653,29 @@
}
}
}
+
+
+//
-----------------------------------------------------------------------------
+// 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)))));
+ }
+}
//
-----------------------------------------------------------------------------
--
--
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.