@@ -47264,13 +47264,14 @@ static SDValue combineToExtendBoolVectorInReg(
47264
47264
DAG.getConstant(EltSizeInBits - 1, DL, VT));
47265
47265
}
47266
47266
47267
- /// If a vector select has an operand that is -1 or 0, try to simplify the
47267
+ /// If a vector select has an left operand that is 0, try to simplify the
47268
47268
/// select to a bitwise logic operation.
47269
- /// TODO: Move to DAGCombiner, possibly using TargetLowering::hasAndNot()?
47270
- static SDValue
47271
- combineVSelectWithAllOnesOrZeros(SDNode *N, SelectionDAG &DAG, const SDLoc &DL,
47272
- TargetLowering::DAGCombinerInfo &DCI,
47273
- const X86Subtarget &Subtarget) {
47269
+ /// TODO: Move to DAGCombiner.combineVSelectWithAllOnesOrZeros, possibly using
47270
+ /// TargetLowering::hasAndNot()?
47271
+ static SDValue combineVSelectWithLastZeros(SDNode *N, SelectionDAG &DAG,
47272
+ const SDLoc &DL,
47273
+ TargetLowering::DAGCombinerInfo &DCI,
47274
+ const X86Subtarget &Subtarget) {
47274
47275
SDValue Cond = N->getOperand(0);
47275
47276
SDValue LHS = N->getOperand(1);
47276
47277
SDValue RHS = N->getOperand(2);
@@ -47283,20 +47284,6 @@ combineVSelectWithAllOnesOrZeros(SDNode *N, SelectionDAG &DAG, const SDLoc &DL,
47283
47284
47284
47285
assert(CondVT.isVector() && "Vector select expects a vector selector!");
47285
47286
47286
- // TODO: Use isNullOrNullSplat() to distinguish constants with undefs?
47287
- // TODO: Can we assert that both operands are not zeros (because that should
47288
- // get simplified at node creation time)?
47289
- bool TValIsAllZeros = ISD::isBuildVectorAllZeros(LHS.getNode());
47290
- bool FValIsAllZeros = ISD::isBuildVectorAllZeros(RHS.getNode());
47291
-
47292
- // If both inputs are 0/undef, create a complete zero vector.
47293
- // FIXME: As noted above this should be handled by DAGCombiner/getNode.
47294
- if (TValIsAllZeros && FValIsAllZeros) {
47295
- if (VT.isFloatingPoint())
47296
- return DAG.getConstantFP(0.0, DL, VT);
47297
- return DAG.getConstant(0, DL, VT);
47298
- }
47299
-
47300
47287
// To use the condition operand as a bitwise mask, it must have elements that
47301
47288
// are the same size as the select elements. Ie, the condition operand must
47302
47289
// have already been promoted from the IR select condition type <N x i1>.
@@ -47305,56 +47292,15 @@ combineVSelectWithAllOnesOrZeros(SDNode *N, SelectionDAG &DAG, const SDLoc &DL,
47305
47292
if (CondVT.getScalarSizeInBits() != VT.getScalarSizeInBits())
47306
47293
return SDValue();
47307
47294
47308
- // Try to invert the condition if true value is not all 1s and false value is
47309
- // not all 0s. Only do this if the condition has one use.
47310
- bool TValIsAllOnes = ISD::isBuildVectorAllOnes(LHS.getNode());
47311
- if (!TValIsAllOnes && !FValIsAllZeros && Cond.hasOneUse() &&
47312
- // Check if the selector will be produced by CMPP*/PCMP*.
47313
- Cond.getOpcode() == ISD::SETCC &&
47314
- // Check if SETCC has already been promoted.
47315
- TLI.getSetCCResultType(DAG.getDataLayout(), *DAG.getContext(), VT) ==
47316
- CondVT) {
47317
- bool FValIsAllOnes = ISD::isBuildVectorAllOnes(RHS.getNode());
47318
-
47319
- if (TValIsAllZeros || FValIsAllOnes) {
47320
- SDValue CC = Cond.getOperand(2);
47321
- ISD::CondCode NewCC = ISD::getSetCCInverse(
47322
- cast<CondCodeSDNode>(CC)->get(), Cond.getOperand(0).getValueType());
47323
- Cond = DAG.getSetCC(DL, CondVT, Cond.getOperand(0), Cond.getOperand(1),
47324
- NewCC);
47325
- std::swap(LHS, RHS);
47326
- TValIsAllOnes = FValIsAllOnes;
47327
- FValIsAllZeros = TValIsAllZeros;
47328
- }
47329
- }
47330
-
47331
47295
// Cond value must be 'sign splat' to be converted to a logical op.
47332
47296
if (DAG.ComputeNumSignBits(Cond) != CondVT.getScalarSizeInBits())
47333
47297
return SDValue();
47334
47298
47335
- // vselect Cond, 111..., 000... -> Cond
47336
- if (TValIsAllOnes && FValIsAllZeros)
47337
- return DAG.getBitcast(VT, Cond);
47338
-
47339
47299
if (!TLI.isTypeLegal(CondVT))
47340
47300
return SDValue();
47341
47301
47342
- // vselect Cond, 111..., X -> or Cond, X
47343
- if (TValIsAllOnes) {
47344
- SDValue CastRHS = DAG.getBitcast(CondVT, RHS);
47345
- SDValue Or = DAG.getNode(ISD::OR, DL, CondVT, Cond, CastRHS);
47346
- return DAG.getBitcast(VT, Or);
47347
- }
47348
-
47349
- // vselect Cond, X, 000... -> and Cond, X
47350
- if (FValIsAllZeros) {
47351
- SDValue CastLHS = DAG.getBitcast(CondVT, LHS);
47352
- SDValue And = DAG.getNode(ISD::AND, DL, CondVT, Cond, CastLHS);
47353
- return DAG.getBitcast(VT, And);
47354
- }
47355
-
47356
47302
// vselect Cond, 000..., X -> andn Cond, X
47357
- if (TValIsAllZeros ) {
47303
+ if (ISD::isBuildVectorAllZeros(LHS.getNode()) ) {
47358
47304
SDValue CastRHS = DAG.getBitcast(CondVT, RHS);
47359
47305
SDValue AndN;
47360
47306
// The canonical form differs for i1 vectors - x86andnp is not used
@@ -48115,7 +48061,7 @@ static SDValue combineSelect(SDNode *N, SelectionDAG &DAG,
48115
48061
if (!TLI.isTypeLegal(VT) || isSoftF16(VT, Subtarget))
48116
48062
return SDValue();
48117
48063
48118
- if (SDValue V = combineVSelectWithAllOnesOrZeros (N, DAG, DL, DCI, Subtarget))
48064
+ if (SDValue V = combineVSelectWithLastZeros (N, DAG, DL, DCI, Subtarget))
48119
48065
return V;
48120
48066
48121
48067
if (SDValue V = combineVSelectToBLENDV(N, DAG, DL, DCI, Subtarget))
0 commit comments