Reviewers: Vyacheslav Egorov (Google),
https://chromiumcodereview.appspot.com/10825071/diff/1/src/hydrogen-instructions.cc
File src/hydrogen-instructions.cc (right):
https://chromiumcodereview.appspot.com/10825071/diff/1/src/hydrogen-instructions.cc#newcode1151
src/hydrogen-instructions.cc:1151: if (change->value()->IsDiv() &&
These aren't the only conditions that trigger this optimization. It must
also be the case that both operands are integers, the dividend is
non-negative, and the divisor is positive. This ensures that the result
of the division can always be representable as an integer and that the
deopt will never be hit. For example, with the following HIR:
d3 = Div i1, i2
i4 = Change d to i d3
The preconditions are:
- i1 is an int32 in range [a, b] where 0 <= a <= b <= kMaxInt
- i2 is an int32 in range [c, d] where 1 <= c <= d <= kMaxInt
Thus the range of the result is [a / d, b / c] which can always be
safely truncated to int32 range since:
- 0 <= a / d <= a
- 0 <= b / c <= b
- a / d <= b / c
https://chromiumcodereview.appspot.com/10825071/diff/1/src/hydrogen-instructions.cc#newcode1159
src/hydrogen-instructions.cc:1159: if
(div->UseCountIgnoringInputsRequiringNone() == 1) {
Thanks for pointing this out! I guess I don't understand HSimulate then.
I needed it for the case in my example of updating an element in a typed
array "x[0] = 0xFF / (x[0] + 1)" but that can be done instead by using
"x[0] = 0 | 0xFF / (x[0] + 1)", which doesn't generate a HSimulate
pointing to the HDiv. I'll change this to require an absolute use count
of 1 instead.
Description:
Use integer division in a certain case.
This optimization triggers when:
- Both operands are integers
- The result will be truncated to an integer
- The dividend is non-negative
- The divisor is positive
It is done during range analysis because it needs range information for the
preconditions and because, if the optimization triggers, the range of the
output
can also be computed. This optimization also removes the deopt on non-zero
remainder since the result is always truncated.
BUG=v8:2258
TEST=test/mjsunit/fast-div-int.js
Please review this at https://chromiumcodereview.appspot.com/10825071/
SVN Base: http://v8.googlecode.com/svn/trunk/
Affected files:
M AUTHORS
M src/hydrogen-instructions.h
M src/hydrogen-instructions.cc
M src/ia32/lithium-codegen-ia32.cc
M src/x64/lithium-codegen-x64.cc
A test/mjsunit/fast-div-int.js
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev