diff options
| author | 2013-06-13 15:06:54 -0700 | |
|---|---|---|
| committer | 2013-06-13 15:06:54 -0700 | |
| commit | 22fd6a095bcb98dfce1afc70ad447d7fd0d23d74 (patch) | |
| tree | e510fbb3c013cf9c1ee181e886a2476e2e36d138 | |
| parent | 8afe6e0d8c4151ac74afc4ebe0dab85550821243 (diff) | |
Avoid null-checks in blocks following an explicit check.
Change-Id: Ie23f8f23808be3cc335d0a8775c35ddf0c131a6c
| -rw-r--r-- | src/compiler/dex/mir_optimization.cc | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/src/compiler/dex/mir_optimization.cc b/src/compiler/dex/mir_optimization.cc index d9c443e536..6b8f3f0915 100644 --- a/src/compiler/dex/mir_optimization.cc +++ b/src/compiler/dex/mir_optimization.cc @@ -641,8 +641,29 @@ bool MIRGraph::EliminateNullChecks(struct BasicBlock* bb) int this_reg = cu_->num_dalvik_registers - cu_->num_ins; temp_ssa_register_v_->SetBit(this_reg); } + } else if (bb->predecessors->Size() == 1) { + BasicBlock* pred_bb = bb->predecessors->Get(0); + temp_ssa_register_v_->Copy(pred_bb->data_flow_info->ending_null_check_v); + if (pred_bb->block_type == kDalvikByteCode) { + // Check to see if predecessor had an explicit null-check. + MIR* last_insn = pred_bb->last_mir_insn; + Instruction::Code last_opcode = last_insn->dalvikInsn.opcode; + if (last_opcode == Instruction::IF_EQZ) { + if (pred_bb->fall_through == bb) { + // The fall-through of a block following a IF_EQZ, set the vA of the IF_EQZ to show that + // it can't be null. + temp_ssa_register_v_->SetBit(last_insn->ssa_rep->uses[0]); + } + } else if (last_opcode == Instruction::IF_NEZ) { + if (pred_bb->taken == bb) { + // The taken block following a IF_NEZ, set the vA of the IF_NEZ to show that it can't be + // null. + temp_ssa_register_v_->SetBit(last_insn->ssa_rep->uses[0]); + } + } + } } else { - // Starting state is intesection of all incoming arcs + // Starting state is intersection of all incoming arcs GrowableArray<BasicBlock*>::Iterator iter(bb->predecessors); BasicBlock* pred_bb = iter.Next(); DCHECK(pred_bb != NULL); |