Constant-folding through HForceRepresentation fix.
authorishell@chromium.org <ishell@chromium.org@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Tue, 19 Nov 2013 11:41:04 +0000 (11:41 +0000)
committerishell@chromium.org <ishell@chromium.org@ce2b1a6d-e550-0410-aec6-3dcde31c8c00>
Tue, 19 Nov 2013 11:41:04 +0000 (11:41 +0000)
Reverts changes in HValue::IsInteger32Constant() made in https://code.google.com/p/v8/source/detail?r=17787

R=bmeurer@chromium.org, mvstanton@chromium.org

Review URL: https://codereview.chromium.org/68493005

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@17863 ce2b1a6d-e550-0410-aec6-3dcde31c8c00

src/hydrogen-instructions.cc
src/hydrogen-instructions.h
src/hydrogen.cc

index c47351d1aafa3c4a7856a40dbfeda4cb1e3a9f32..84949c09aa1df1b3038f20d6ab2a8c6a45e267ae 100644 (file)
@@ -521,19 +521,12 @@ bool HValue::CanReplaceWithDummyUses() {
 
 
 bool HValue::IsInteger32Constant() {
-  HValue* value_to_check = IsForceRepresentation()
-      ? HForceRepresentation::cast(this)->value()
-      : this;
-  return value_to_check->IsConstant() &&
-      HConstant::cast(value_to_check)->HasInteger32Value();
+  return IsConstant() && HConstant::cast(this)->HasInteger32Value();
 }
 
 
 int32_t HValue::GetInteger32Constant() {
-  HValue* constant_value = IsForceRepresentation()
-      ? HForceRepresentation::cast(this)->value()
-      : this;
-  return HConstant::cast(constant_value)->Integer32Value();
+  return HConstant::cast(this)->Integer32Value();
 }
 
 
@@ -1342,6 +1335,23 @@ void HTypeof::PrintDataTo(StringStream* stream) {
 }
 
 
+HInstruction* HForceRepresentation::New(Zone* zone, HValue* context,
+       HValue* value, Representation required_representation) {
+  if (FLAG_fold_constants && value->IsConstant()) {
+    HConstant* c = HConstant::cast(value);
+    if (c->HasNumberValue()) {
+      double double_res = c->DoubleValue();
+      if (TypeInfo::IsInt32Double(double_res)) {
+        return HConstant::New(zone, context,
+                              static_cast<int32_t>(double_res),
+                              required_representation);
+      }
+    }
+  }
+  return new(zone) HForceRepresentation(value, required_representation);
+}
+
+
 void HForceRepresentation::PrintDataTo(StringStream* stream) {
   stream->Add("%s ", representation().Mnemonic());
   value()->PrintNameTo(stream);
index 756ae0d83eff31c6e8056dfa84ad150f45ca7499..c77c2ebf0e495a134172b2da370b19eebfdfb6cc 100644 (file)
@@ -1675,7 +1675,8 @@ class HUseConst V8_FINAL : public HUnaryOperation {
 
 class HForceRepresentation V8_FINAL : public HTemplateInstruction<1> {
  public:
-  DECLARE_INSTRUCTION_FACTORY_P2(HForceRepresentation, HValue*, Representation);
+  static HInstruction* New(Zone* zone, HValue* context, HValue* value,
+                           Representation required_representation);
 
   HValue* value() { return OperandAt(0); }
 
index 431242fe15c30252372ceef34ff960dffa405db3..b5fd2dfebc5c6a31356b17e5291f8661275242a2 100644 (file)
@@ -2078,7 +2078,7 @@ HInstruction* HGraphBuilder::BuildUncheckedMonomorphicElementAccess(
   // deopt, leaving the backing store in an invalid state.
   if (is_store && IsFastSmiElementsKind(elements_kind) &&
       !val->type().IsSmi()) {
-    val = Add<HForceRepresentation>(val, Representation::Smi());
+    val = AddUncasted<HForceRepresentation>(val, Representation::Smi());
   }
 
   if (IsGrowStoreMode(store_mode)) {
@@ -2195,7 +2195,7 @@ HValue* HGraphBuilder::BuildAllocateElementsAndInitializeElementsHeader(
     HValue* capacity) {
   // The HForceRepresentation is to prevent possible deopt on int-smi
   // conversion after allocation but before the new object fields are set.
-  capacity = Add<HForceRepresentation>(capacity, Representation::Smi());
+  capacity = AddUncasted<HForceRepresentation>(capacity, Representation::Smi());
   HValue* new_elements = BuildAllocateElements(kind, capacity);
   BuildInitializeElementsHeader(new_elements, kind, capacity);
   return new_elements;
@@ -2714,10 +2714,12 @@ HValue* HGraphBuilder::JSArrayBuilder::AllocateArray(HValue* size_in_bytes,
   // These HForceRepresentations are because we store these as fields in the
   // objects we construct, and an int32-to-smi HChange could deopt. Accept
   // the deopt possibility now, before allocation occurs.
-  capacity = builder()->Add<HForceRepresentation>(capacity,
-                                                  Representation::Smi());
-  length_field = builder()->Add<HForceRepresentation>(length_field,
-                                                      Representation::Smi());
+  capacity =
+      builder()->AddUncasted<HForceRepresentation>(capacity,
+                                                   Representation::Smi());
+  length_field =
+      builder()->AddUncasted<HForceRepresentation>(length_field,
+                                                   Representation::Smi());
   // Allocate (dealing with failure appropriately)
   HAllocate* new_object = builder()->Add<HAllocate>(size_in_bytes,
       HType::JSArray(), NOT_TENURED, JS_ARRAY_TYPE);
@@ -8267,7 +8269,7 @@ HInstruction* HOptimizedGraphBuilder::BuildIncrement(
     // actual HChange instruction we need is (sometimes) added in a later
     // phase, so it is not available now to be used as an input to HAdd and
     // as the return value.
-    HInstruction* number_input = Add<HForceRepresentation>(Pop(), rep);
+    HInstruction* number_input = AddUncasted<HForceRepresentation>(Pop(), rep);
     if (!rep.IsDouble()) {
       number_input->SetFlag(HInstruction::kFlexibleRepresentation);
       number_input->SetFlag(HInstruction::kCannotBeTagged);
@@ -8514,10 +8516,11 @@ bool CanBeZero(HValue* right) {
 HValue* HGraphBuilder::EnforceNumberType(HValue* number,
                                          Handle<Type> expected) {
   if (expected->Is(Type::Smi())) {
-    return Add<HForceRepresentation>(number, Representation::Smi());
+    return AddUncasted<HForceRepresentation>(number, Representation::Smi());
   }
   if (expected->Is(Type::Signed32())) {
-    return Add<HForceRepresentation>(number, Representation::Integer32());
+    return AddUncasted<HForceRepresentation>(number,
+                                             Representation::Integer32());
   }
   return number;
 }