diff options
| author | 2015-04-23 21:35:11 +0100 | |
|---|---|---|
| committer | 2015-05-18 17:58:21 +0100 | |
| commit | 8909bafa5d64e12eb53f3d37b984f53e7a632224 (patch) | |
| tree | 6bac613ed796914ec4937a64d40d44b1888d4878 /compiler/optimizing/instruction_simplifier.cc | |
| parent | 06675720cc274eb9d91a4ecd3fb1eef94a2d88f0 (diff) | |
Mark CheckCast's and InstanceOf's input as !CanBeNull if used before in a NullCheck
Change-Id: Ied0412a01922b40a3f5d89bed49707498582abc1
Diffstat (limited to 'compiler/optimizing/instruction_simplifier.cc')
| -rw-r--r-- | compiler/optimizing/instruction_simplifier.cc | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/compiler/optimizing/instruction_simplifier.cc b/compiler/optimizing/instruction_simplifier.cc index 46fad17b8f..86c4a98deb 100644 --- a/compiler/optimizing/instruction_simplifier.cc +++ b/compiler/optimizing/instruction_simplifier.cc @@ -63,6 +63,7 @@ class InstructionSimplifierVisitor : public HGraphVisitor { void VisitUShr(HUShr* instruction) OVERRIDE; void VisitXor(HXor* instruction) OVERRIDE; void VisitInstanceOf(HInstanceOf* instruction) OVERRIDE; + bool IsDominatedByInputNullCheck(HInstruction* instr); OptimizingCompilerStats* stats_; bool simplification_occurred_ = false; @@ -170,9 +171,20 @@ void InstructionSimplifierVisitor::VisitNullCheck(HNullCheck* null_check) { } } +bool InstructionSimplifierVisitor::IsDominatedByInputNullCheck(HInstruction* instr) { + HInstruction* input = instr->InputAt(0); + for (HUseIterator<HInstruction*> it(input->GetUses()); !it.Done(); it.Advance()) { + HInstruction* use = it.Current()->GetUser(); + if (use->IsNullCheck() && use->StrictlyDominates(instr)) { + return true; + } + } + return false; +} + void InstructionSimplifierVisitor::VisitCheckCast(HCheckCast* check_cast) { HLoadClass* load_class = check_cast->InputAt(1)->AsLoadClass(); - if (!check_cast->InputAt(0)->CanBeNull()) { + if (!check_cast->InputAt(0)->CanBeNull() || IsDominatedByInputNullCheck(check_cast)) { check_cast->ClearMustDoNullCheck(); } @@ -194,7 +206,7 @@ void InstructionSimplifierVisitor::VisitCheckCast(HCheckCast* check_cast) { } void InstructionSimplifierVisitor::VisitInstanceOf(HInstanceOf* instruction) { - if (!instruction->InputAt(0)->CanBeNull()) { + if (!instruction->InputAt(0)->CanBeNull() || IsDominatedByInputNullCheck(instruction)) { instruction->ClearMustDoNullCheck(); } } |