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