Allow comparison in UINT32 mode.

Shamelessly based on parts of https://codereview.chromium.org/288853003/. :-)

R=jkummerow@chromium.org

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

git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@21355 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
This commit is contained in:
svenpanne@chromium.org 2014-05-19 07:47:09 +00:00
parent ba5763f3cb
commit ec23d0b815
6 changed files with 45 additions and 11 deletions

View File

@ -2361,7 +2361,8 @@ Condition LCodeGen::TokenToCondition(Token::Value op, bool is_unsigned) {
void LCodeGen::DoCompareNumericAndBranch(LCompareNumericAndBranch* instr) {
LOperand* left = instr->left();
LOperand* right = instr->right();
Condition cond = TokenToCondition(instr->op(), false);
bool is_unsigned = instr->hydrogen()->CheckFlag(HInstruction::kUint32);
Condition cond = TokenToCondition(instr->op(), is_unsigned);
if (left->IsConstantOperand() && right->IsConstantOperand()) {
// We can statically evaluate the comparison.

View File

@ -2429,7 +2429,8 @@ void LCodeGen::DoCompareMinusZeroAndBranch(LCompareMinusZeroAndBranch* instr) {
void LCodeGen::DoCompareNumericAndBranch(LCompareNumericAndBranch* instr) {
LOperand* left = instr->left();
LOperand* right = instr->right();
Condition cond = TokenToCondition(instr->op(), false);
bool is_unsigned = instr->hydrogen()->CheckFlag(HInstruction::kUint32);
Condition cond = TokenToCondition(instr->op(), is_unsigned);
if (left->IsConstantOperand() && right->IsConstantOperand()) {
// We can statically evaluate the comparison.

View File

@ -8,6 +8,30 @@ namespace v8 {
namespace internal {
static bool IsUnsignedLoad(HLoadKeyed* instr) {
switch (instr->elements_kind()) {
case EXTERNAL_UINT8_ELEMENTS:
case EXTERNAL_UINT16_ELEMENTS:
case EXTERNAL_UINT32_ELEMENTS:
case EXTERNAL_UINT8_CLAMPED_ELEMENTS:
case UINT8_ELEMENTS:
case UINT16_ELEMENTS:
case UINT32_ELEMENTS:
case UINT8_CLAMPED_ELEMENTS:
return true;
default:
return false;
}
}
static bool IsUint32Operation(HValue* instr) {
return instr->IsShr() ||
(instr->IsLoadKeyed() && IsUnsignedLoad(HLoadKeyed::cast(instr))) ||
(instr->IsInteger32Constant() && instr->GetInteger32Constant() >= 0);
}
bool HUint32AnalysisPhase::IsSafeUint32Use(HValue* val, HValue* use) {
// Operations that operate on bits are safe.
if (use->IsBitwise() || use->IsShl() || use->IsSar() || use->IsShr()) {
@ -37,6 +61,9 @@ bool HUint32AnalysisPhase::IsSafeUint32Use(HValue* val, HValue* use) {
return true;
}
}
} else if (use->IsCompareNumericAndBranch()) {
HCompareNumericAndBranch* c = HCompareNumericAndBranch::cast(use);
return IsUint32Operation(c->left()) && IsUint32Operation(c->right());
}
return false;

View File

@ -1645,11 +1645,11 @@ void LCodeGen::DoShiftI(LShiftI* instr) {
}
break;
case Token::SHR:
if (shift_count == 0 && instr->can_deopt()) {
if (shift_count != 0) {
__ shr(ToRegister(left), shift_count);
} else if (instr->can_deopt()) {
__ test(ToRegister(left), ToRegister(left));
DeoptimizeIf(sign, instr->environment());
} else {
__ shr(ToRegister(left), shift_count);
}
break;
case Token::SHL:
@ -2236,7 +2236,9 @@ Condition LCodeGen::TokenToCondition(Token::Value op, bool is_unsigned) {
void LCodeGen::DoCompareNumericAndBranch(LCompareNumericAndBranch* instr) {
LOperand* left = instr->left();
LOperand* right = instr->right();
Condition cc = TokenToCondition(instr->op(), instr->is_double());
bool is_unsigned =
instr->is_double() || instr->hydrogen()->CheckFlag(HInstruction::kUint32);
Condition cc = TokenToCondition(instr->op(), is_unsigned);
if (left->IsConstantOperand() && right->IsConstantOperand()) {
// We can statically evaluate the comparison.

View File

@ -2270,7 +2270,8 @@ Condition LCodeGen::TokenToCondition(Token::Value op, bool is_unsigned) {
void LCodeGen::DoCompareNumericAndBranch(LCompareNumericAndBranch* instr) {
LOperand* left = instr->left();
LOperand* right = instr->right();
Condition cond = TokenToCondition(instr->op(), false);
bool is_unsigned = instr->hydrogen()->CheckFlag(HInstruction::kUint32);
Condition cc = TokenToCondition(instr->op(), is_unsigned);
if (left->IsConstantOperand() && right->IsConstantOperand()) {
// We can statically evaluate the comparison.

View File

@ -1605,11 +1605,11 @@ void LCodeGen::DoShiftI(LShiftI* instr) {
}
break;
case Token::SHR:
if (shift_count == 0 && instr->can_deopt()) {
if (shift_count != 0) {
__ shrl(ToRegister(left), Immediate(shift_count));
} else if (instr->can_deopt()) {
__ testl(ToRegister(left), ToRegister(left));
DeoptimizeIf(negative, instr->environment());
} else {
__ shrl(ToRegister(left), Immediate(shift_count));
}
break;
case Token::SHL:
@ -2227,7 +2227,9 @@ inline Condition LCodeGen::TokenToCondition(Token::Value op, bool is_unsigned) {
void LCodeGen::DoCompareNumericAndBranch(LCompareNumericAndBranch* instr) {
LOperand* left = instr->left();
LOperand* right = instr->right();
Condition cc = TokenToCondition(instr->op(), instr->is_double());
bool is_unsigned =
instr->is_double() || instr->hydrogen()->CheckFlag(HInstruction::kUint32);
Condition cc = TokenToCondition(instr->op(), is_unsigned);
if (left->IsConstantOperand() && right->IsConstantOperand()) {
// We can statically evaluate the comparison.