Skip to content

Commit e1df78c

Browse files
committed
update uses in SLPVectorizer
- pass down the previously defined TTI
1 parent 3473171 commit e1df78c

File tree

1 file changed

+22
-20
lines changed

1 file changed

+22
-20
lines changed

llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1091,7 +1091,8 @@ static bool allSameType(ArrayRef<Value *> VL) {
10911091
/// \returns True if in-tree use also needs extract. This refers to
10921092
/// possible scalar operand in vectorized instruction.
10931093
static bool doesInTreeUserNeedToExtract(Value *Scalar, Instruction *UserInst,
1094-
TargetLibraryInfo *TLI) {
1094+
TargetLibraryInfo *TLI,
1095+
const TargetTransformInfo *TTI) {
10951096
if (!UserInst)
10961097
return false;
10971098
unsigned Opcode = UserInst->getOpcode();
@@ -1108,7 +1109,7 @@ static bool doesInTreeUserNeedToExtract(Value *Scalar, Instruction *UserInst,
11081109
CallInst *CI = cast<CallInst>(UserInst);
11091110
Intrinsic::ID ID = getVectorIntrinsicIDForCall(CI, TLI);
11101111
return any_of(enumerate(CI->args()), [&](auto &&Arg) {
1111-
return isVectorIntrinsicWithScalarOpAtArg(ID, Arg.index()) &&
1112+
return isVectorIntrinsicWithScalarOpAtArg(ID, Arg.index(), TTI) &&
11121113
Arg.value().get() == Scalar;
11131114
});
11141115
}
@@ -6505,7 +6506,7 @@ void BoUpSLP::buildExternalUses(
65056506
// be used.
65066507
if (UseEntry->State == TreeEntry::ScatterVectorize ||
65076508
!doesInTreeUserNeedToExtract(
6508-
Scalar, getRootEntryInstruction(*UseEntry), TLI)) {
6509+
Scalar, getRootEntryInstruction(*UseEntry), TLI, TTI)) {
65096510
LLVM_DEBUG(dbgs() << "SLP: \tInternal user will be removed:" << *U
65106511
<< ".\n");
65116512
assert(!UseEntry->isGather() && "Bad state");
@@ -7830,7 +7831,7 @@ BoUpSLP::TreeEntry::EntryState BoUpSLP::getScalarsVectorizationState(
78307831
unsigned NumArgs = CI->arg_size();
78317832
SmallVector<Value *, 4> ScalarArgs(NumArgs, nullptr);
78327833
for (unsigned J = 0; J != NumArgs; ++J)
7833-
if (isVectorIntrinsicWithScalarOpAtArg(ID, J))
7834+
if (isVectorIntrinsicWithScalarOpAtArg(ID, J, TTI))
78347835
ScalarArgs[J] = CI->getArgOperand(J);
78357836
for (Value *V : VL) {
78367837
CallInst *CI2 = dyn_cast<CallInst>(V);
@@ -7846,7 +7847,7 @@ BoUpSLP::TreeEntry::EntryState BoUpSLP::getScalarsVectorizationState(
78467847
// Some intrinsics have scalar arguments and should be same in order for
78477848
// them to be vectorized.
78487849
for (unsigned J = 0; J != NumArgs; ++J) {
7849-
if (isVectorIntrinsicWithScalarOpAtArg(ID, J)) {
7850+
if (isVectorIntrinsicWithScalarOpAtArg(ID, J, TTI)) {
78507851
Value *A1J = CI2->getArgOperand(J);
78517852
if (ScalarArgs[J] != A1J) {
78527853
LLVM_DEBUG(dbgs()
@@ -8718,7 +8719,7 @@ void BoUpSLP::buildTree_rec(ArrayRef<Value *> VL, unsigned Depth,
87188719
for (unsigned I : seq<unsigned>(CI->arg_size())) {
87198720
// For scalar operands no need to create an entry since no need to
87208721
// vectorize it.
8721-
if (isVectorIntrinsicWithScalarOpAtArg(ID, I))
8722+
if (isVectorIntrinsicWithScalarOpAtArg(ID, I, TTI))
87228723
continue;
87238724
buildTree_rec(TE->getOperand(I), Depth + 1, {TE, I});
87248725
}
@@ -10948,14 +10949,14 @@ TTI::CastContextHint BoUpSLP::getCastContextHint(const TreeEntry &TE) const {
1094810949

1094910950
/// Builds the arguments types vector for the given call instruction with the
1095010951
/// given \p ID for the specified vector factor.
10951-
static SmallVector<Type *> buildIntrinsicArgTypes(const CallInst *CI,
10952-
const Intrinsic::ID ID,
10953-
const unsigned VF,
10954-
unsigned MinBW) {
10952+
static SmallVector<Type *>
10953+
buildIntrinsicArgTypes(const CallInst *CI, const Intrinsic::ID ID,
10954+
const unsigned VF, unsigned MinBW,
10955+
const TargetTransformInfo *TTI) {
1095510956
SmallVector<Type *> ArgTys;
1095610957
for (auto [Idx, Arg] : enumerate(CI->args())) {
1095710958
if (ID != Intrinsic::not_intrinsic) {
10958-
if (isVectorIntrinsicWithScalarOpAtArg(ID, Idx)) {
10959+
if (isVectorIntrinsicWithScalarOpAtArg(ID, Idx, TTI)) {
1095910960
ArgTys.push_back(Arg->getType());
1096010961
continue;
1096110962
}
@@ -11657,9 +11658,9 @@ BoUpSLP::getEntryCost(const TreeEntry *E, ArrayRef<Value *> VectorizedVals,
1165711658
auto GetVectorCost = [=](InstructionCost CommonCost) {
1165811659
auto *CI = cast<CallInst>(VL0);
1165911660
Intrinsic::ID ID = getVectorIntrinsicIDForCall(CI, TLI);
11660-
SmallVector<Type *> ArgTys =
11661-
buildIntrinsicArgTypes(CI, ID, VecTy->getNumElements(),
11662-
It != MinBWs.end() ? It->second.first : 0);
11661+
SmallVector<Type *> ArgTys = buildIntrinsicArgTypes(
11662+
CI, ID, VecTy->getNumElements(),
11663+
It != MinBWs.end() ? It->second.first : 0, TTI);
1166311664
auto VecCallCosts = getVectorCallCosts(CI, VecTy, TTI, TLI, ArgTys);
1166411665
return std::min(VecCallCosts.first, VecCallCosts.second) + CommonCost;
1166511666
};
@@ -15817,9 +15818,9 @@ Value *BoUpSLP::vectorizeTree(TreeEntry *E, bool PostponedPHIs) {
1581715818

1581815819
Intrinsic::ID ID = getVectorIntrinsicIDForCall(CI, TLI);
1581915820

15820-
SmallVector<Type *> ArgTys =
15821-
buildIntrinsicArgTypes(CI, ID, VecTy->getNumElements(),
15822-
It != MinBWs.end() ? It->second.first : 0);
15821+
SmallVector<Type *> ArgTys = buildIntrinsicArgTypes(
15822+
CI, ID, VecTy->getNumElements(),
15823+
It != MinBWs.end() ? It->second.first : 0, TTI);
1582315824
auto VecCallCosts = getVectorCallCosts(CI, VecTy, TTI, TLI, ArgTys);
1582415825
bool UseIntrinsic = ID != Intrinsic::not_intrinsic &&
1582515826
VecCallCosts.first <= VecCallCosts.second;
@@ -15835,7 +15836,7 @@ Value *BoUpSLP::vectorizeTree(TreeEntry *E, bool PostponedPHIs) {
1583515836
ValueList OpVL;
1583615837
// Some intrinsics have scalar arguments. This argument should not be
1583715838
// vectorized.
15838-
if (UseIntrinsic && isVectorIntrinsicWithScalarOpAtArg(ID, I)) {
15839+
if (UseIntrinsic && isVectorIntrinsicWithScalarOpAtArg(ID, I, TTI)) {
1583915840
ScalarArg = CEI->getArgOperand(I);
1584015841
// if decided to reduce bitwidth of abs intrinsic, it second argument
1584115842
// must be set false (do not return poison, if value issigned min).
@@ -16374,7 +16375,7 @@ BoUpSLP::vectorizeTree(const ExtraValueToDebugLocsMap &ExternallyUsedValues,
1637416375
E->State == TreeEntry::StridedVectorize) &&
1637516376
doesInTreeUserNeedToExtract(
1637616377
Scalar, getRootEntryInstruction(*UseEntry),
16377-
TLI);
16378+
TLI, TTI);
1637816379
})) &&
1637916380
"Scalar with nullptr User must be registered in "
1638016381
"ExternallyUsedValues map or remain as scalar in vectorized "
@@ -17870,7 +17871,8 @@ bool BoUpSLP::collectValuesToDemote(
1787017871
// Choose the best bitwidth based on cost estimations.
1787117872
auto Checker = [&](unsigned BitWidth, unsigned) {
1787217873
unsigned MinBW = PowerOf2Ceil(BitWidth);
17873-
SmallVector<Type *> ArgTys = buildIntrinsicArgTypes(IC, ID, VF, MinBW);
17874+
SmallVector<Type *> ArgTys =
17875+
buildIntrinsicArgTypes(IC, ID, VF, MinBW, TTI);
1787417876
auto VecCallCosts = getVectorCallCosts(
1787517877
IC, getWidenedType(IntegerType::get(IC->getContext(), MinBW), VF),
1787617878
TTI, TLI, ArgTys);

0 commit comments

Comments
 (0)