Optimize String's length/isEmpty for constant strings
If at compile time we know the length of the string, we can insert
that constant into the graph.
As part of this CL, I introduced VisitArrayLength in
ConstantFolding. This is done because:
* We are folding the instrucion into a constant so it makes
logical sense, and
* It plays better with isEmpty since that's an ArrayLength+Equal
which can be dealt with in one ConstantFolding pass.
As a note, there's VisitArrayLength in InstructionSimplifier which
would make sense to also move to ConstantFolding. However, in doing
so we get code size regressions. Added a TODO to see if we can deal
with that in the future.
Locally speed-compiling in a Pixel 5:
* SystemServer: -4.38 KB (-0.01%)
* SystemUIGoogle: -23.92KB (-0.09%)
* AGSA: -217.66KB (-0.07%)
Bug: 276416001
Test: art/test/testrunner/testrunner.py --host --64 --optimizing -b
Change-Id: Ic2081d489482157b016762e0ec103319d3b9a46e
diff --git a/compiler/optimizing/instruction_simplifier.cc b/compiler/optimizing/instruction_simplifier.cc
index 12ca30f..b772fbb 100644
--- a/compiler/optimizing/instruction_simplifier.cc
+++ b/compiler/optimizing/instruction_simplifier.cc
@@ -1117,6 +1117,10 @@
}
}
+// TODO(solanes): This optimization should be in ConstantFolding since we are folding to a constant.
+// However, we get code size regressions when we do that since we sometimes have a NullCheck between
+// HArrayLength and IsNewArray, and said NullCheck is eliminated in InstructionSimplifier. If we run
+// ConstantFolding and InstructionSimplifier in lockstep this wouldn't be an issue.
void InstructionSimplifierVisitor::VisitArrayLength(HArrayLength* instruction) {
HInstruction* input = instruction->InputAt(0);
// If the array is a NewArray with constant size, replace the array length