-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[SLP][REVEC] Make Instruction::Select support vector instructions. #100507
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9713,6 +9713,23 @@ BoUpSLP::getEntryCost(const TreeEntry *E, ArrayRef<Value *> VectorizedVals, | |
} | ||
VecCost = std::min(VecCost, IntrinsicCost); | ||
} | ||
if (auto *SI = dyn_cast<SelectInst>(VL0)) { | ||
auto *CondType = | ||
getWidenedType(SI->getCondition()->getType(), VL.size()); | ||
unsigned CondNumElements = CondType->getNumElements(); | ||
unsigned VecTyNumElements = getNumElements(VecTy); | ||
assert(VecTyNumElements >= CondNumElements && | ||
VecTyNumElements % CondNumElements == 0 && | ||
"Cannot vectorize Instruction::Select"); | ||
if (CondNumElements != VecTyNumElements) { | ||
// When the return type is i1 but the source is fixed vector type, we | ||
// need to duplicate the condition value. | ||
VecCost += TTI->getShuffleCost( | ||
TTI::SK_PermuteSingleSrc, CondType, | ||
createReplicatedMask(VecTyNumElements / CondNumElements, | ||
CondNumElements)); | ||
} | ||
} | ||
return VecCost + CommonCost; | ||
}; | ||
return GetCostDiff(GetScalarCost, GetVectorCost); | ||
|
@@ -13196,6 +13213,22 @@ Value *BoUpSLP::vectorizeTree(TreeEntry *E, bool PostponedPHIs) { | |
False = Builder.CreateIntCast(False, VecTy, GetOperandSignedness(2)); | ||
} | ||
|
||
unsigned CondNumElements = getNumElements(Cond->getType()); | ||
unsigned TrueNumElements = getNumElements(True->getType()); | ||
assert(TrueNumElements >= CondNumElements && | ||
TrueNumElements % CondNumElements == 0 && | ||
"Cannot vectorize Instruction::Select"); | ||
assert(TrueNumElements == getNumElements(False->getType()) && | ||
"Cannot vectorize Instruction::Select"); | ||
if (CondNumElements != TrueNumElements) { | ||
// When the return type is i1 but the source is fixed vector type, we | ||
// need to duplicate the condition value. | ||
Cond = Builder.CreateShuffleVector( | ||
Cond, createReplicatedMask(TrueNumElements / CondNumElements, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What if CondNumElements > TrueNumElements? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Cannot. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add assertion There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add in getEntryCost, including comments. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add here too There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can it be that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Cannot. They are the operands of Instruction::Select. The number of elements must be the same. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add the assertions, please, in all branches There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
CondNumElements)); | ||
} | ||
assert(getNumElements(Cond->getType()) == TrueNumElements && | ||
"Cannot vectorize Instruction::Select"); | ||
Value *V = Builder.CreateSelect(Cond, True, False); | ||
V = FinalShuffle(V, E, VecTy); | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why this is specific only for selects?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only select has a special form.
For fcmp and icmp, it is either
i1 = cmp <cond> <ty>, <ty>
or<i1 x N> = cmp <cond> <ty x N>, <ty x N>
.For select, it can be
select i1, <ty>, <ty>
,select <i1 x N>, <ty x N>, <ty x N>
orselect i1, <ty x N>, <ty x N>
.