From ca741a0b3c244a690b2ad263ed5b389c9628d5d4 Mon Sep 17 00:00:00 2001 From: bmeurer Date: Tue, 13 Jan 2015 02:01:06 -0800 Subject: [PATCH] [turbofan] Avoid expensive fixup for Uint32Div if divisor is even. R=dcarney@chromium.org Review URL: https://codereview.chromium.org/840813008 Cr-Commit-Position: refs/heads/master@{#26036} --- src/compiler/machine-operator-reducer.cc | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/compiler/machine-operator-reducer.cc b/src/compiler/machine-operator-reducer.cc index 9b0c2b2..b7142a5 100644 --- a/src/compiler/machine-operator-reducer.cc +++ b/src/compiler/machine-operator-reducer.cc @@ -104,8 +104,14 @@ Node* MachineOperatorReducer::Int32Div(Node* dividend, int32_t divisor) { Node* MachineOperatorReducer::Uint32Div(Node* dividend, uint32_t divisor) { DCHECK_LT(0, divisor); + // If the divisor is even, we can avoid using the expensive fixup by shifting + // the dividend upfront. + unsigned const shift = base::bits::CountTrailingZeros32(divisor); + dividend = Word32Shr(dividend, shift); + divisor >>= shift; + // Compute the magic number for the (shifted) divisor. base::MagicNumbersForDivision const mag = - base::UnsignedDivisionByConstant(bit_cast(divisor)); + base::UnsignedDivisionByConstant(divisor, shift); Node* quotient = graph()->NewNode(machine()->Uint32MulHigh(), dividend, Uint32Constant(mag.multiplier)); if (mag.add) { -- 2.7.4