Skip to content

Commit b358f21

Browse files
authored
[X86] visitSelect - widen select(cond,extract_subvector(shuffle(vec0)),vec1) if it will create a mask instruction (#115223)
This patch extends the existing fold "select(mask, extract_subvector(shuffle(x)), zero) --> extract_subvector(select(insert_subvector(mask), shuffle(x), zero))", to also handle the non-zero case. I've put in a restriction for VPERMV3 3 vector operands shuffles to only work with the zero select as in most circumstances we are not selecting with either of the source vectors (the only case the mask instructions match). We should be able to generalize this in the future to work with other maskable instructions, but this is a good initial improvement. Fixes #113400
1 parent e40a31b commit b358f21

File tree

2 files changed

+194
-142
lines changed

2 files changed

+194
-142
lines changed

llvm/lib/Target/X86/X86ISelLowering.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46835,9 +46835,9 @@ static SDValue combineSelect(SDNode *N, SelectionDAG &DAG,
4683546835
return DAG.getNode(N->getOpcode(), DL, VT, Cond, LHS, RHS);
4683646836
}
4683746837

46838-
// AVX512 - Extend select with zero to merge with target shuffle.
46839-
// select(mask, extract_subvector(shuffle(x)), zero) -->
46840-
// extract_subvector(select(insert_subvector(mask), shuffle(x), zero))
46838+
// AVX512 - Extend select to merge with target shuffle.
46839+
// select(mask, extract_subvector(shuffle(x)), y) -->
46840+
// extract_subvector(select(widen(mask), shuffle(x), widen(y)))
4684146841
// TODO - support non target shuffles as well with canCombineAsMaskOperation.
4684246842
if (Subtarget.hasAVX512() && CondVT.isVector() &&
4684346843
CondVT.getVectorElementType() == MVT::i1) {
@@ -46847,7 +46847,8 @@ static SDValue combineSelect(SDNode *N, SelectionDAG &DAG,
4684746847
isNullConstant(Op.getOperand(1)) &&
4684846848
TLI.isTypeLegal(Op.getOperand(0).getValueType()) &&
4684946849
Op.hasOneUse() && Op.getOperand(0).hasOneUse() &&
46850-
ISD::isBuildVectorAllZeros(Alt.getNode());
46850+
(Op.getOperand(0).getOpcode() != X86ISD::VPERMV3 ||
46851+
ISD::isBuildVectorAllZeros(Alt.getNode()));
4685146852
};
4685246853

4685346854
bool SelectableLHS = SelectableOp(LHS, RHS);

0 commit comments

Comments
 (0)