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