Commit 48fea83d authored by bmeurer@chromium.org's avatar bmeurer@chromium.org

Merge the "Compute Minus Zero Checks" phase into the range analysis.

It is not safe to access the range for an SSA value
after range analysis.

BUG=v8:3204
LOG=y
R=svenpanne@chromium.org

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

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@19751 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 1b7055cf
......@@ -241,7 +241,6 @@ DEFINE_bool(string_slices, true, "use string slices")
// Flags for Crankshaft.
DEFINE_bool(crankshaft, true, "use crankshaft")
DEFINE_string(hydrogen_filter, "*", "optimization filter")
DEFINE_bool(use_range, true, "use hydrogen range analysis")
DEFINE_bool(use_gvn, true, "use hydrogen global value numbering")
DEFINE_int(gvn_iterations, 3, "maximum number of GVN fix-point iterations")
DEFINE_bool(use_canonicalizing, true, "use hydrogen instruction canonicalizing")
......
// Copyright 2013 the V8 project authors. All rights reserved.
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials provided
// with the distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#include "hydrogen-minus-zero.h"
namespace v8 {
namespace internal {
void HComputeMinusZeroChecksPhase::Run() {
const ZoneList<HBasicBlock*>* blocks(graph()->blocks());
for (int i = 0; i < blocks->length(); ++i) {
for (HInstructionIterator it(blocks->at(i)); !it.Done(); it.Advance()) {
HInstruction* current = it.Current();
if (current->IsChange()) {
HChange* change = HChange::cast(current);
// Propagate flags for negative zero checks upwards from conversions
// int32-to-tagged and int32-to-double.
Representation from = change->value()->representation();
ASSERT(from.Equals(change->from()));
if (from.IsSmiOrInteger32()) {
ASSERT(change->to().IsTagged() ||
change->to().IsDouble() ||
change->to().IsSmiOrInteger32());
PropagateMinusZeroChecks(change->value());
}
} else if (current->IsCompareMinusZeroAndBranch()) {
HCompareMinusZeroAndBranch* check =
HCompareMinusZeroAndBranch::cast(current);
if (check->value()->representation().IsSmiOrInteger32()) {
PropagateMinusZeroChecks(check->value());
}
}
}
}
}
void HComputeMinusZeroChecksPhase::PropagateMinusZeroChecks(HValue* value) {
ASSERT(worklist_.is_empty());
ASSERT(in_worklist_.IsEmpty());
AddToWorklist(value);
while (!worklist_.is_empty()) {
value = worklist_.RemoveLast();
if (value->IsPhi()) {
// For phis, we must propagate the check to all of its inputs.
HPhi* phi = HPhi::cast(value);
for (int i = 0; i < phi->OperandCount(); ++i) {
AddToWorklist(phi->OperandAt(i));
}
} else if (value->IsUnaryMathOperation()) {
HUnaryMathOperation* instr = HUnaryMathOperation::cast(value);
if (instr->representation().IsSmiOrInteger32() &&
!instr->value()->representation().Equals(instr->representation())) {
if (instr->value()->range() == NULL ||
instr->value()->range()->CanBeMinusZero()) {
instr->SetFlag(HValue::kBailoutOnMinusZero);
}
}
if (instr->RequiredInputRepresentation(0).IsSmiOrInteger32() &&
instr->representation().Equals(
instr->RequiredInputRepresentation(0))) {
AddToWorklist(instr->value());
}
} else if (value->IsChange()) {
HChange* instr = HChange::cast(value);
if (!instr->from().IsSmiOrInteger32() &&
!instr->CanTruncateToInt32() &&
(instr->value()->range() == NULL ||
instr->value()->range()->CanBeMinusZero())) {
instr->SetFlag(HValue::kBailoutOnMinusZero);
}
} else if (value->IsForceRepresentation()) {
HForceRepresentation* instr = HForceRepresentation::cast(value);
AddToWorklist(instr->value());
} else if (value->IsMod()) {
HMod* instr = HMod::cast(value);
if (instr->range() == NULL || instr->range()->CanBeMinusZero()) {
instr->SetFlag(HValue::kBailoutOnMinusZero);
AddToWorklist(instr->left());
}
} else if (value->IsDiv() || value->IsMul()) {
HBinaryOperation* instr = HBinaryOperation::cast(value);
if (instr->range() == NULL || instr->range()->CanBeMinusZero()) {
instr->SetFlag(HValue::kBailoutOnMinusZero);
}
AddToWorklist(instr->right());
AddToWorklist(instr->left());
} else if (value->IsMathFloorOfDiv()) {
HMathFloorOfDiv* instr = HMathFloorOfDiv::cast(value);
instr->SetFlag(HValue::kBailoutOnMinusZero);
} else if (value->IsAdd() || value->IsSub()) {
HBinaryOperation* instr = HBinaryOperation::cast(value);
if (instr->range() == NULL || instr->range()->CanBeMinusZero()) {
// Propagate to the left argument. If the left argument cannot be -0,
// then the result of the add/sub operation cannot be either.
AddToWorklist(instr->left());
}
} else if (value->IsMathMinMax()) {
HMathMinMax* instr = HMathMinMax::cast(value);
AddToWorklist(instr->right());
AddToWorklist(instr->left());
}
}
in_worklist_.Clear();
ASSERT(in_worklist_.IsEmpty());
ASSERT(worklist_.is_empty());
}
} } // namespace v8::internal
// Copyright 2013 the V8 project authors. All rights reserved.
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials provided
// with the distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived
// from this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#ifndef V8_HYDROGEN_MINUS_ZERO_H_
#define V8_HYDROGEN_MINUS_ZERO_H_
#include "hydrogen.h"
namespace v8 {
namespace internal {
class HComputeMinusZeroChecksPhase : public HPhase {
public:
explicit HComputeMinusZeroChecksPhase(HGraph* graph)
: HPhase("H_Compute minus zero checks", graph),
in_worklist_(graph->GetMaximumValueID(), zone()),
worklist_(32, zone()) {}
void Run();
private:
void AddToWorklist(HValue* value) {
if (value->CheckFlag(HValue::kBailoutOnMinusZero)) return;
if (in_worklist_.Contains(value->id())) return;
in_worklist_.Add(value->id());
worklist_.Add(value, zone());
}
void PropagateMinusZeroChecks(HValue* value);
BitVector in_worklist_;
ZoneList<HValue*> worklist_;
DISALLOW_COPY_AND_ASSIGN(HComputeMinusZeroChecksPhase);
};
} } // namespace v8::internal
#endif // V8_HYDROGEN_MINUS_ZERO_H_
......@@ -78,7 +78,29 @@ void HRangeAnalysisPhase::Run() {
// Go through all instructions of the current block.
for (HInstructionIterator it(block); !it.Done(); it.Advance()) {
InferRange(it.Current());
HValue* value = it.Current();
InferRange(value);
// Compute the bailout-on-minus-zero flag.
if (value->IsChange()) {
HChange* instr = HChange::cast(value);
// Propagate flags for negative zero checks upwards from conversions
// int32-to-tagged and int32-to-double.
Representation from = instr->value()->representation();
ASSERT(from.Equals(instr->from()));
if (from.IsSmiOrInteger32()) {
ASSERT(instr->to().IsTagged() ||
instr->to().IsDouble() ||
instr->to().IsSmiOrInteger32());
PropagateMinusZeroChecks(instr->value());
}
} else if (value->IsCompareMinusZeroAndBranch()) {
HCompareMinusZeroAndBranch* instr =
HCompareMinusZeroAndBranch::cast(value);
if (instr->value()->representation().IsSmiOrInteger32()) {
PropagateMinusZeroChecks(instr->value());
}
}
}
// Continue analysis in all dominated blocks.
......@@ -197,4 +219,79 @@ void HRangeAnalysisPhase::AddRange(HValue* value, Range* range) {
}
void HRangeAnalysisPhase::PropagateMinusZeroChecks(HValue* value) {
ASSERT(worklist_.is_empty());
ASSERT(in_worklist_.IsEmpty());
AddToWorklist(value);
while (!worklist_.is_empty()) {
value = worklist_.RemoveLast();
if (value->IsPhi()) {
// For phis, we must propagate the check to all of its inputs.
HPhi* phi = HPhi::cast(value);
for (int i = 0; i < phi->OperandCount(); ++i) {
AddToWorklist(phi->OperandAt(i));
}
} else if (value->IsUnaryMathOperation()) {
HUnaryMathOperation* instr = HUnaryMathOperation::cast(value);
if (instr->representation().IsSmiOrInteger32() &&
!instr->value()->representation().Equals(instr->representation())) {
if (instr->value()->range() == NULL ||
instr->value()->range()->CanBeMinusZero()) {
instr->SetFlag(HValue::kBailoutOnMinusZero);
}
}
if (instr->RequiredInputRepresentation(0).IsSmiOrInteger32() &&
instr->representation().Equals(
instr->RequiredInputRepresentation(0))) {
AddToWorklist(instr->value());
}
} else if (value->IsChange()) {
HChange* instr = HChange::cast(value);
if (!instr->from().IsSmiOrInteger32() &&
!instr->CanTruncateToInt32() &&
(instr->value()->range() == NULL ||
instr->value()->range()->CanBeMinusZero())) {
instr->SetFlag(HValue::kBailoutOnMinusZero);
}
} else if (value->IsForceRepresentation()) {
HForceRepresentation* instr = HForceRepresentation::cast(value);
AddToWorklist(instr->value());
} else if (value->IsMod()) {
HMod* instr = HMod::cast(value);
if (instr->range() == NULL || instr->range()->CanBeMinusZero()) {
instr->SetFlag(HValue::kBailoutOnMinusZero);
AddToWorklist(instr->left());
}
} else if (value->IsDiv() || value->IsMul()) {
HBinaryOperation* instr = HBinaryOperation::cast(value);
if (instr->range() == NULL || instr->range()->CanBeMinusZero()) {
instr->SetFlag(HValue::kBailoutOnMinusZero);
}
AddToWorklist(instr->right());
AddToWorklist(instr->left());
} else if (value->IsMathFloorOfDiv()) {
HMathFloorOfDiv* instr = HMathFloorOfDiv::cast(value);
instr->SetFlag(HValue::kBailoutOnMinusZero);
} else if (value->IsAdd() || value->IsSub()) {
HBinaryOperation* instr = HBinaryOperation::cast(value);
if (instr->range() == NULL || instr->range()->CanBeMinusZero()) {
// Propagate to the left argument. If the left argument cannot be -0,
// then the result of the add/sub operation cannot be either.
AddToWorklist(instr->left());
}
} else if (value->IsMathMinMax()) {
HMathMinMax* instr = HMathMinMax::cast(value);
AddToWorklist(instr->right());
AddToWorklist(instr->left());
}
}
in_worklist_.Clear();
ASSERT(in_worklist_.IsEmpty());
ASSERT(worklist_.is_empty());
}
} } // namespace v8::internal
......@@ -37,7 +37,9 @@ namespace internal {
class HRangeAnalysisPhase : public HPhase {
public:
explicit HRangeAnalysisPhase(HGraph* graph)
: HPhase("H_Range analysis", graph), changed_ranges_(16, zone()) { }
: HPhase("H_Range analysis", graph), changed_ranges_(16, zone()),
in_worklist_(graph->GetMaximumValueID(), zone()),
worklist_(32, zone()) {}
void Run();
......@@ -49,8 +51,19 @@ class HRangeAnalysisPhase : public HPhase {
void InferRange(HValue* value);
void RollBackTo(int index);
void AddRange(HValue* value, Range* range);
void AddToWorklist(HValue* value) {
if (in_worklist_.Contains(value->id())) return;
in_worklist_.Add(value->id());
worklist_.Add(value, zone());
}
void PropagateMinusZeroChecks(HValue* value);
ZoneList<HValue*> changed_ranges_;
BitVector in_worklist_;
ZoneList<HValue*> worklist_;
DISALLOW_COPY_AND_ASSIGN(HRangeAnalysisPhase);
};
......
......@@ -48,7 +48,6 @@
#include "hydrogen-gvn.h"
#include "hydrogen-mark-deoptimize.h"
#include "hydrogen-mark-unreachable.h"
#include "hydrogen-minus-zero.h"
#include "hydrogen-osr.h"
#include "hydrogen-range-analysis.h"
#include "hydrogen-redundant-phi.h"
......@@ -4049,10 +4048,9 @@ bool HGraph::Optimize(BailoutReason* bailout_reason) {
if (FLAG_check_elimination) Run<HCheckEliminationPhase>();
if (FLAG_use_range) Run<HRangeAnalysisPhase>();
Run<HRangeAnalysisPhase>();
Run<HComputeChangeUndefinedToNaN>();
Run<HComputeMinusZeroChecksPhase>();
// Eliminate redundant stack checks on backwards branches.
Run<HStackCheckEliminationPhase>();
......
......@@ -407,8 +407,6 @@
'../../src/hydrogen-mark-deoptimize.h',
'../../src/hydrogen-mark-unreachable.cc',
'../../src/hydrogen-mark-unreachable.h',
'../../src/hydrogen-minus-zero.cc',
'../../src/hydrogen-minus-zero.h',
'../../src/hydrogen-osr.cc',
'../../src/hydrogen-osr.h',
'../../src/hydrogen-range-analysis.cc',
......
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