Skip to content

Commit 6ccbf1d

Browse files
committed
[X86] combineSelect - use SelectableOp helper to match the zero operand as well as the target shuffle
For the "select(mask, extract_subvector(shuffle(x)), zero) --> extract_subvector(select(insert_subvector(mask), shuffle(x), zero))" fold, match the zero operand inside the SelectableOp helper. Prep work for #113400 - we will be able to relax the zero operand requirement for some target shuffles.
1 parent 712c90e commit 6ccbf1d

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

llvm/lib/Target/X86/X86ISelLowering.cpp

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46838,23 +46838,21 @@ static SDValue combineSelect(SDNode *N, SelectionDAG &DAG,
4683846838
// AVX512 - Extend select with zero to merge with target shuffle.
4683946839
// select(mask, extract_subvector(shuffle(x)), zero) -->
4684046840
// extract_subvector(select(insert_subvector(mask), shuffle(x), zero))
46841-
// TODO - support non target shuffles as well.
46841+
// TODO - support non target shuffles as well with canCombineAsMaskOperation.
4684246842
if (Subtarget.hasAVX512() && CondVT.isVector() &&
4684346843
CondVT.getVectorElementType() == MVT::i1) {
46844-
auto SelectableOp = [&TLI](SDValue Op) {
46844+
auto SelectableOp = [&TLI](SDValue Op, SDValue Alt) {
4684546845
return Op.getOpcode() == ISD::EXTRACT_SUBVECTOR &&
4684646846
isTargetShuffle(Op.getOperand(0).getOpcode()) &&
4684746847
isNullConstant(Op.getOperand(1)) &&
4684846848
TLI.isTypeLegal(Op.getOperand(0).getValueType()) &&
46849-
Op.hasOneUse() && Op.getOperand(0).hasOneUse();
46849+
Op.hasOneUse() && Op.getOperand(0).hasOneUse() &&
46850+
ISD::isBuildVectorAllZeros(Alt.getNode());
4685046851
};
4685146852

46852-
bool SelectableLHS = SelectableOp(LHS);
46853-
bool SelectableRHS = SelectableOp(RHS);
46854-
bool ZeroLHS = ISD::isBuildVectorAllZeros(LHS.getNode());
46855-
bool ZeroRHS = ISD::isBuildVectorAllZeros(RHS.getNode());
46856-
46857-
if ((SelectableLHS && ZeroRHS) || (SelectableRHS && ZeroLHS)) {
46853+
bool SelectableLHS = SelectableOp(LHS, RHS);
46854+
bool SelectableRHS = SelectableOp(RHS, LHS);
46855+
if (SelectableLHS || SelectableRHS) {
4685846856
EVT SrcVT = SelectableLHS ? LHS.getOperand(0).getValueType()
4685946857
: RHS.getOperand(0).getValueType();
4686046858
EVT SrcCondVT = SrcVT.changeVectorElementType(MVT::i1);

0 commit comments

Comments
 (0)