Skip to content

Commit 2d98d76

Browse files
[SLP]Fix the cost model for extracts combined with later shuffle.
If the buildvector node contains extract, which later should be combined with some other nodes by shuffling, need to estimate the cost of this shuffle before building the mask after shuffle. Reviewers: RKSimon Reviewed By: RKSimon Pull Request: llvm#83442
1 parent 0e9a102 commit 2d98d76

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7606,7 +7606,24 @@ class BoUpSLP::ShuffleCostEstimator : public BaseShuffleAnalysis {
76067606
}
76077607
SameNodesEstimated = false;
76087608
Cost += createShuffle(&E1, E2, Mask);
7609-
transformMaskAfterShuffle(CommonMask, Mask);
7609+
if (!E2 && InVectors.size() == 1) {
7610+
unsigned VF = E1.getVectorFactor();
7611+
if (Value *V1 = InVectors.front().dyn_cast<Value *>()) {
7612+
VF = std::max(VF,
7613+
cast<FixedVectorType>(V1->getType())->getNumElements());
7614+
} else {
7615+
const auto *E = InVectors.front().get<const TreeEntry *>();
7616+
VF = std::max(VF, E->getVectorFactor());
7617+
}
7618+
for (unsigned Idx = 0, Sz = CommonMask.size(); Idx < Sz; ++Idx)
7619+
if (Mask[Idx] != PoisonMaskElem && CommonMask[Idx] == PoisonMaskElem)
7620+
CommonMask[Idx] = Mask[Idx] + VF;
7621+
Cost += createShuffle(InVectors.front(), &E1, CommonMask);
7622+
transformMaskAfterShuffle(CommonMask, CommonMask);
7623+
} else {
7624+
Cost += createShuffle(&E1, E2, Mask);
7625+
transformMaskAfterShuffle(CommonMask, Mask);
7626+
}
76107627
}
76117628

76127629
class ShuffleCostBuilder {

llvm/test/Transforms/SLPVectorizer/X86/crash_clear_undefs.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16
99
; YAML-NEXT: Function: foo
1010
; YAML-NEXT: Args:
1111
; YAML-NEXT: - String: 'SLP vectorized with cost '
12-
; YAML-NEXT: - Cost: '-4'
12+
; YAML-NEXT: - Cost: '-3'
1313
; YAML-NEXT: - String: ' and with tree size '
1414
; YAML-NEXT: - TreeSize: '10'
1515
; YAML-NEXT: ...

llvm/test/Transforms/SLPVectorizer/X86/multi-nodes-to-shuffle.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2-
; RUN: opt -passes=slp-vectorizer -S < %s -mtriple=x86_64-unknown-linux -slp-threshold=-115 | FileCheck %s
2+
; RUN: opt -passes=slp-vectorizer -S < %s -mtriple=x86_64-unknown-linux -slp-threshold=-127 | FileCheck %s
33
; RUN: opt -passes=slp-vectorizer -S < %s -mtriple=x86_64-unknown-linux -slp-threshold=-115 -mattr=+avx2 | FileCheck %s --check-prefix=AVX2
44

55
define void @test(i64 %p0, i64 %p1, i64 %p2, i64 %p3) {

0 commit comments

Comments
 (0)