Commit 53bd540e authored by ishell@chromium.org's avatar ishell@chromium.org

Constant-folding through HForceRepresentation fix.

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
parent 0767ee86
...@@ -521,19 +521,12 @@ bool HValue::CanReplaceWithDummyUses() { ...@@ -521,19 +521,12 @@ bool HValue::CanReplaceWithDummyUses() {
bool HValue::IsInteger32Constant() { bool HValue::IsInteger32Constant() {
HValue* value_to_check = IsForceRepresentation() return IsConstant() && HConstant::cast(this)->HasInteger32Value();
? HForceRepresentation::cast(this)->value()
: this;
return value_to_check->IsConstant() &&
HConstant::cast(value_to_check)->HasInteger32Value();
} }
int32_t HValue::GetInteger32Constant() { int32_t HValue::GetInteger32Constant() {
HValue* constant_value = IsForceRepresentation() return HConstant::cast(this)->Integer32Value();
? HForceRepresentation::cast(this)->value()
: this;
return HConstant::cast(constant_value)->Integer32Value();
} }
...@@ -1342,6 +1335,23 @@ void HTypeof::PrintDataTo(StringStream* stream) { ...@@ -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) { void HForceRepresentation::PrintDataTo(StringStream* stream) {
stream->Add("%s ", representation().Mnemonic()); stream->Add("%s ", representation().Mnemonic());
value()->PrintNameTo(stream); value()->PrintNameTo(stream);
......
...@@ -1675,7 +1675,8 @@ class HUseConst V8_FINAL : public HUnaryOperation { ...@@ -1675,7 +1675,8 @@ class HUseConst V8_FINAL : public HUnaryOperation {
class HForceRepresentation V8_FINAL : public HTemplateInstruction<1> { class HForceRepresentation V8_FINAL : public HTemplateInstruction<1> {
public: 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); } HValue* value() { return OperandAt(0); }
......
...@@ -2078,7 +2078,7 @@ HInstruction* HGraphBuilder::BuildUncheckedMonomorphicElementAccess( ...@@ -2078,7 +2078,7 @@ HInstruction* HGraphBuilder::BuildUncheckedMonomorphicElementAccess(
// deopt, leaving the backing store in an invalid state. // deopt, leaving the backing store in an invalid state.
if (is_store && IsFastSmiElementsKind(elements_kind) && if (is_store && IsFastSmiElementsKind(elements_kind) &&
!val->type().IsSmi()) { !val->type().IsSmi()) {
val = Add<HForceRepresentation>(val, Representation::Smi()); val = AddUncasted<HForceRepresentation>(val, Representation::Smi());
} }
if (IsGrowStoreMode(store_mode)) { if (IsGrowStoreMode(store_mode)) {
...@@ -2195,7 +2195,7 @@ HValue* HGraphBuilder::BuildAllocateElementsAndInitializeElementsHeader( ...@@ -2195,7 +2195,7 @@ HValue* HGraphBuilder::BuildAllocateElementsAndInitializeElementsHeader(
HValue* capacity) { HValue* capacity) {
// The HForceRepresentation is to prevent possible deopt on int-smi // The HForceRepresentation is to prevent possible deopt on int-smi
// conversion after allocation but before the new object fields are set. // 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); HValue* new_elements = BuildAllocateElements(kind, capacity);
BuildInitializeElementsHeader(new_elements, kind, capacity); BuildInitializeElementsHeader(new_elements, kind, capacity);
return new_elements; return new_elements;
...@@ -2714,10 +2714,12 @@ HValue* HGraphBuilder::JSArrayBuilder::AllocateArray(HValue* size_in_bytes, ...@@ -2714,10 +2714,12 @@ HValue* HGraphBuilder::JSArrayBuilder::AllocateArray(HValue* size_in_bytes,
// These HForceRepresentations are because we store these as fields in the // These HForceRepresentations are because we store these as fields in the
// objects we construct, and an int32-to-smi HChange could deopt. Accept // objects we construct, and an int32-to-smi HChange could deopt. Accept
// the deopt possibility now, before allocation occurs. // the deopt possibility now, before allocation occurs.
capacity = builder()->Add<HForceRepresentation>(capacity, capacity =
Representation::Smi()); builder()->AddUncasted<HForceRepresentation>(capacity,
length_field = builder()->Add<HForceRepresentation>(length_field, Representation::Smi());
Representation::Smi()); length_field =
builder()->AddUncasted<HForceRepresentation>(length_field,
Representation::Smi());
// Allocate (dealing with failure appropriately) // Allocate (dealing with failure appropriately)
HAllocate* new_object = builder()->Add<HAllocate>(size_in_bytes, HAllocate* new_object = builder()->Add<HAllocate>(size_in_bytes,
HType::JSArray(), NOT_TENURED, JS_ARRAY_TYPE); HType::JSArray(), NOT_TENURED, JS_ARRAY_TYPE);
...@@ -8267,7 +8269,7 @@ HInstruction* HOptimizedGraphBuilder::BuildIncrement( ...@@ -8267,7 +8269,7 @@ HInstruction* HOptimizedGraphBuilder::BuildIncrement(
// actual HChange instruction we need is (sometimes) added in a later // 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 // phase, so it is not available now to be used as an input to HAdd and
// as the return value. // as the return value.
HInstruction* number_input = Add<HForceRepresentation>(Pop(), rep); HInstruction* number_input = AddUncasted<HForceRepresentation>(Pop(), rep);
if (!rep.IsDouble()) { if (!rep.IsDouble()) {
number_input->SetFlag(HInstruction::kFlexibleRepresentation); number_input->SetFlag(HInstruction::kFlexibleRepresentation);
number_input->SetFlag(HInstruction::kCannotBeTagged); number_input->SetFlag(HInstruction::kCannotBeTagged);
...@@ -8514,10 +8516,11 @@ bool CanBeZero(HValue* right) { ...@@ -8514,10 +8516,11 @@ bool CanBeZero(HValue* right) {
HValue* HGraphBuilder::EnforceNumberType(HValue* number, HValue* HGraphBuilder::EnforceNumberType(HValue* number,
Handle<Type> expected) { Handle<Type> expected) {
if (expected->Is(Type::Smi())) { if (expected->Is(Type::Smi())) {
return Add<HForceRepresentation>(number, Representation::Smi()); return AddUncasted<HForceRepresentation>(number, Representation::Smi());
} }
if (expected->Is(Type::Signed32())) { if (expected->Is(Type::Signed32())) {
return Add<HForceRepresentation>(number, Representation::Integer32()); return AddUncasted<HForceRepresentation>(number,
Representation::Integer32());
} }
return number; return number;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment