diff options
author | 2016-11-10 18:21:30 -0800 | |
---|---|---|
committer | 2016-11-11 09:34:56 -0800 | |
commit | 08ec180de9481024c16be6841f068a45284cd8cc (patch) | |
tree | e8d450a7be42213ee14d465cd374e90f205e54df /compiler | |
parent | 5302bd999afee6db5b0cfd63e6a49b0fcbf92dd4 (diff) |
Fixed bug in LICM
Rationale:
We should stop hoisting anything that can throw
as soon as something else that can do something
visible (either throw or write something) is *not*
hoisted (used to be just throw test on second part).
Bug: 32810295
Test: test-art-host
Change-Id: Id88b712a5d9e37598d0bebbd4ecf4b1d8ee787b5
Diffstat (limited to 'compiler')
-rw-r--r-- | compiler/optimizing/licm.cc | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/compiler/optimizing/licm.cc b/compiler/optimizing/licm.cc index eb2d18dd88..f0086fb202 100644 --- a/compiler/optimizing/licm.cc +++ b/compiler/optimizing/licm.cc @@ -120,17 +120,17 @@ void LICM::Run() { } DCHECK(!loop_info->IsIrreducible()); - // We can move an instruction that can throw only if it is the first - // throwing instruction in the loop. Note that the first potentially - // throwing instruction encountered that is not hoisted stops this - // optimization. Non-throwing instruction can still be hoisted. - bool found_first_non_hoisted_throwing_instruction_in_loop = !inner->IsLoopHeader(); + // We can move an instruction that can throw only as long as it is the first visible + // instruction (throw or write) in the loop. Note that the first potentially visible + // instruction that is not hoisted stops this optimization. Non-throwing instructions, + // on the other hand, can still be hoisted. + bool found_first_non_hoisted_visible_instruction_in_loop = !inner->IsLoopHeader(); for (HInstructionIterator inst_it(inner->GetInstructions()); !inst_it.Done(); inst_it.Advance()) { HInstruction* instruction = inst_it.Current(); if (instruction->CanBeMoved() - && (!instruction->CanThrow() || !found_first_non_hoisted_throwing_instruction_in_loop) + && (!instruction->CanThrow() || !found_first_non_hoisted_visible_instruction_in_loop) && !instruction->GetSideEffects().MayDependOn(loop_effects) && InputsAreDefinedBeforeLoop(instruction)) { // We need to update the environment if the instruction has a loop header @@ -142,10 +142,10 @@ void LICM::Run() { } instruction->MoveBefore(pre_header->GetLastInstruction()); MaybeRecordStat(MethodCompilationStat::kLoopInvariantMoved); - } else if (instruction->CanThrow()) { - // If `instruction` can throw, we cannot move further instructions - // that can throw as well. - found_first_non_hoisted_throwing_instruction_in_loop = true; + } else if (instruction->CanThrow() || instruction->DoesAnyWrite()) { + // If `instruction` can do something visible (throw or write), + // we cannot move further instructions that can throw. + found_first_non_hoisted_visible_instruction_in_loop = true; } } } |