diff options
author | Mingyao Yang <mingyao@google.com> | 2015-01-30 16:41:29 -0800 |
---|---|---|
committer | Mingyao Yang <mingyao@google.com> | 2015-02-09 10:53:16 -0800 |
commit | 0304e182adee81be32c744fd3c0d28add29974ff (patch) | |
tree | 1fb1a8730d94222e79e8525b5f887c6816d6833d /compiler/optimizing/instruction_simplifier.cc | |
parent | 2a3611feeb12bd73ccdbb4692f9ca3705f925d56 (diff) | |
download | art-0304e182adee81be32c744fd3c0d28add29974ff.zip art-0304e182adee81be32c744fd3c0d28add29974ff.tar.gz art-0304e182adee81be32c744fd3c0d28add29974ff.tar.bz2 |
Improve bce so that more bounds checks can be eliminated.
For pattern like "int[] array = new int[size+1]", we record this range
for size:
[-1, array.length-1]
This can eliminate more bounds checks.
Also simplify overflow/underflow handling and make it more solid.
Enhance instruction simplifier such that if array is a result of
NewArray with a constant size, replace array.length with that constant.
Plan to move all bce gtests to checker in another change.
Change-Id: Ibe7cc7940b68fb6465dc3e0ff3ebdb0fd6487aa9
Diffstat (limited to 'compiler/optimizing/instruction_simplifier.cc')
-rw-r--r-- | compiler/optimizing/instruction_simplifier.cc | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/compiler/optimizing/instruction_simplifier.cc b/compiler/optimizing/instruction_simplifier.cc index 17c8f33..44dbb9d 100644 --- a/compiler/optimizing/instruction_simplifier.cc +++ b/compiler/optimizing/instruction_simplifier.cc @@ -28,6 +28,7 @@ class InstructionSimplifierVisitor : public HGraphVisitor { void VisitArraySet(HArraySet* equal) OVERRIDE; void VisitTypeConversion(HTypeConversion* instruction) OVERRIDE; void VisitNullCheck(HNullCheck* instruction) OVERRIDE; + void VisitArrayLength(HArrayLength* instruction) OVERRIDE; }; void InstructionSimplifier::Run() { @@ -75,6 +76,18 @@ void InstructionSimplifierVisitor::VisitEqual(HEqual* equal) { } } +void InstructionSimplifierVisitor::VisitArrayLength(HArrayLength* instruction) { + HInstruction* input = instruction->InputAt(0); + // If the array is a NewArray with constant size, replace the array length + // with the constant instruction. This helps the bounds check elimination phase. + if (input->IsNewArray()) { + input = input->InputAt(0); + if (input->IsIntConstant()) { + instruction->ReplaceWith(input); + } + } +} + void InstructionSimplifierVisitor::VisitArraySet(HArraySet* instruction) { HInstruction* value = instruction->GetValue(); if (value->GetType() != Primitive::kPrimNot) return; |