Revision: 24931
Author:   [email protected]
Date:     Tue Oct 28 11:57:20 2014 UTC
Log:      [turbofan] Reduce (x & K) & K to x & K.

TEST=unittests
[email protected]

Review URL: https://codereview.chromium.org/685713002
https://code.google.com/p/v8/source/detail?r=24931

Modified:
 /branches/bleeding_edge/src/compiler/machine-operator-reducer.cc
/branches/bleeding_edge/test/unittests/compiler/machine-operator-reducer-unittest.cc

=======================================
--- /branches/bleeding_edge/src/compiler/machine-operator-reducer.cc Mon Oct 27 22:33:52 2014 UTC +++ /branches/bleeding_edge/src/compiler/machine-operator-reducer.cc Tue Oct 28 11:57:20 2014 UTC
@@ -109,6 +109,15 @@
         return ReplaceInt32(m.left().Value() & m.right().Value());
       }
if (m.LeftEqualsRight()) return Replace(m.left().node()); // x & x => x
+      if (m.left().IsWord32And() && m.right().HasValue()) {
+        Int32BinopMatcher mleft(m.left().node());
+        if (mleft.right().HasValue()) {  // (x & K) & K => x & K
+          node->ReplaceInput(0, mleft.left().node());
+          node->ReplaceInput(
+              1, Int32Constant(m.right().Value() & mleft.right().Value()));
+          return Changed(node);
+        }
+      }
       break;
     }
     case IrOpcode::kWord32Or: {
=======================================
--- /branches/bleeding_edge/test/unittests/compiler/machine-operator-reducer-unittest.cc Sun Oct 26 12:49:56 2014 UTC +++ /branches/bleeding_edge/test/unittests/compiler/machine-operator-reducer-unittest.cc Tue Oct 28 11:57:20 2014 UTC
@@ -479,6 +479,37 @@
                     static_cast<uint32_t>(bit_cast<uint64_t>(x)))));
   }
 }
+
+
+// -----------------------------------------------------------------------------
+// Word32And
+
+
+TEST_F(MachineOperatorReducerTest, Word32AndWithWord32AndWithConstant) {
+  Node* const p0 = Parameter(0);
+
+  TRACED_FOREACH(int32_t, k, kInt32Values) {
+    TRACED_FOREACH(int32_t, l, kInt32Values) {
+      if (k == 0 || k == -1 || l == 0 || l == -1) continue;
+
+      // (x & K) & L => x & (K & L)
+      Reduction const r1 = Reduce(graph()->NewNode(
+          machine()->Word32And(),
+          graph()->NewNode(machine()->Word32And(), p0, Int32Constant(k)),
+          Int32Constant(l)));
+      ASSERT_TRUE(r1.Changed());
+ EXPECT_THAT(r1.replacement(), IsWord32And(p0, IsInt32Constant(k & l)));
+
+      // (K & x) & L => x & (K & L)
+      Reduction const r2 = Reduce(graph()->NewNode(
+          machine()->Word32And(),
+          graph()->NewNode(machine()->Word32And(), Int32Constant(k), p0),
+          Int32Constant(l)));
+      ASSERT_TRUE(r2.Changed());
+ EXPECT_THAT(r2.replacement(), IsWord32And(p0, IsInt32Constant(k & l)));
+    }
+  }
+}


// -----------------------------------------------------------------------------

--
--
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.

Reply via email to