diff options
| author | 2017-08-07 17:23:38 +0000 | |
|---|---|---|
| committer | 2017-08-07 17:23:38 +0000 | |
| commit | 5aedbcd3d0a1a60643db3e904254e0a3060599bf (patch) | |
| tree | 3d136637c0ef0cb12093d6f412fe1ec7e7a26e7e /compiler/optimizing/loop_optimization_test.cc | |
| parent | c7c25d5b4cf243cbbf06f2e4302a0faa5eccb42a (diff) | |
| parent | c73ee37b76494253862ee17933acfe2b88de1a01 (diff) | |
Merge "ART: Fix loop header's predecessors reordering in SimplifyLoops."
Diffstat (limited to 'compiler/optimizing/loop_optimization_test.cc')
| -rw-r--r-- | compiler/optimizing/loop_optimization_test.cc | 40 | 
1 files changed, 40 insertions, 0 deletions
| diff --git a/compiler/optimizing/loop_optimization_test.cc b/compiler/optimizing/loop_optimization_test.cc index 5b9350689e..b5b03d8f26 100644 --- a/compiler/optimizing/loop_optimization_test.cc +++ b/compiler/optimizing/loop_optimization_test.cc @@ -195,4 +195,44 @@ TEST_F(LoopOptimizationTest, LoopNestWithSequence) {    EXPECT_EQ("[[[[[[[[[[][][][][][][][][][]]]]]]]]]]", LoopStructure());  } +// Check that SimplifyLoop() doesn't invalidate data flow when ordering loop headers' +// predecessors. +TEST_F(LoopOptimizationTest, SimplifyLoop) { +  // Can't use AddLoop as we want special order for blocks predecessors. +  HBasicBlock* header = new (&allocator_) HBasicBlock(graph_); +  HBasicBlock* body = new (&allocator_) HBasicBlock(graph_); +  graph_->AddBlock(header); +  graph_->AddBlock(body); + +  // Control flow: make a loop back edge first in the list of predecessors. +  entry_block_->RemoveSuccessor(return_block_); +  body->AddSuccessor(header); +  entry_block_->AddSuccessor(header); +  header->AddSuccessor(body); +  header->AddSuccessor(return_block_); +  DCHECK(header->GetSuccessors()[1] == return_block_); + +  // Data flow. +  header->AddInstruction(new (&allocator_) HIf(parameter_)); +  body->AddInstruction(new (&allocator_) HGoto()); + +  HPhi* phi = new (&allocator_) HPhi(&allocator_, 0, 0, Primitive::kPrimInt); +  HInstruction* add = new (&allocator_) HAdd(Primitive::kPrimInt, phi, parameter_); +  header->AddPhi(phi); +  body->AddInstruction(add); + +  phi->AddInput(add); +  phi->AddInput(parameter_); + +  graph_->ClearLoopInformation(); +  graph_->ClearDominanceInformation(); +  graph_->BuildDominatorTree(); + +  // Check that after optimizations in BuildDominatorTree()/SimplifyCFG() phi inputs +  // are still mapped correctly to the block predecessors. +  for (size_t i = 0, e = phi->InputCount(); i < e; i++) { +    HInstruction* input = phi->InputAt(i); +    ASSERT_TRUE(input->GetBlock()->Dominates(header->GetPredecessors()[i])); +  } +}  }  // namespace art |