Revision: 10382
Author: [email protected]
Date: Wed Jan 11 02:01:59 2012
Log: Optimize simple constant cases for bitwise &, | and ^.
For integer bitwise operations we can replace
x & -1 with x, x | 0 with x and x ^ 0 with x.
Review URL: http://codereview.chromium.org/9177001
http://code.google.com/p/v8/source/detail?r=10382
Modified:
/branches/bleeding_edge/src/hydrogen-instructions.cc
/branches/bleeding_edge/src/hydrogen-instructions.h
=======================================
--- /branches/bleeding_edge/src/hydrogen-instructions.cc Wed Dec 14
05:01:27 2011
+++ /branches/bleeding_edge/src/hydrogen-instructions.cc Wed Jan 11
02:01:59 2012
@@ -786,6 +786,24 @@
HValue* HTypeof::Canonicalize() {
return HasNoUses() && !IsBlockEntry() ? NULL : this;
}
+
+
+HValue* HBitwise::Canonicalize() {
+ if (!representation().IsInteger32()) return this;
+ // If x is an int32, then x & -1 == x, x | 0 == x and x ^ 0 == x.
+ int32_t 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) {
=======================================
--- /branches/bleeding_edge/src/hydrogen-instructions.h Mon Jan 9 08:37:47
2012
+++ /branches/bleeding_edge/src/hydrogen-instructions.h Wed Jan 11 02:01:59
2012
@@ -3150,6 +3150,8 @@
Token::Value op() const { return op_; }
virtual bool IsCommutative() const { return true; }
+
+ virtual HValue* Canonicalize();
static HInstruction* NewHBitwise(Zone* zone,
Token::Value op,
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev