From f11c420c448baffac6a70ac0884d481ab347e257 Mon Sep 17 00:00:00 2001 From: Vladimir Marko Date: Fri, 19 Jun 2015 12:58:22 +0100 Subject: Quick: Fix optimizations for empty if blocks. If a block ending with if-eqz or if-nez has the same "taken" and "fallthrough", we cannot assume that the value has been checked against zero in one of the succesors. This affects the null check elimination pass as well as GVN. Refactor all those checks to a single function in BasicBlock and check that the "taken" and "falthrough" are different when needed. Bug: 21614284 Change-Id: I8c6ac23e96cdaf5984786a555ebbd28110f095cb --- compiler/dex/mir_optimization.cc | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) (limited to 'compiler/dex/mir_optimization.cc') diff --git a/compiler/dex/mir_optimization.cc b/compiler/dex/mir_optimization.cc index 645511ed9f..727d0fd759 100644 --- a/compiler/dex/mir_optimization.cc +++ b/compiler/dex/mir_optimization.cc @@ -978,18 +978,12 @@ bool MIRGraph::EliminateNullChecks(BasicBlock* bb) { BasicBlock* pred_bb = GetBasicBlock(pred_id); DCHECK(pred_bb != nullptr); MIR* null_check_insn = nullptr; - if (pred_bb->block_type == kDalvikByteCode) { - // Check to see if predecessor had an explicit null-check. - MIR* last_insn = pred_bb->last_mir_insn; - if (last_insn != nullptr) { - Instruction::Code last_opcode = last_insn->dalvikInsn.opcode; - if ((last_opcode == Instruction::IF_EQZ && pred_bb->fall_through == bb->id) || - (last_opcode == Instruction::IF_NEZ && pred_bb->taken == bb->id)) { - // Remember the null check insn if there's no other predecessor requiring null check. - if (!copied_first || !vregs_to_check->IsBitSet(last_insn->dalvikInsn.vA)) { - null_check_insn = last_insn; - } - } + // Check to see if predecessor had an explicit null-check. + if (pred_bb->BranchesToSuccessorOnlyIfNotZero(bb->id)) { + // Remember the null check insn if there's no other predecessor requiring null check. + if (!copied_first || !vregs_to_check->IsBitSet(pred_bb->last_mir_insn->dalvikInsn.vA)) { + null_check_insn = pred_bb->last_mir_insn; + DCHECK(null_check_insn != nullptr); } } if (!copied_first) { -- cgit v1.2.3-59-g8ed1b