From 22fe45de11ed7afdf21400d2de3abd23f3a62800 Mon Sep 17 00:00:00 2001 From: Vladimir Marko Date: Wed, 18 Mar 2015 11:33:58 +0000 Subject: Quick: Eliminate check-cast guaranteed by instance-of. Eliminate check-cast if the result of an instance-of with the very same type on the same value is used to branch to the check-cast's block or a dominator of it. Note that there already exists a verifier-based elimination of check-cast but it excludes check-cast on interfaces. This new optimization works for interface types and, since it's GVN-based, it can better recognize when the same reference is used for instance-of and check-cast. Change-Id: Ib315199805099d1cb0534bb4a90dc51baa409685 --- compiler/dex/mir_optimization.cc | 3 +++ 1 file changed, 3 insertions(+) (limited to 'compiler/dex/mir_optimization.cc') diff --git a/compiler/dex/mir_optimization.cc b/compiler/dex/mir_optimization.cc index 93749e4424..266b7c3064 100644 --- a/compiler/dex/mir_optimization.cc +++ b/compiler/dex/mir_optimization.cc @@ -1751,6 +1751,9 @@ bool MIRGraph::CanThrow(MIR* mir) const { DCHECK_NE(opt_flags & MIR_IGNORE_NULL_CHECK, 0); // Non-throwing only if range check has been eliminated. return ((opt_flags & MIR_IGNORE_RANGE_CHECK) == 0); + } else if (mir->dalvikInsn.opcode == Instruction::CHECK_CAST && + (opt_flags & MIR_IGNORE_CHECK_CAST) != 0) { + return false; } else if (mir->dalvikInsn.opcode == Instruction::ARRAY_LENGTH || static_cast(mir->dalvikInsn.opcode) == kMirOpNullCheck) { // No more checks for these (null check was processed above). -- cgit v1.2.3-59-g8ed1b