Make MathFloorOfDiv optimization trigger more often
BUG=v8:2205 R=yangguo@chromium.org Review URL: https://codereview.chromium.org/16973002 git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@15161 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
This commit is contained in:
parent
f751e89416
commit
de71923b20
@ -1403,19 +1403,6 @@ bool LChunkBuilder::HasMagicNumberForDivisor(int32_t divisor) {
|
||||
}
|
||||
|
||||
|
||||
HValue* LChunkBuilder::SimplifiedDividendForMathFloorOfDiv(HValue* dividend) {
|
||||
// A value with an integer representation does not need to be transformed.
|
||||
if (dividend->representation().IsInteger32()) {
|
||||
return dividend;
|
||||
// A change from an integer32 can be replaced by the integer32 value.
|
||||
} else if (dividend->IsChange() &&
|
||||
HChange::cast(dividend)->from().IsInteger32()) {
|
||||
return HChange::cast(dividend)->value();
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
HValue* LChunkBuilder::SimplifiedDivisorForMathFloorOfDiv(HValue* divisor) {
|
||||
if (CpuFeatures::IsSupported(SUDIV)) {
|
||||
// A value with an integer representation does not need to be transformed.
|
||||
|
@ -2692,7 +2692,6 @@ class LChunkBuilder BASE_EMBEDDED {
|
||||
LInstruction* DoRSub(HSub* instr);
|
||||
|
||||
static bool HasMagicNumberForDivisor(int32_t divisor);
|
||||
static HValue* SimplifiedDividendForMathFloorOfDiv(HValue* val);
|
||||
static HValue* SimplifiedDivisorForMathFloorOfDiv(HValue* val);
|
||||
|
||||
LInstruction* DoMathFloor(HUnaryMathOperation* instr);
|
||||
|
@ -1510,30 +1510,52 @@ void HChange::PrintDataTo(StringStream* stream) {
|
||||
}
|
||||
|
||||
|
||||
static HValue* SimplifiedDividendForMathFloorOfDiv(
|
||||
HValue* dividend,
|
||||
Representation observed_representation) {
|
||||
// A value with an integer representation does not need to be transformed.
|
||||
if (dividend->representation().IsInteger32()) {
|
||||
return dividend;
|
||||
}
|
||||
// A change from an integer32 can be replaced by the integer32 value.
|
||||
if (dividend->IsChange() &&
|
||||
HChange::cast(dividend)->from().IsInteger32()) {
|
||||
return HChange::cast(dividend)->value();
|
||||
}
|
||||
// If we've only seen integers so far, insert an appropriate change.
|
||||
if (observed_representation.IsSmiOrInteger32()) {
|
||||
return new(dividend->block()->zone())
|
||||
HChange(dividend, Representation::Integer32(), false, false);
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
HValue* HUnaryMathOperation::Canonicalize() {
|
||||
if (op() == kMathFloor) {
|
||||
HValue* val = value();
|
||||
if (val->IsChange()) val = HChange::cast(val)->value();
|
||||
|
||||
// If the input is integer32 then we replace the floor instruction
|
||||
// with its input. This happens before the representation changes are
|
||||
// introduced.
|
||||
|
||||
// TODO(2205): The above comment is lying. All of this happens
|
||||
// *after* representation changes are introduced. We should check
|
||||
// for value->IsChange() and react accordingly if yes.
|
||||
|
||||
if (value()->representation().IsInteger32()) return value();
|
||||
// with its input.
|
||||
if (val->representation().IsInteger32()) return val;
|
||||
|
||||
#if defined(V8_TARGET_ARCH_ARM) || defined(V8_TARGET_ARCH_IA32) || \
|
||||
defined(V8_TARGET_ARCH_X64)
|
||||
if (value()->IsDiv() && (value()->UseCount() == 1)) {
|
||||
// TODO(2038): Implement this optimization for non ARM architectures.
|
||||
HDiv* hdiv = HDiv::cast(value());
|
||||
if (val->IsDiv() && (val->UseCount() == 1)) {
|
||||
HDiv* hdiv = HDiv::cast(val);
|
||||
HValue* left = hdiv->left();
|
||||
HValue* right = hdiv->right();
|
||||
// Try to simplify left and right values of the division.
|
||||
HValue* new_left =
|
||||
LChunkBuilder::SimplifiedDividendForMathFloorOfDiv(left);
|
||||
HValue* new_left = SimplifiedDividendForMathFloorOfDiv(
|
||||
left, hdiv->observed_input_representation(1));
|
||||
HValue* new_right =
|
||||
LChunkBuilder::SimplifiedDivisorForMathFloorOfDiv(right);
|
||||
LChunkBuilder::SimplifiedDivisorForMathFloorOfDiv(right);
|
||||
if (new_right == NULL &&
|
||||
hdiv->observed_input_representation(2).IsSmiOrInteger32()) {
|
||||
new_right = new(block()->zone())
|
||||
HChange(right, Representation::Integer32(), false, false);
|
||||
}
|
||||
|
||||
// Return if left or right are not optimizable.
|
||||
if ((new_left == NULL) || (new_right == NULL)) return this;
|
||||
@ -1547,9 +1569,8 @@ HValue* HUnaryMathOperation::Canonicalize() {
|
||||
!HInstruction::cast(new_right)->IsLinked()) {
|
||||
HInstruction::cast(new_right)->InsertBefore(this);
|
||||
}
|
||||
HMathFloorOfDiv* instr = new(block()->zone()) HMathFloorOfDiv(context(),
|
||||
new_left,
|
||||
new_right);
|
||||
HMathFloorOfDiv* instr = new(block()->zone())
|
||||
HMathFloorOfDiv(context(), new_left, new_right);
|
||||
// Replace this HMathFloor instruction by the new HMathFloorOfDiv.
|
||||
instr->InsertBefore(this);
|
||||
ReplaceAllUsesWith(instr);
|
||||
|
@ -2985,6 +2985,15 @@ void HGraph::MergeRemovableSimulates() {
|
||||
}
|
||||
continue;
|
||||
}
|
||||
if (current->IsReturn()) {
|
||||
// Drop mergeable simulates in the list. This is safe because
|
||||
// simulates after instructions with side effects are never added
|
||||
// to the merge list.
|
||||
while (!mergelist.is_empty()) {
|
||||
mergelist.RemoveLast()->DeleteAndReplaceWith(NULL);
|
||||
}
|
||||
continue;
|
||||
}
|
||||
// Skip the non-simulates and the first simulate.
|
||||
if (!current->IsSimulate()) continue;
|
||||
if (first) {
|
||||
|
@ -1470,19 +1470,6 @@ LInstruction* LChunkBuilder::DoDiv(HDiv* instr) {
|
||||
}
|
||||
|
||||
|
||||
HValue* LChunkBuilder::SimplifiedDividendForMathFloorOfDiv(HValue* dividend) {
|
||||
// A value with an integer representation does not need to be transformed.
|
||||
if (dividend->representation().IsInteger32()) {
|
||||
return dividend;
|
||||
// A change from an integer32 can be replaced by the integer32 value.
|
||||
} else if (dividend->IsChange() &&
|
||||
HChange::cast(dividend)->from().IsInteger32()) {
|
||||
return HChange::cast(dividend)->value();
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
HValue* LChunkBuilder::SimplifiedDivisorForMathFloorOfDiv(HValue* divisor) {
|
||||
if (divisor->IsConstant() &&
|
||||
HConstant::cast(divisor)->HasInteger32Value()) {
|
||||
|
@ -2813,7 +2813,6 @@ class LChunkBuilder BASE_EMBEDDED {
|
||||
HYDROGEN_CONCRETE_INSTRUCTION_LIST(DECLARE_DO)
|
||||
#undef DECLARE_DO
|
||||
|
||||
static HValue* SimplifiedDividendForMathFloorOfDiv(HValue* val);
|
||||
static HValue* SimplifiedDivisorForMathFloorOfDiv(HValue* val);
|
||||
|
||||
LInstruction* DoMathFloor(HUnaryMathOperation* instr);
|
||||
|
@ -1385,19 +1385,6 @@ LInstruction* LChunkBuilder::DoDiv(HDiv* instr) {
|
||||
}
|
||||
|
||||
|
||||
HValue* LChunkBuilder::SimplifiedDividendForMathFloorOfDiv(HValue* dividend) {
|
||||
// A value with an integer representation does not need to be transformed.
|
||||
if (dividend->representation().IsInteger32()) {
|
||||
return dividend;
|
||||
// A change from an integer32 can be replaced by the integer32 value.
|
||||
} else if (dividend->IsChange() &&
|
||||
HChange::cast(dividend)->from().IsInteger32()) {
|
||||
return HChange::cast(dividend)->value();
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
HValue* LChunkBuilder::SimplifiedDivisorForMathFloorOfDiv(HValue* divisor) {
|
||||
if (divisor->IsConstant() &&
|
||||
HConstant::cast(divisor)->HasInteger32Value()) {
|
||||
|
@ -2590,7 +2590,6 @@ class LChunkBuilder BASE_EMBEDDED {
|
||||
HYDROGEN_CONCRETE_INSTRUCTION_LIST(DECLARE_DO)
|
||||
#undef DECLARE_DO
|
||||
|
||||
static HValue* SimplifiedDividendForMathFloorOfDiv(HValue* val);
|
||||
static HValue* SimplifiedDivisorForMathFloorOfDiv(HValue* val);
|
||||
|
||||
LInstruction* DoMathFloor(HUnaryMathOperation* instr);
|
||||
|
Loading…
Reference in New Issue
Block a user