@@ -5207,18 +5207,19 @@ static bool isConstantPowerOf2(SDValue V, unsigned EltSizeInBIts,
5207
5207
return IsPow2OrUndef;
5208
5208
}
5209
5209
5210
- // Match not(xor X, -1) -> X.
5211
- // Match not(pcmpgt(C, X)) -> pcmpgt(X, C - 1).
5212
- // Match not(extract_subvector(xor X, -1)) -> extract_subvector(X).
5213
- // Match not(concat_vectors(xor X, -1, xor Y, -1)) -> concat_vectors(X, Y).
5214
- // Match or(not(X),not(Y)) -> and(X, Y).
5210
+ // Helper to attempt to return a cheaper, bit-inverted version of \p V.
5215
5211
static SDValue IsNOT(SDValue V, SelectionDAG &DAG) {
5212
+ // TODO: don't always ignore oneuse constraints.
5216
5213
V = peekThroughBitcasts(V);
5217
5214
EVT VT = V.getValueType();
5215
+
5216
+ // Match not(xor X, -1) -> X.
5218
5217
if (V.getOpcode() == ISD::XOR &&
5219
5218
(ISD::isBuildVectorAllOnes(V.getOperand(1).getNode()) ||
5220
5219
isAllOnesConstant(V.getOperand(1))))
5221
5220
return V.getOperand(0);
5221
+
5222
+ // Match not(extract_subvector(not(X)) -> extract_subvector(X).
5222
5223
if (V.getOpcode() == ISD::EXTRACT_SUBVECTOR &&
5223
5224
(isNullConstant(V.getOperand(1)) || V.getOperand(0).hasOneUse())) {
5224
5225
if (SDValue Not = IsNOT(V.getOperand(0), DAG)) {
@@ -5227,6 +5228,8 @@ static SDValue IsNOT(SDValue V, SelectionDAG &DAG) {
5227
5228
V.getOperand(1));
5228
5229
}
5229
5230
}
5231
+
5232
+ // Match not(pcmpgt(C, X)) -> pcmpgt(X, C - 1).
5230
5233
if (V.getOpcode() == X86ISD::PCMPGT &&
5231
5234
!ISD::isBuildVectorAllZeros(V.getOperand(0).getNode()) &&
5232
5235
!ISD::isBuildVectorAllOnes(V.getOperand(0).getNode()) &&
@@ -5250,15 +5253,20 @@ static SDValue IsNOT(SDValue V, SelectionDAG &DAG) {
5250
5253
}
5251
5254
}
5252
5255
}
5256
+
5257
+ // Match not(concat_vectors(not(X), not(Y))) -> concat_vectors(X, Y).
5253
5258
SmallVector<SDValue, 2> CatOps;
5254
5259
if (collectConcatOps(V.getNode(), CatOps, DAG)) {
5255
5260
for (SDValue &CatOp : CatOps) {
5256
5261
SDValue NotCat = IsNOT(CatOp, DAG);
5257
- if (!NotCat) return SDValue();
5262
+ if (!NotCat)
5263
+ return SDValue();
5258
5264
CatOp = DAG.getBitcast(CatOp.getValueType(), NotCat);
5259
5265
}
5260
5266
return DAG.getNode(ISD::CONCAT_VECTORS, SDLoc(V), VT, CatOps);
5261
5267
}
5268
+
5269
+ // Match not(or(not(X),not(Y))) -> and(X, Y).
5262
5270
if (V.getOpcode() == ISD::OR && DAG.getTargetLoweringInfo().isTypeLegal(VT) &&
5263
5271
V.getOperand(0).hasOneUse() && V.getOperand(1).hasOneUse()) {
5264
5272
// TODO: Handle cases with single NOT operand -> ANDNP
@@ -5267,6 +5275,7 @@ static SDValue IsNOT(SDValue V, SelectionDAG &DAG) {
5267
5275
return DAG.getNode(ISD::AND, SDLoc(V), VT, DAG.getBitcast(VT, Op0),
5268
5276
DAG.getBitcast(VT, Op1));
5269
5277
}
5278
+
5270
5279
return SDValue();
5271
5280
}
5272
5281
0 commit comments