@@ -7543,6 +7543,20 @@ static bool isFoldableUseOfShuffle(SDNode *N) {
75437543 return false;
75447544}
75457545
7546+ // If the node has a single use by a VSELECT then AVX512 targets may be able to
7547+ // fold as a predicated instruction.
7548+ static bool isMaskableNode(SDValue V, const X86Subtarget &Subtarget) {
7549+ unsigned SizeInBits = V.getValueSizeInBits();
7550+ if ((SizeInBits == 512 && Subtarget.hasAVX512()) ||
7551+ (SizeInBits >= 128 && Subtarget.hasVLX())) {
7552+ if (V.hasOneUse() && V->user_begin()->getOpcode() == ISD::VSELECT &&
7553+ V->user_begin()->getOperand(0).getScalarValueSizeInBits() == 1) {
7554+ return true;
7555+ }
7556+ }
7557+ return false;
7558+ }
7559+
75467560/// Attempt to use the vbroadcast instruction to generate a splat value
75477561/// from a splat BUILD_VECTOR which uses:
75487562/// a. A single scalar load, or a constant.
@@ -41259,13 +41273,7 @@ static SDValue combineX86ShufflesRecursively(
4125941273
4126041274 // If we are a AVX512/EVEX target the mask element size should match the root
4126141275 // element size to allow writemasks to be reused.
41262- bool IsMaskedShuffle = false;
41263- if (RootSizeInBits == 512 || (Subtarget.hasVLX() && RootSizeInBits >= 128)) {
41264- if (Root.hasOneUse() && Root->user_begin()->getOpcode() == ISD::VSELECT &&
41265- Root->user_begin()->getOperand(0).getScalarValueSizeInBits() == 1) {
41266- IsMaskedShuffle = true;
41267- }
41268- }
41276+ bool IsMaskedShuffle = isMaskableNode(Root, Subtarget);
4126941277
4127041278 // We can only combine unary and binary shuffle mask cases.
4127141279 if (Ops.size() <= 2) {
0 commit comments