Reviewers: Sven,

Description:
Optimize simple constant cases for bitwise & and |.

For integer bitwise operations we can replace
x & -1 with x and x | 0 with x.

Please review this at http://codereview.chromium.org/9177001/

SVN Base: http://v8.googlecode.com/svn/branches/bleeding_edge/

Affected files:
  M     src/hydrogen-instructions.h
  M     src/hydrogen-instructions.cc


Index: src/hydrogen-instructions.cc
===================================================================
--- src/hydrogen-instructions.cc        (revision 10369)
+++ src/hydrogen-instructions.cc        (working copy)
@@ -788,6 +788,25 @@
 }


+HValue* HBitwise::Canonicalize() {
+  if (!representation().IsInteger32()) return this;
+  if (op() == Token::BIT_XOR) return this;
+  // If x is an int32, x & -1 == x and x | 0 == x.
+  int nop_constant = (op() == Token::BIT_AND) ? -1 : 0;
+  if (left()->IsConstant() &&
+      HConstant::cast(left())->HasInteger32Value() &&
+      HConstant::cast(left())->Integer32Value() == nop_constant) {
+    return right();
+  }
+  if (right()->IsConstant() &&
+      HConstant::cast(right())->HasInteger32Value() &&
+      HConstant::cast(right())->Integer32Value() == nop_constant) {
+    return left();
+  }
+  return this;
+}
+
+
 void HTypeof::PrintDataTo(StringStream* stream) {
   value()->PrintNameTo(stream);
 }
Index: src/hydrogen-instructions.h
===================================================================
--- src/hydrogen-instructions.h (revision 10369)
+++ src/hydrogen-instructions.h (working copy)
@@ -3151,6 +3151,8 @@

   virtual bool IsCommutative() const { return true; }

+  virtual HValue* Canonicalize();
+
   static HInstruction* NewHBitwise(Zone* zone,
                                    Token::Value op,
                                    HValue* context,


--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev

Reply via email to