Improve code generation for bounds checks.

R=svenpanne@chromium.org

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

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@20872 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
This commit is contained in:
bmeurer@chromium.org 2014-04-22 08:28:14 +00:00
parent 2c394ad00d
commit af05141176
12 changed files with 139 additions and 143 deletions

View File

@ -1830,9 +1830,16 @@ LInstruction* LChunkBuilder::DoSeqStringSetChar(HSeqStringSetChar* instr) {
LInstruction* LChunkBuilder::DoBoundsCheck(HBoundsCheck* instr) {
LOperand* value = UseRegisterOrConstantAtStart(instr->index());
LOperand* length = UseRegister(instr->length());
return AssignEnvironment(new(zone()) LBoundsCheck(value, length));
if (!FLAG_debug_code && instr->skip_check()) return NULL;
LOperand* index = UseRegisterOrConstantAtStart(instr->index());
LOperand* length = !index->IsConstantOperand()
? UseRegisterOrConstantAtStart(instr->length())
: UseRegisterAtStart(instr->length());
LInstruction* result = new(zone()) LBoundsCheck(index, length);
if (!FLAG_debug_code || !instr->skip_check()) {
result = AssignEnvironment(result);
}
return result;
}

View File

@ -4188,38 +4188,29 @@ void LCodeGen::DoStoreNamedGeneric(LStoreNamedGeneric* instr) {
}
void LCodeGen::ApplyCheckIf(Condition condition, LBoundsCheck* check) {
if (FLAG_debug_code && check->hydrogen()->skip_check()) {
void LCodeGen::DoBoundsCheck(LBoundsCheck* instr) {
Condition cc = instr->hydrogen()->allow_equality() ? hi : hs;
if (instr->index()->IsConstantOperand()) {
Operand index = ToOperand(instr->index());
Register length = ToRegister(instr->length());
__ cmp(length, index);
cc = ReverseCondition(cc);
} else {
Register index = ToRegister(instr->index());
Operand length = ToOperand(instr->length());
__ cmp(index, length);
}
if (FLAG_debug_code && instr->hydrogen()->skip_check()) {
Label done;
__ b(NegateCondition(condition), &done);
__ b(NegateCondition(cc), &done);
__ stop("eliminated bounds check failed");
__ bind(&done);
} else {
DeoptimizeIf(condition, check->environment());
DeoptimizeIf(cc, instr->environment());
}
}
void LCodeGen::DoBoundsCheck(LBoundsCheck* instr) {
if (instr->hydrogen()->skip_check()) return;
if (instr->index()->IsConstantOperand()) {
int constant_index =
ToInteger32(LConstantOperand::cast(instr->index()));
if (instr->hydrogen()->length()->representation().IsSmi()) {
__ mov(ip, Operand(Smi::FromInt(constant_index)));
} else {
__ mov(ip, Operand(constant_index));
}
__ cmp(ip, ToRegister(instr->length()));
} else {
__ cmp(ToRegister(instr->index()), ToRegister(instr->length()));
}
Condition condition = instr->hydrogen()->allow_equality() ? hi : hs;
ApplyCheckIf(condition, instr);
}
void LCodeGen::DoStoreKeyedExternalArray(LStoreKeyed* instr) {
Register external_pointer = ToRegister(instr->elements());
Register key = no_reg;

View File

@ -264,7 +264,6 @@ class LCodeGen: public LCodeGenBase {
LEnvironment* environment,
Deoptimizer::BailoutType bailout_type);
void DeoptimizeIf(Condition condition, LEnvironment* environment);
void ApplyCheckIf(Condition condition, LBoundsCheck* check);
void AddToTranslation(LEnvironment* environment,
Translation* translation,

View File

@ -949,9 +949,16 @@ LInstruction* LChunkBuilder::DoBlockEntry(HBlockEntry* instr) {
LInstruction* LChunkBuilder::DoBoundsCheck(HBoundsCheck* instr) {
LOperand* value = UseRegisterOrConstantAtStart(instr->index());
LOperand* length = UseRegister(instr->length());
return AssignEnvironment(new(zone()) LBoundsCheck(value, length));
if (!FLAG_debug_code && instr->skip_check()) return NULL;
LOperand* index = UseRegisterOrConstantAtStart(instr->index());
LOperand* length = !index->IsConstantOperand()
? UseRegisterOrConstantAtStart(instr->length())
: UseRegisterAtStart(instr->length());
LInstruction* result = new(zone()) LBoundsCheck(index, length);
if (!FLAG_debug_code || !instr->skip_check()) {
result = AssignEnvironment(result);
}
return result;
}

View File

@ -1775,39 +1775,28 @@ void LCodeGen::DoBitS(LBitS* instr) {
}
void LCodeGen::ApplyCheckIf(Condition cc, LBoundsCheck* check) {
if (FLAG_debug_code && check->hydrogen()->skip_check()) {
void LCodeGen::DoBoundsCheck(LBoundsCheck *instr) {
Condition cc = instr->hydrogen()->allow_equality() ? hi : hs;
ASSERT(instr->hydrogen()->index()->representation().IsInteger32());
ASSERT(instr->hydrogen()->length()->representation().IsInteger32());
if (instr->index()->IsConstantOperand()) {
Operand index = ToOperand32I(instr->index());
Register length = ToRegister32(instr->length());
__ Cmp(length, index);
cc = ReverseConditionForCmp(cc);
} else {
Register index = ToRegister32(instr->index());
Operand length = ToOperand32I(instr->length());
__ Cmp(index, length);
}
if (FLAG_debug_code && instr->hydrogen()->skip_check()) {
__ Assert(InvertCondition(cc), kEliminatedBoundsCheckFailed);
} else {
DeoptimizeIf(cc, check->environment());
DeoptimizeIf(cc, instr->environment());
}
}
void LCodeGen::DoBoundsCheck(LBoundsCheck *instr) {
if (instr->hydrogen()->skip_check()) return;
ASSERT(instr->hydrogen()->length()->representation().IsInteger32());
Register length = ToRegister32(instr->length());
if (instr->index()->IsConstantOperand()) {
int constant_index =
ToInteger32(LConstantOperand::cast(instr->index()));
if (instr->hydrogen()->length()->representation().IsSmi()) {
__ Cmp(length, Smi::FromInt(constant_index));
} else {
__ Cmp(length, constant_index);
}
} else {
ASSERT(instr->hydrogen()->index()->representation().IsInteger32());
__ Cmp(length, ToRegister32(instr->index()));
}
Condition condition = instr->hydrogen()->allow_equality() ? lo : ls;
ApplyCheckIf(condition, instr);
}
void LCodeGen::DoBranch(LBranch* instr) {
Representation r = instr->hydrogen()->value()->representation();
Label* true_label = instr->TrueLabel(chunk_);

View File

@ -243,7 +243,6 @@ class LCodeGen: public LCodeGenBase {
void DeoptimizeIfMinusZero(DoubleRegister input, LEnvironment* environment);
void DeoptimizeIfBitSet(Register rt, int bit, LEnvironment* environment);
void DeoptimizeIfBitClear(Register rt, int bit, LEnvironment* environment);
void ApplyCheckIf(Condition cc, LBoundsCheck* check);
MemOperand PrepareKeyedExternalArrayOperand(Register key,
Register base,

View File

@ -4497,34 +4497,27 @@ void LCodeGen::DoStoreNamedGeneric(LStoreNamedGeneric* instr) {
}
void LCodeGen::ApplyCheckIf(Condition cc, LBoundsCheck* check) {
if (FLAG_debug_code && check->hydrogen()->skip_check()) {
void LCodeGen::DoBoundsCheck(LBoundsCheck* instr) {
Condition cc = instr->hydrogen()->allow_equality() ? above : above_equal;
if (instr->index()->IsConstantOperand()) {
__ cmp(ToOperand(instr->length()),
ToImmediate(LConstantOperand::cast(instr->index()),
instr->hydrogen()->length()->representation()));
cc = ReverseCondition(cc);
} else if (instr->length()->IsConstantOperand()) {
__ cmp(ToOperand(instr->index()),
ToImmediate(LConstantOperand::cast(instr->length()),
instr->hydrogen()->index()->representation()));
} else {
__ cmp(ToRegister(instr->index()), ToOperand(instr->length()));
}
if (FLAG_debug_code && instr->hydrogen()->skip_check()) {
Label done;
__ j(NegateCondition(cc), &done, Label::kNear);
__ int3();
__ bind(&done);
} else {
DeoptimizeIf(cc, check->environment());
}
}
void LCodeGen::DoBoundsCheck(LBoundsCheck* instr) {
if (instr->hydrogen()->skip_check() && !FLAG_debug_code) return;
if (instr->index()->IsConstantOperand()) {
Immediate immediate =
ToImmediate(LConstantOperand::cast(instr->index()),
instr->hydrogen()->length()->representation());
__ cmp(ToOperand(instr->length()), immediate);
Condition condition =
instr->hydrogen()->allow_equality() ? below : below_equal;
ApplyCheckIf(condition, instr);
} else {
__ cmp(ToRegister(instr->index()), ToOperand(instr->length()));
Condition condition =
instr->hydrogen()->allow_equality() ? above : above_equal;
ApplyCheckIf(condition, instr);
DeoptimizeIf(cc, instr->environment());
}
}

View File

@ -271,7 +271,6 @@ class LCodeGen: public LCodeGenBase {
LEnvironment* environment,
Deoptimizer::BailoutType bailout_type);
void DeoptimizeIf(Condition cc, LEnvironment* environment);
void ApplyCheckIf(Condition cc, LBoundsCheck* check);
bool DeoptEveryNTimes() {
return FLAG_deopt_every_n_times != 0 && !info()->IsStub();

View File

@ -1865,9 +1865,16 @@ LInstruction* LChunkBuilder::DoSeqStringSetChar(HSeqStringSetChar* instr) {
LInstruction* LChunkBuilder::DoBoundsCheck(HBoundsCheck* instr) {
return AssignEnvironment(new(zone()) LBoundsCheck(
UseRegisterOrConstantAtStart(instr->index()),
UseAtStart(instr->length())));
if (!FLAG_debug_code && instr->skip_check()) return NULL;
LOperand* index = UseRegisterOrConstantAtStart(instr->index());
LOperand* length = !index->IsConstantOperand()
? UseOrConstantAtStart(instr->length())
: UseAtStart(instr->length());
LInstruction* result = new(zone()) LBoundsCheck(index, length);
if (!FLAG_debug_code || !instr->skip_check()) {
result = AssignEnvironment(result);
}
return result;
}

View File

@ -4140,68 +4140,67 @@ void LCodeGen::DoStoreNamedGeneric(LStoreNamedGeneric* instr) {
}
void LCodeGen::ApplyCheckIf(Condition cc, LBoundsCheck* check) {
if (FLAG_debug_code && check->hydrogen()->skip_check()) {
void LCodeGen::DoBoundsCheck(LBoundsCheck* instr) {
Representation representation = instr->hydrogen()->length()->representation();
ASSERT(representation.Equals(instr->hydrogen()->index()->representation()));
ASSERT(representation.IsSmiOrInteger32());
Condition cc = instr->hydrogen()->allow_equality() ? below : below_equal;
if (instr->length()->IsConstantOperand()) {
int32_t length = ToInteger32(LConstantOperand::cast(instr->length()));
Register index = ToRegister(instr->index());
if (representation.IsSmi()) {
__ Cmp(index, Smi::FromInt(length));
} else {
__ cmpl(index, Immediate(length));
}
cc = ReverseCondition(cc);
} else if (instr->index()->IsConstantOperand()) {
int32_t index = ToInteger32(LConstantOperand::cast(instr->index()));
if (instr->length()->IsRegister()) {
Register length = ToRegister(instr->length());
if (representation.IsSmi()) {
__ Cmp(length, Smi::FromInt(index));
} else {
__ cmpl(length, Immediate(index));
}
} else {
Operand length = ToOperand(instr->length());
if (representation.IsSmi()) {
__ Cmp(length, Smi::FromInt(index));
} else {
__ cmpl(length, Immediate(index));
}
}
} else {
Register index = ToRegister(instr->index());
if (instr->length()->IsRegister()) {
Register length = ToRegister(instr->length());
if (representation.IsSmi()) {
__ cmpp(length, index);
} else {
__ cmpl(length, index);
}
} else {
Operand length = ToOperand(instr->length());
if (representation.IsSmi()) {
__ cmpp(length, index);
} else {
__ cmpl(length, index);
}
}
}
if (FLAG_debug_code && instr->hydrogen()->skip_check()) {
Label done;
__ j(NegateCondition(cc), &done, Label::kNear);
__ int3();
__ bind(&done);
} else {
DeoptimizeIf(cc, check->environment());
DeoptimizeIf(cc, instr->environment());
}
}
void LCodeGen::DoBoundsCheck(LBoundsCheck* instr) {
HBoundsCheck* hinstr = instr->hydrogen();
if (hinstr->skip_check()) return;
Representation representation = hinstr->length()->representation();
ASSERT(representation.Equals(hinstr->index()->representation()));
ASSERT(representation.IsSmiOrInteger32());
if (instr->length()->IsRegister()) {
Register reg = ToRegister(instr->length());
if (instr->index()->IsConstantOperand()) {
int32_t constant_index =
ToInteger32(LConstantOperand::cast(instr->index()));
if (representation.IsSmi()) {
__ Cmp(reg, Smi::FromInt(constant_index));
} else {
__ cmpl(reg, Immediate(constant_index));
}
} else {
Register reg2 = ToRegister(instr->index());
if (representation.IsSmi()) {
__ cmpp(reg, reg2);
} else {
__ cmpl(reg, reg2);
}
}
} else {
Operand length = ToOperand(instr->length());
if (instr->index()->IsConstantOperand()) {
int32_t constant_index =
ToInteger32(LConstantOperand::cast(instr->index()));
if (representation.IsSmi()) {
__ Cmp(length, Smi::FromInt(constant_index));
} else {
__ cmpl(length, Immediate(constant_index));
}
} else {
if (representation.IsSmi()) {
__ cmpp(length, ToRegister(instr->index()));
} else {
__ cmpl(length, ToRegister(instr->index()));
}
}
}
Condition condition = hinstr->allow_equality() ? below : below_equal;
ApplyCheckIf(condition, instr);
}
void LCodeGen::DoStoreKeyedExternalArray(LStoreKeyed* instr) {
ElementsKind elements_kind = instr->elements_kind();
LOperand* key = instr->key();

View File

@ -227,7 +227,6 @@ class LCodeGen: public LCodeGenBase {
LEnvironment* environment,
Deoptimizer::BailoutType bailout_type);
void DeoptimizeIf(Condition cc, LEnvironment* environment);
void ApplyCheckIf(Condition cc, LBoundsCheck* check);
bool DeoptEveryNTimes() {
return FLAG_deopt_every_n_times != 0 && !info()->IsStub();

View File

@ -1789,9 +1789,16 @@ LInstruction* LChunkBuilder::DoSeqStringSetChar(HSeqStringSetChar* instr) {
LInstruction* LChunkBuilder::DoBoundsCheck(HBoundsCheck* instr) {
LOperand* value = UseRegisterOrConstantAtStart(instr->index());
LOperand* length = Use(instr->length());
return AssignEnvironment(new(zone()) LBoundsCheck(value, length));
if (!FLAG_debug_code && instr->skip_check()) return NULL;
LOperand* index = UseRegisterOrConstantAtStart(instr->index());
LOperand* length = !index->IsConstantOperand()
? UseOrConstantAtStart(instr->length())
: UseAtStart(instr->length());
LInstruction* result = new(zone()) LBoundsCheck(index, length);
if (!FLAG_debug_code || !instr->skip_check()) {
result = AssignEnvironment(result);
}
return result;
}