summaryrefslogtreecommitdiff
path: root/compiler/optimizing/instruction_simplifier.cc
diff options
context:
space:
mode:
author Santiago Aboy Solanes <solanes@google.com> 2023-03-31 16:04:22 +0100
committer Treehugger Robot <treehugger-gerrit@google.com> 2023-04-03 16:50:40 +0000
commitc63bdde13d9d2cd7f82fae590611e2ff7a77bc49 (patch)
treed905361d626944b5393ccdc6538bda6465576fa7 /compiler/optimizing/instruction_simplifier.cc
parent07798c2e898a8c3344cac123f9873a50ad2e075d (diff)
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
Diffstat (limited to 'compiler/optimizing/instruction_simplifier.cc')
-rw-r--r--compiler/optimizing/instruction_simplifier.cc4
1 files changed, 4 insertions, 0 deletions
diff --git a/compiler/optimizing/instruction_simplifier.cc b/compiler/optimizing/instruction_simplifier.cc
index 12ca30fb1b..b772fbbbb6 100644
--- a/compiler/optimizing/instruction_simplifier.cc
+++ b/compiler/optimizing/instruction_simplifier.cc
@@ -1117,6 +1117,10 @@ void InstructionSimplifierVisitor::VisitIf(HIf* instruction) {
}
}
+// 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