Extend ArrayLengthVisitor in Instruction Simplifier
Currently, if a NewArray is created with an IntConstant size, the
Instruction Simplifier pass substitutes corresponding ArrayLength
instructions with the IntConstant instruction. This patch extends this
such that ArrayLength instructions can be substituted with the input to
NewArray even if the input is not an IntConstant instruction.
Currently, d8 can make this substitution at the bytecode level if the
NewArray and ArrayLength instructions are in the same function. This
patch allows the optimization to be applied even if the NewArray
instruction is in a separate function which is inlined.
This new optimization is applied only when the compiler is not in
`be_loop_friendly` mode. This is to avoid conflicts with the Bounds
Check Elimination (BCE) pass, which currently assumes that the array
length input to a BoundsCheck instruction is an ArrayLength or
IntConstant. However, this restriction could be relaxed in the future if
BCE is updated.
In addition, tests in `530-checker-lse-simd` are updated to reflect the
new optimization and new tests are added in
`458-checker-instruct-simplification`. The new tests check for the
following:
- Check that, when the NewArray instruction is in a different
function which is inlined, the ArrayLength instruction is
substituted with the input to NewArray and subsequently optimised
out
- Check that the optimization is applied only after loop optimizations
have taken place.
Test: art/test.py --run-test --target --64 --optimizing
Test: art/test.py --run-test --host --optimizing
Cherrypick-From: https://partner-android-review.googlesource.com/q/commit:a0bc6a8c878907b4498ccff3f7903495a22c5a26
Flag: NONE Partner contribution.
Change-Id: Ibeaa17969ca3609fb4112083737e37accfe05493
3 files changed