// Base class for loop optimization tests. class LoopOptimizationTestBase : public OptimizingUnitTest { protected: void SetUp() override {
OptimizingUnitTest::SetUp();
#ifdef ART_ENABLE_CODEGEN_arm64 // Unit tests for predicated vectorization. class PredicatedSimdLoopOptimizationTest : public LoopOptimizationTestBase { protected: void SetUp() override { // Predicated SIMD is only supported by SVE on Arm64.
compiler_options_ = CommonCompilerTest::CreateCompilerOptions(InstructionSet::kArm64, "default", "sve");
LoopOptimizationTestBase::SetUp();
}
virtual ~PredicatedSimdLoopOptimizationTest() {}
// Constructs a graph with a diamond loop which should be vectorizable with predicated // vectorization. This graph includes a basic loop induction (consisting of Phi, Add, If and // SuspendCheck instructions) to control the loop as well as an if comparison (consisting of // Parameter, GreaterThanOrEqual and If instructions) to control the diamond loop. // // entry // | // preheader // | // return <------------ header <----------------+ // | | | // exit diamond_top | // / \ | // diamond_true diamond_false | // \ / | // back_edge | // | | // +---------------------+ void BuildGraph() override {
return_block_ = InitEntryMainExitGraphWithReturnVoid();
HBasicBlock* back_edge;
std::tie(std::ignore, header_, back_edge) = CreateWhileLoop(return_block_);
std::tie(diamond_top_, diamond_true_, std::ignore) = CreateDiamondPattern(back_edge);
// Add an ArraySet to the loop which will be vectorized, thus setting the type of vector // instructions in the graph to the given vector_type. This needs to be called to ensure the loop // is not simplified by SimplifyInduction or SimplifyBlocks before vectorization. void AddArraySetToLoop(DataType::Type vector_type) { // Ensure the data type is a java type so it can be stored in a TypeField. The actual type does // not matter as long as the size is the same so it can still be vectorized.
DataType::Type new_type = DataType::SignedIntegralTypeFromSize(DataType::Size(vector_type));
// Add an array set to prevent the loop from being optimized away before vectorization. // Note: This uses an integer parameter and not an array reference to avoid the difficulties in // allocating an array. The instruction is still treated as a valid ArraySet by loop // optimization.
diamond_true_->AddInstruction(new (GetAllocator()) HArraySet(parameter_,
phi_,
graph_->GetIntConstant(1),
new_type, /* dex_pc= */ 0));
}
// Replace the input of diamond_hif_ with a new condition of the given types. void ReplaceIfCondition(DataType::Type l_type,
DataType::Type r_type,
HBasicBlock* condition_block,
IfCondition cond) {
AddArraySetToLoop(l_type);
HInstruction* l_param = MakeParam(l_type);
HInstruction* r_param = MakeParam(r_type);
HCondition* condition = MakeCondition(condition_block, cond, l_param, r_param);
diamond_hif_->ReplaceInput(condition, 0);
}
// Is loop optimization able to vectorize predicated code? bool IsPredicatedVectorizationSupported() { // Mirror the check guarding TryVectorizePredicated in TryOptimizeInnerLoopFinite. return kForceTryPredicatedSIMD && loop_opt_->IsInPredicatedVectorizationMode();
}
TEST_F(LoopOptimizationTest, LoopNest10) {
HBasicBlock* b = entry_block_;
HBasicBlock* s = return_block_; for (int i = 0; i < 10; i++) {
s = AddLoop(b, s);
b = s->GetSuccessors()[0];
}
PerformAnalysis(/*run_checker=*/ false);
EXPECT_EQ("[[[[[[[[[[]]]]]]]]]]", LoopStructure());
}
TEST_F(LoopOptimizationTest, LoopSequence10) {
HBasicBlock* b = entry_block_;
HBasicBlock* s = return_block_; for (int i = 0; i < 10; i++) {
b = AddLoop(b, s);
s = b->GetSuccessors()[1];
}
PerformAnalysis(/*run_checker=*/ false);
EXPECT_EQ("[][][][][][][][][][]", LoopStructure());
}
TEST_F(LoopOptimizationTest, LoopSequenceOfNests) {
HBasicBlock* b = entry_block_;
HBasicBlock* s = return_block_; for (int i = 0; i < 10; i++) {
b = AddLoop(b, s);
s = b->GetSuccessors()[1];
HBasicBlock* bi = b->GetSuccessors()[0];
HBasicBlock* si = b; for (int j = 0; j < i; j++) {
si = AddLoop(bi, si);
bi = si->GetSuccessors()[0];
}
}
PerformAnalysis(/*run_checker=*/ false);
EXPECT_EQ("[]" "[[]]" "[[[]]]" "[[[[]]]]" "[[[[[]]]]]" "[[[[[[]]]]]]" "[[[[[[[]]]]]]]" "[[[[[[[[]]]]]]]]" "[[[[[[[[[]]]]]]]]]" "[[[[[[[[[[]]]]]]]]]]",
LoopStructure());
}
TEST_F(LoopOptimizationTest, LoopNestWithSequence) {
HBasicBlock* b = entry_block_;
HBasicBlock* s = return_block_; for (int i = 0; i < 10; i++) {
s = AddLoop(b, s);
b = s->GetSuccessors()[0];
}
b = s;
s = b->GetSuccessors()[1]; for (int i = 0; i < 9; i++) {
b = AddLoop(b, s);
s = b->GetSuccessors()[1];
}
PerformAnalysis(/*run_checker=*/ false);
EXPECT_EQ("[[[[[[[[[[][][][][][][][][][]]]]]]]]]]", LoopStructure());
}
// Check that SimplifyLoop() doesn't invalidate data flow when ordering loop headers' // predecessors. // // This is a test for nodes.cc functionality - HGraph::SimplifyLoop.
TEST_F(LoopOptimizationTest, SimplifyLoopReoderPredecessors) { // Can't use AddLoop as we want special order for blocks predecessors.
HBasicBlock* header = AddNewBlock();
HBasicBlock* body = AddNewBlock();
// 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.
MakeIf(header, parameter_);
MakeGoto(body);
// BuildDominatorTree inserts a block beetween loop header and entry block.
EXPECT_EQ(header->GetPredecessors()[0]->GetSinglePredecessor(), entry_block_);
// 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);
EXPECT_TRUE(input->GetBlock()->Dominates(header->GetPredecessors()[i]));
}
}
// Test that SimplifyLoop() processes the multiple-preheaders loops correctly. // // This is a test for nodes.cc functionality - HGraph::SimplifyLoop.
TEST_F(LoopOptimizationTest, SimplifyLoopSinglePreheader) {
HBasicBlock* header = AddLoop(entry_block_, return_block_);
header->InsertInstructionBefore( new (GetAllocator()) HSuspendCheck(), header->GetLastInstruction());
// Insert an if construct before the loop so it will have two preheaders.
HBasicBlock* if_block = AddNewBlock();
HBasicBlock* preheader0 = AddNewBlock();
HBasicBlock* preheader1 = AddNewBlock();
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.