From 1d116a904a41f969b549cac33a4baaf5a123c3ec Mon Sep 17 00:00:00 2001 From: Artem Serov Date: Tue, 21 May 2024 14:28:56 +0100 Subject: [SVE] Fix a bug with vectorization external set. This patch fixes a bug when LoopOptimization::vector_external_set_ (contains vector instructions to be inserted outside of newly generated loops) was reset more than once during vectorization. Instead, it should only be reset when vectorization of the loop has finished. It also adds a regression test for the situation: a loop is vectorized in predicated mode and a disambiguation test and a back-up scalar loop are needed and inserted. Note: This bug only affected predicated vectorization (e.g. using Arm SVE) and didn't impact any production devices. Test: run with ART_FORCE_TRY_PREDICATED_SIMD=true and without Test: 623-checker-loop-regressions Test: ./art/test.py --host --optimizing --jit Test: ./art/test.py --target --optimizing --jit Change-Id: I19fabd4d7034e5aa6421df79b2519d8f7e6ef43a --- compiler/optimizing/loop_optimization.cc | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) (limited to 'compiler/optimizing/loop_optimization.cc') diff --git a/compiler/optimizing/loop_optimization.cc b/compiler/optimizing/loop_optimization.cc index 14e6683cf8..9372e116bb 100644 --- a/compiler/optimizing/loop_optimization.cc +++ b/compiler/optimizing/loop_optimization.cc @@ -1283,6 +1283,8 @@ void HLoopOptimization::VectorizePredicated(LoopNode* node, HBasicBlock* exit) { DCHECK(IsInPredicatedVectorizationMode()); + vector_external_set_->clear(); + HBasicBlock* header = node->loop_info->GetHeader(); HBasicBlock* preheader = node->loop_info->GetPreHeader(); @@ -1369,6 +1371,8 @@ void HLoopOptimization::VectorizeTraditional(LoopNode* node, int64_t trip_count) { DCHECK(!IsInPredicatedVectorizationMode()); + vector_external_set_->clear(); + HBasicBlock* header = node->loop_info->GetHeader(); HBasicBlock* preheader = node->loop_info->GetPreHeader(); @@ -1566,7 +1570,6 @@ HPhi* HLoopOptimization::InitializeForNewLoop(HBasicBlock* new_preheader, HInstr vector_header_->AddPhi(phi); vector_index_ = phi; vector_permanent_map_->clear(); - vector_external_set_->clear(); predicate_info_map_->clear(); return phi; @@ -2208,7 +2211,7 @@ void HLoopOptimization::GenerateVecInv(HInstruction* org, DataType::Type type) { vector = new (global_allocator_) HVecReplicateScalar(global_allocator_, input, type, vector_length_, kNoDexPc); vector_permanent_map_->Put(org, Insert(vector_preheader_, vector)); - vector_external_set_->insert(vector); + MaybeInsertInVectorExternalSet(vector); } vector_map_->Put(org, vector); } @@ -2337,7 +2340,7 @@ void HLoopOptimization::GenerateVecReductionPhiInputs(HPhi* phi, HInstruction* r vector_length, kNoDexPc)); } - vector_external_set_->insert(new_init); + MaybeInsertInVectorExternalSet(new_init); } else { new_init = ReduceAndExtractIfNeeded(new_init); } @@ -2366,12 +2369,12 @@ HInstruction* HLoopOptimization::ReduceAndExtractIfNeeded(HInstruction* instruct HVecReduce* reduce = new (global_allocator_) HVecReduce( global_allocator_, instruction, type, vector_length, kind, kNoDexPc); exit->InsertInstructionBefore(reduce, exit->GetFirstInstruction()); - vector_external_set_->insert(reduce); + MaybeInsertInVectorExternalSet(reduce); instruction = new (global_allocator_) HVecExtractScalar( global_allocator_, reduce, type, vector_length, 0, kNoDexPc); exit->InsertInstructionAfter(instruction, reduce); - vector_external_set_->insert(instruction); + MaybeInsertInVectorExternalSet(instruction); } } return instruction; @@ -3167,6 +3170,12 @@ void HLoopOptimization::InitPredicateInfoMap(LoopNode* node, back_edge_info->SetControlPredicate(header_info->GetTruePredicate()); } +void HLoopOptimization::MaybeInsertInVectorExternalSet(HInstruction* instruction) { + if (IsInPredicatedVectorizationMode()) { + vector_external_set_->insert(instruction); + } +} + std::ostream& operator<<(std::ostream& os, const HLoopOptimization::VectorMode& mode) { switch (mode) { case HLoopOptimization::VectorMode::kSequential: -- cgit v1.2.3-59-g8ed1b