From: Alexey Bataev Date: Fri, 5 May 2023 14:49:15 +0000 (-0700) Subject: [SLP]Include cost of the reshuffling for same nodes with resizing. X-Git-Tag: upstream/17.0.6~1347 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=83ba148a8ae1561a32e8d6dc5209ce8d67e59a63;p=platform%2Fupstream%2Fllvm.git [SLP]Include cost of the reshuffling for same nodes with resizing. Need to account reshuffling, required for the reused elements in the buildvector nodes, which are copies (perfect match) of other nodes, but include reused elements. Differential Revision: https://reviews.llvm.org/D149966 --- diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp index b1727b3..9e179b8 100644 --- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp +++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp @@ -7006,6 +7006,17 @@ class BoUpSLP::ShuffleCostEstimator : public BaseShuffleAnalysis { const TreeEntry *E2 = P2.get(); if (E->Scalars.size() == E2->Scalars.size()) CommonVF = VF = E->Scalars.size(); + } else { + // P2 is empty, check that we have same node + reshuffle (if any). + if (E->Scalars.size() == Mask.size() && VF != Mask.size()) { + VF = E->Scalars.size(); + SmallVector CommonMask(Mask.begin(), Mask.end()); + ::addMask(CommonMask, E->getCommonMask()); + V1 = Constant::getNullValue( + FixedVectorType::get(E->Scalars.front()->getType(), VF)); + return BaseShuffleAnalysis::createShuffle( + V1, nullptr, CommonMask, Builder); + } } V1 = Constant::getNullValue( FixedVectorType::get(E->Scalars.front()->getType(), VF)); @@ -7286,7 +7297,17 @@ BoUpSLP::getEntryCost(const TreeEntry *E, ArrayRef VectorizedVals, dbgs() << "SLP: perfect diamond match for gather bundle that starts with " << *VL.front() << ".\n"); - return 0; + // Restore the mask for previous partially matched values. + for (auto [I, V] : enumerate(E->Scalars)) { + if (isa(V)) { + Mask[I] = PoisonMaskElem; + continue; + } + if (Mask[I] == PoisonMaskElem) + Mask[I] = Entries.front()->findLaneForValue(V); + } + Estimator.add(Entries.front(), Mask); + return Estimator.finalize(E->ReuseShuffleIndices); } if (!Resized) { unsigned VF1 = Entries.front()->getVectorFactor(); diff --git a/llvm/test/Transforms/SLPVectorizer/X86/crash_clear_undefs.ll b/llvm/test/Transforms/SLPVectorizer/X86/crash_clear_undefs.ll index 5701ec9..5366792 100644 --- a/llvm/test/Transforms/SLPVectorizer/X86/crash_clear_undefs.ll +++ b/llvm/test/Transforms/SLPVectorizer/X86/crash_clear_undefs.ll @@ -9,7 +9,7 @@ target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16 ; YAML-NEXT: Function: foo ; YAML-NEXT: Args: ; YAML-NEXT: - String: 'SLP vectorized with cost ' -; YAML-NEXT: - Cost: '-6' +; YAML-NEXT: - Cost: '-5' ; YAML-NEXT: - String: ' and with tree size ' ; YAML-NEXT: - TreeSize: '10' ; YAML-NEXT: ...