Commit d0fe2952 authored by ulan@chromium.org's avatar ulan@chromium.org

Revert r20246 "ARM64: Add overflow checking support for multiplications by constant powers of 2."

Reason: mjsunit/mul-exhaustive-part4 fails in no snaphot debug.

TBR=alexandre.rames@arm.com

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

git-svn-id: http://v8.googlecode.com/svn/branches/bleeding_edge@20254 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent f306341b
...@@ -1891,36 +1891,29 @@ LInstruction* LChunkBuilder::DoMul(HMul* instr) { ...@@ -1891,36 +1891,29 @@ LInstruction* LChunkBuilder::DoMul(HMul* instr) {
HValue* least_const = instr->BetterLeftOperand(); HValue* least_const = instr->BetterLeftOperand();
HValue* most_const = instr->BetterRightOperand(); HValue* most_const = instr->BetterRightOperand();
LOperand* left; LOperand* left = UseRegisterAtStart(least_const);
// LMulConstI can handle a subset of constants: // LMulConstI can handle a subset of constants:
// With support for overflow detection: // With support for overflow detection:
// -1, 0, 1, 2 // -1, 0, 1, 2
// 2^n, -(2^n)
// Without support for overflow detection: // Without support for overflow detection:
// 2^n, -(2^n)
// 2^n + 1, -(2^n - 1) // 2^n + 1, -(2^n - 1)
if (most_const->IsConstant()) { if (most_const->IsConstant()) {
int32_t constant = HConstant::cast(most_const)->Integer32Value(); int32_t constant = HConstant::cast(most_const)->Integer32Value();
bool small_constant = (constant >= -1) && (constant <= 2); int32_t constant_abs = (constant >= 0) ? constant : -constant;
bool end_range_constant = (constant <= -kMaxInt) || (constant == kMaxInt);
int32_t constant_abs = Abs(constant); if (((constant >= -1) && (constant <= 2)) ||
(!can_overflow && (IsPowerOf2(constant_abs) ||
if (!end_range_constant && IsPowerOf2(constant_abs + 1) ||
(small_constant || IsPowerOf2(constant_abs - 1)))) {
(IsPowerOf2(constant_abs)) ||
(!can_overflow && (IsPowerOf2(constant_abs + 1) ||
IsPowerOf2(constant_abs - 1))))) {
LConstantOperand* right = UseConstant(most_const); LConstantOperand* right = UseConstant(most_const);
bool need_register = IsPowerOf2(constant_abs) && !small_constant;
left = need_register ? UseRegister(least_const)
: UseRegisterAtStart(least_const);
LMulConstIS* mul = new(zone()) LMulConstIS(left, right); LMulConstIS* mul = new(zone()) LMulConstIS(left, right);
if (needs_environment) AssignEnvironment(mul); if (needs_environment) AssignEnvironment(mul);
return DefineAsRegister(mul); return DefineAsRegister(mul);
} }
} }
left = UseRegisterAtStart(least_const);
// LMulI/S can handle all cases, but it requires that a register is // LMulI/S can handle all cases, but it requires that a register is
// allocated for the second operand. // allocated for the second operand.
LInstruction* result; LInstruction* result;
......
...@@ -4253,7 +4253,6 @@ void LCodeGen::DoMulConstIS(LMulConstIS* instr) { ...@@ -4253,7 +4253,6 @@ void LCodeGen::DoMulConstIS(LMulConstIS* instr) {
Register left = Register left =
is_smi ? ToRegister(instr->left()) : ToRegister32(instr->left()) ; is_smi ? ToRegister(instr->left()) : ToRegister32(instr->left()) ;
int32_t right = ToInteger32(instr->right()); int32_t right = ToInteger32(instr->right());
ASSERT((right > -kMaxInt) || (right < kMaxInt));
bool can_overflow = instr->hydrogen()->CheckFlag(HValue::kCanOverflow); bool can_overflow = instr->hydrogen()->CheckFlag(HValue::kCanOverflow);
bool bailout_on_minus_zero = bool bailout_on_minus_zero =
...@@ -4297,40 +4296,20 @@ void LCodeGen::DoMulConstIS(LMulConstIS* instr) { ...@@ -4297,40 +4296,20 @@ void LCodeGen::DoMulConstIS(LMulConstIS* instr) {
} }
break; break;
// All other cases cannot detect overflow, because it would probably be no
// faster than using the smull method in LMulI.
// TODO(jbramley): Investigate this, and add overflow support if it would
// be useful.
default: default:
// Multiplication by constant powers of two (and some related values)
// can be done efficiently with shifted operands.
int32_t right_abs = Abs(right);
if (IsPowerOf2(right_abs)) {
int right_log2 = WhichPowerOf2(right_abs);
if (can_overflow) {
Register scratch = result;
ASSERT(!AreAliased(scratch, left));
__ Cls(scratch, left);
__ Cmp(scratch, right_log2);
DeoptimizeIf(lt, instr->environment());
}
if (right >= 0) {
// result = left << log2(right)
__ Lsl(result, left, right_log2);
} else {
// result = -left << log2(-right)
__ Neg(result, Operand(left, LSL, right_log2));
}
return;
}
// For the following cases, we could perform a conservative overflow check
// with CLS as above. However the few cycles saved are likely not worth
// the risk of deoptimizing more often than required.
ASSERT(!can_overflow); ASSERT(!can_overflow);
// Multiplication by constant powers of two (and some related values)
// can be done efficiently with shifted operands.
if (right >= 0) { if (right >= 0) {
if (IsPowerOf2(right - 1)) { if (IsPowerOf2(right)) {
// result = left << log2(right)
__ Lsl(result, left, WhichPowerOf2(right));
} else if (IsPowerOf2(right - 1)) {
// result = left + left << log2(right - 1) // result = left + left << log2(right - 1)
__ Add(result, left, Operand(left, LSL, WhichPowerOf2(right - 1))); __ Add(result, left, Operand(left, LSL, WhichPowerOf2(right - 1)));
} else if (IsPowerOf2(right + 1)) { } else if (IsPowerOf2(right + 1)) {
...@@ -4341,7 +4320,10 @@ void LCodeGen::DoMulConstIS(LMulConstIS* instr) { ...@@ -4341,7 +4320,10 @@ void LCodeGen::DoMulConstIS(LMulConstIS* instr) {
UNREACHABLE(); UNREACHABLE();
} }
} else { } else {
if (IsPowerOf2(-right + 1)) { if (IsPowerOf2(-right)) {
// result = -left << log2(-right)
__ Neg(result, Operand(left, LSL, WhichPowerOf2(-right)));
} else if (IsPowerOf2(-right + 1)) {
// result = left - left << log2(-right + 1) // result = left - left << log2(-right + 1)
__ Sub(result, left, Operand(left, LSL, WhichPowerOf2(-right + 1))); __ Sub(result, left, Operand(left, LSL, WhichPowerOf2(-right + 1)));
} else if (IsPowerOf2(-right - 1)) { } else if (IsPowerOf2(-right - 1)) {
...@@ -4352,6 +4334,7 @@ void LCodeGen::DoMulConstIS(LMulConstIS* instr) { ...@@ -4352,6 +4334,7 @@ void LCodeGen::DoMulConstIS(LMulConstIS* instr) {
UNREACHABLE(); UNREACHABLE();
} }
} }
break;
} }
} }
......
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