Index: src/compiler/machine-operator-reducer.cc |
diff --git a/src/compiler/machine-operator-reducer.cc b/src/compiler/machine-operator-reducer.cc |
index 4a4057646dde8bc0f60c8866207f52512ea06387..8466cbbf47537f22b8b750fb5ea8dd38b41962d8 100644 |
--- a/src/compiler/machine-operator-reducer.cc |
+++ b/src/compiler/machine-operator-reducer.cc |
@@ -4,6 +4,7 @@ |
#include "src/compiler/machine-operator-reducer.h" |
+#include "src/base/bits.h" |
#include "src/compiler/common-node-cache.h" |
#include "src/compiler/generic-node-inl.h" |
#include "src/compiler/graph.h" |
@@ -67,6 +68,56 @@ Reduction MachineOperatorReducer::Reduce(Node* node) { |
return ReplaceInt32(m.left().Value() | m.right().Value()); |
} |
if (m.LeftEqualsRight()) return Replace(m.left().node()); // x | x => x |
+ if (m.left().IsWord32Shl() && m.right().IsWord32Shr()) { |
+ Int32BinopMatcher mleft(m.left().node()); |
+ Int32BinopMatcher mright(m.right().node()); |
+ if (mleft.left().node() == mright.left().node()) { |
+ // (x << y) | (x >> (32 - y)) => x ror y |
+ if (mright.right().IsInt32Sub()) { |
+ Int32BinopMatcher mrightright(mright.right().node()); |
+ if (mrightright.left().Is(32) && |
+ mrightright.right().node() == mleft.right().node()) { |
+ graph_->ChangeOperator(node, machine_.Word32Ror()); |
+ node->ReplaceInput(0, mleft.left().node()); |
+ node->ReplaceInput(1, mleft.right().node()); |
+ return Changed(node); |
+ } |
+ } |
+ // (x << K) | (x >> (32 - K)) => x ror K |
+ if (mleft.right().IsInRange(0, 31) && |
+ mright.right().Is(32 - mleft.right().Value())) { |
+ graph_->ChangeOperator(node, machine_.Word32Ror()); |
+ node->ReplaceInput(0, mleft.left().node()); |
+ node->ReplaceInput(1, mleft.right().node()); |
+ return Changed(node); |
+ } |
+ } |
+ } |
+ if (m.left().IsWord32Shr() && m.right().IsWord32Shl()) { |
+ // (x >> (32 - y)) | (x << y) => x ror y |
+ Int32BinopMatcher mleft(m.left().node()); |
+ Int32BinopMatcher mright(m.right().node()); |
+ if (mleft.left().node() == mright.left().node()) { |
+ if (mleft.right().IsInt32Sub()) { |
+ Int32BinopMatcher mleftright(mleft.right().node()); |
+ if (mleftright.left().Is(32) && |
+ mleftright.right().node() == mright.right().node()) { |
+ graph_->ChangeOperator(node, machine_.Word32Ror()); |
+ node->ReplaceInput(0, mright.left().node()); |
+ node->ReplaceInput(1, mright.right().node()); |
+ return Changed(node); |
+ } |
+ } |
+ // (x >> (32 - K)) | (x << K) => x ror K |
+ if (mright.right().IsInRange(0, 31) && |
+ mleft.right().Is(32 - mright.right().Value())) { |
+ graph_->ChangeOperator(node, machine_.Word32Ror()); |
+ node->ReplaceInput(0, mright.left().node()); |
+ node->ReplaceInput(1, mright.right().node()); |
+ return Changed(node); |
+ } |
+ } |
+ } |
break; |
} |
case IrOpcode::kWord32Xor: { |
@@ -102,6 +153,15 @@ Reduction MachineOperatorReducer::Reduce(Node* node) { |
} |
break; |
} |
+ case IrOpcode::kWord32Ror: { |
+ Int32BinopMatcher m(node); |
+ if (m.right().Is(0)) return Replace(m.left().node()); // x ror 0 => x |
+ if (m.IsFoldable()) { // K ror K => K |
+ return ReplaceInt32( |
+ base::bits::RotateRight32(m.left().Value(), m.right().Value())); |
+ } |
+ break; |
+ } |
case IrOpcode::kWord32Equal: { |
Int32BinopMatcher m(node); |
if (m.IsFoldable()) { // K == K => K |