MIPS: Improve code generation for bounds checks.

Port r20872 (0e79653)

BUG=
R=plind44@gmail.com

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

Patch from Balazs Kilvady <kilvadyb@homejinni.com>.

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@20892 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
This commit is contained in:
plind44@gmail.com 2014-04-22 16:56:42 +00:00
parent 137833248a
commit 691865653f
4 changed files with 26 additions and 40 deletions

View File

@ -4162,42 +4162,25 @@ void LCodeGen::DoStoreNamedGeneric(LStoreNamedGeneric* instr) {
} }
void LCodeGen::ApplyCheckIf(Condition condition, void LCodeGen::DoBoundsCheck(LBoundsCheck* instr) {
LBoundsCheck* check, Condition cc = instr->hydrogen()->allow_equality() ? hi : hs;
Register src1, Operand operand(0);
const Operand& src2) { Register reg;
if (FLAG_debug_code && check->hydrogen()->skip_check()) { if (instr->index()->IsConstantOperand()) {
operand = ToOperand(instr->index());
reg = ToRegister(instr->length());
cc = ReverseCondition(cc);
} else {
reg = ToRegister(instr->index());
operand = ToOperand(instr->length());
}
if (FLAG_debug_code && instr->hydrogen()->skip_check()) {
Label done; Label done;
__ Branch(&done, NegateCondition(condition), src1, src2); __ Branch(&done, NegateCondition(cc), reg, operand);
__ stop("eliminated bounds check failed"); __ stop("eliminated bounds check failed");
__ bind(&done); __ bind(&done);
} else { } else {
DeoptimizeIf(condition, check->environment(), src1, src2); DeoptimizeIf(cc, instr->environment(), reg, operand);
}
}
void LCodeGen::DoBoundsCheck(LBoundsCheck* instr) {
if (instr->hydrogen()->skip_check()) return;
Condition condition = instr->hydrogen()->allow_equality() ? hi : hs;
if (instr->index()->IsConstantOperand()) {
int constant_index =
ToInteger32(LConstantOperand::cast(instr->index()));
if (instr->hydrogen()->length()->representation().IsSmi()) {
__ li(at, Operand(Smi::FromInt(constant_index)));
} else {
__ li(at, Operand(constant_index));
}
ApplyCheckIf(condition,
instr,
at,
Operand(ToRegister(instr->length())));
} else {
ApplyCheckIf(condition,
instr,
ToRegister(instr->index()),
Operand(ToRegister(instr->length())));
} }
} }

View File

@ -263,10 +263,6 @@ class LCodeGen: public LCodeGenBase {
LEnvironment* environment, LEnvironment* environment,
Register src1 = zero_reg, Register src1 = zero_reg,
const Operand& src2 = Operand(zero_reg)); const Operand& src2 = Operand(zero_reg));
void ApplyCheckIf(Condition condition,
LBoundsCheck* check,
Register src1 = zero_reg,
const Operand& src2 = Operand(zero_reg));
void AddToTranslation(LEnvironment* environment, void AddToTranslation(LEnvironment* environment,
Translation* translation, Translation* translation,

View File

@ -1782,9 +1782,16 @@ LInstruction* LChunkBuilder::DoSeqStringSetChar(HSeqStringSetChar* instr) {
LInstruction* LChunkBuilder::DoBoundsCheck(HBoundsCheck* instr) { LInstruction* LChunkBuilder::DoBoundsCheck(HBoundsCheck* instr) {
LOperand* value = UseRegisterOrConstantAtStart(instr->index()); if (!FLAG_debug_code && instr->skip_check()) return NULL;
LOperand* length = UseRegister(instr->length()); LOperand* index = UseRegisterOrConstantAtStart(instr->index());
return AssignEnvironment(new(zone()) LBoundsCheck(value, length)); 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

@ -2091,7 +2091,7 @@ void MacroAssembler::BranchShort(Label* L, Condition cond, Register rs,
case Uless_equal: case Uless_equal:
if (rt.imm32_ == 0) { if (rt.imm32_ == 0) {
offset = shifted_branch_offset(L, false); offset = shifted_branch_offset(L, false);
b(offset); beq(rs, zero_reg, offset);
} else { } else {
ASSERT(!scratch.is(rs)); ASSERT(!scratch.is(rs));
r2 = scratch; r2 = scratch;