Reviewers: Sven Panne,

Description:
Inline isUint32() method from HConstant, which was only used in one place.
Add utility method for checking whether an HValue is a given int32_t constant.

BUG=

Please review this at https://codereview.chromium.org/14244023/

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

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


Index: src/hydrogen-instructions.cc
diff --git a/src/hydrogen-instructions.cc b/src/hydrogen-instructions.cc
index 0aabfbc43229198f181ec9f76d4aaf4724228f4f..f1137f6360c21f6cabe5c5eb49e528156f199498 100644
--- a/src/hydrogen-instructions.cc
+++ b/src/hydrogen-instructions.cc
@@ -648,6 +648,13 @@ int32_t HValue::GetInteger32Constant() {
 }


+bool HValue::EqualsInteger32Constant(int32_t value) {
+  return IsConstant()
+    && HConstant::cast(this)->HasInteger32Value()
+    && HConstant::cast(this)->Integer32Value() == value;
+}
+
+
 void HValue::SetOperandAt(int index, HValue* value) {
   RegisterUse(index, value);
   InternalSetOperandAt(index, value);
@@ -1393,15 +1400,11 @@ 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 &&
+  if (left()->EqualsInteger32Constant(nop_constant) &&
       !right()->CheckFlag(kUint32)) {
     return right();
   }
-  if (right()->IsConstant() &&
-      HConstant::cast(right())->HasInteger32Value() &&
-      HConstant::cast(right())->Integer32Value() == nop_constant &&
+  if (right()->EqualsInteger32Constant(nop_constant) &&
       !left()->CheckFlag(kUint32)) {
     return left();
   }
@@ -1439,8 +1442,7 @@ HValue* HSub::Canonicalize() {
 // TODO(svenpanne) Use this in other Canonicalize() functions.
static bool IsIdentityOperation(HValue* arg1, HValue* arg2, int32_t identity) {
   return arg1->representation().IsSpecialization() &&
-      arg2->IsInteger32Constant() &&
-      arg2->GetInteger32Constant() == identity;
+    arg2->EqualsInteger32Constant(identity);
 }


Index: src/hydrogen-instructions.h
diff --git a/src/hydrogen-instructions.h b/src/hydrogen-instructions.h
index e74de4a1b1dc345398aff5b765de113fd865f78d..b386cb55cadd0589efaf4d19cbc985f325ddaec2 100644
--- a/src/hydrogen-instructions.h
+++ b/src/hydrogen-instructions.h
@@ -1001,6 +1001,7 @@ class HValue: public ZoneObject {

   bool IsInteger32Constant();
   int32_t GetInteger32Constant();
+  bool EqualsInteger32Constant(int32_t value);

   bool IsDefinedAfter(HBasicBlock* other) const;

@@ -3328,10 +3329,6 @@ class HConstant: public HTemplateInstruction<0> {

   bool BooleanValue() const { return boolean_value_; }

-  bool IsUint32() {
-    return HasInteger32Value() && (Integer32Value() >= 0);
-  }
-
   virtual intptr_t Hashcode() {
     if (has_int32_value_) {
       return static_cast<intptr_t>(int32_value_);
Index: src/hydrogen.cc
diff --git a/src/hydrogen.cc b/src/hydrogen.cc
index 09e3fe9c47310195bc269cc6fa55da7dd9c44acf..3c439825f4103d4041f0bdf2971e29da0321cf76 100644
--- a/src/hydrogen.cc
+++ b/src/hydrogen.cc
@@ -3852,7 +3852,8 @@ bool Uint32Analysis::CheckPhiOperands(HPhi* phi) {
     if (!operand->CheckFlag(HInstruction::kUint32)) {
// Lazyly mark constants that fit into uint32 range with kUint32 flag.
       if (operand->IsConstant() &&
-          HConstant::cast(operand)->IsUint32()) {
+          HConstant::cast(operand)->HasInteger32Value() &&
+          HConstant::cast(operand)->Integer32Value() >= 0) {
         operand->SetFlag(HInstruction::kUint32);
         continue;
       }
@@ -8622,9 +8623,7 @@ bool HOptimizedGraphBuilder::TryInlineBuiltinMethodCall(
           } else if (exponent == 2.0) {
             result = HMul::New(zone(), context, left, left);
           }
-        } else if (right->IsConstant() &&
-                   HConstant::cast(right)->HasInteger32Value() &&
-                   HConstant::cast(right)->Integer32Value() == 2) {
+        } else if (right->EqualsInteger32Constant(2)) {
           result = HMul::New(zone(), context, left, left);
         }



--
--
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/groups/opt_out.


Reply via email to