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