summaryrefslogtreecommitdiffstats
path: root/compiler/optimizing/instruction_simplifier.cc
diff options
context:
space:
mode:
Diffstat (limited to 'compiler/optimizing/instruction_simplifier.cc')
-rw-r--r--compiler/optimizing/instruction_simplifier.cc13
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;