Commit af051411 authored by bmeurer@chromium.org's avatar bmeurer@chromium.org

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
parent 2c394ad0
......@@ -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;
}
......
......@@ -4188,35 +4188,26 @@ 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());
}
}
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()));
DeoptimizeIf(cc, instr->environment());
}
Condition condition = instr->hydrogen()->allow_equality() ? hi : hs;
ApplyCheckIf(condition, instr);
}
......
......@@ -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,
......
......@@ -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;
}
......
......@@ -1775,36 +1775,25 @@ void LCodeGen::DoBitS(LBitS* instr) {
}
void LCodeGen::ApplyCheckIf(Condition cc, LBoundsCheck* check) {
if (FLAG_debug_code && check->hydrogen()->skip_check()) {
__ Assert(InvertCondition(cc), kEliminatedBoundsCheckFailed);
} else {
DeoptimizeIf(cc, check->environment());
}
}
void LCodeGen::DoBoundsCheck(LBoundsCheck *instr) {
if (instr->hydrogen()->skip_check()) return;
Condition cc = instr->hydrogen()->allow_equality() ? hi : hs;
ASSERT(instr->hydrogen()->index()->representation().IsInteger32());
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);
}
Operand index = ToOperand32I(instr->index());
Register length = ToRegister32(instr->length());
__ Cmp(length, index);
cc = ReverseConditionForCmp(cc);
} else {
ASSERT(instr->hydrogen()->index()->representation().IsInteger32());
__ Cmp(length, ToRegister32(instr->index()));
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, instr->environment());
}
Condition condition = instr->hydrogen()->allow_equality() ? lo : ls;
ApplyCheckIf(condition, instr);
}
......
......@@ -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,
......
......@@ -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());
}
}
......
......@@ -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();
......
......@@ -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;
}
......
......@@ -4140,65 +4140,64 @@ void LCodeGen::DoStoreNamedGeneric(LStoreNamedGeneric* instr) {
}
void LCodeGen::ApplyCheckIf(Condition cc, LBoundsCheck* check) {
if (FLAG_debug_code && check->hydrogen()->skip_check()) {
Label done;
__ j(NegateCondition(cc), &done, Label::kNear);
__ int3();
__ bind(&done);
} else {
DeoptimizeIf(cc, check->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()));
Representation representation = instr->hydrogen()->length()->representation();
ASSERT(representation.Equals(instr->hydrogen()->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()));
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(reg, Smi::FromInt(constant_index));
__ Cmp(length, Smi::FromInt(index));
} else {
__ cmpl(reg, Immediate(constant_index));
__ cmpl(length, Immediate(index));
}
} else {
Register reg2 = ToRegister(instr->index());
Operand length = ToOperand(instr->length());
if (representation.IsSmi()) {
__ cmpp(reg, reg2);
__ Cmp(length, Smi::FromInt(index));
} else {
__ cmpl(reg, reg2);
__ cmpl(length, Immediate(index));
}
}
} else {
Operand length = ToOperand(instr->length());
if (instr->index()->IsConstantOperand()) {
int32_t constant_index =
ToInteger32(LConstantOperand::cast(instr->index()));
Register index = ToRegister(instr->index());
if (instr->length()->IsRegister()) {
Register length = ToRegister(instr->length());
if (representation.IsSmi()) {
__ Cmp(length, Smi::FromInt(constant_index));
__ cmpp(length, index);
} else {
__ cmpl(length, Immediate(constant_index));
__ cmpl(length, index);
}
} else {
Operand length = ToOperand(instr->length());
if (representation.IsSmi()) {
__ cmpp(length, ToRegister(instr->index()));
__ cmpp(length, index);
} else {
__ cmpl(length, ToRegister(instr->index()));
__ cmpl(length, index);
}
}
}
Condition condition = hinstr->allow_equality() ? below : below_equal;
ApplyCheckIf(condition, instr);
if (FLAG_debug_code && instr->hydrogen()->skip_check()) {
Label done;
__ j(NegateCondition(cc), &done, Label::kNear);
__ int3();
__ bind(&done);
} else {
DeoptimizeIf(cc, instr->environment());
}
}
......
......@@ -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();
......
......@@ -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;
}
......
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