@@ -11307,28 +11307,34 @@ static SDValue foldBoolSelectToLogic(SDNode *N, SelectionDAG &DAG) {
11307
11307
if (VT != Cond.getValueType() || VT.getScalarSizeInBits() != 1)
11308
11308
return SDValue();
11309
11309
11310
- // select Cond, Cond, F --> or Cond, F
11311
- // select Cond, 1, F --> or Cond, F
11310
+ auto FreezeIfNeeded = [&](SDValue V) {
11311
+ if (!DAG.isGuaranteedNotToBePoison(V))
11312
+ return DAG.getFreeze(V);
11313
+ return V;
11314
+ };
11315
+
11316
+ // select Cond, Cond, F --> or Cond, freeze(F)
11317
+ // select Cond, 1, F --> or Cond, freeze(F)
11312
11318
if (Cond == T || isOneOrOneSplat(T, /* AllowUndefs */ true))
11313
- return matcher.getNode(ISD::OR, SDLoc(N), VT, Cond, F );
11319
+ return matcher.getNode(ISD::OR, SDLoc(N), VT, Cond, FreezeIfNeeded(F) );
11314
11320
11315
11321
// select Cond, T, Cond --> and Cond, T
11316
11322
// select Cond, T, 0 --> and Cond, T
11317
11323
if (Cond == F || isNullOrNullSplat(F, /* AllowUndefs */ true))
11318
- return matcher.getNode(ISD::AND, SDLoc(N), VT, Cond, T );
11324
+ return matcher.getNode(ISD::AND, SDLoc(N), VT, Cond, FreezeIfNeeded(T) );
11319
11325
11320
11326
// select Cond, T, 1 --> or (not Cond), T
11321
11327
if (isOneOrOneSplat(F, /* AllowUndefs */ true)) {
11322
11328
SDValue NotCond = matcher.getNode(ISD::XOR, SDLoc(N), VT, Cond,
11323
11329
DAG.getAllOnesConstant(SDLoc(N), VT));
11324
- return matcher.getNode(ISD::OR, SDLoc(N), VT, NotCond, T );
11330
+ return matcher.getNode(ISD::OR, SDLoc(N), VT, NotCond, FreezeIfNeeded(T) );
11325
11331
}
11326
11332
11327
11333
// select Cond, 0, F --> and (not Cond), F
11328
11334
if (isNullOrNullSplat(T, /* AllowUndefs */ true)) {
11329
11335
SDValue NotCond = matcher.getNode(ISD::XOR, SDLoc(N), VT, Cond,
11330
11336
DAG.getAllOnesConstant(SDLoc(N), VT));
11331
- return matcher.getNode(ISD::AND, SDLoc(N), VT, NotCond, F );
11337
+ return matcher.getNode(ISD::AND, SDLoc(N), VT, NotCond, FreezeIfNeeded(F) );
11332
11338
}
11333
11339
11334
11340
return SDValue();
@@ -11357,20 +11363,26 @@ static SDValue foldVSelectToSignBitSplatMask(SDNode *N, SelectionDAG &DAG) {
11357
11363
else
11358
11364
return SDValue();
11359
11365
11366
+ auto FreezeIfNeeded = [&](SDValue V) {
11367
+ if (!DAG.isGuaranteedNotToBePoison(V))
11368
+ return DAG.getFreeze(V);
11369
+ return V;
11370
+ };
11371
+
11360
11372
// (Cond0 s< 0) ? N1 : 0 --> (Cond0 s>> BW-1) & N1
11361
11373
if (isNullOrNullSplat(N2)) {
11362
11374
SDLoc DL(N);
11363
11375
SDValue ShiftAmt = DAG.getConstant(VT.getScalarSizeInBits() - 1, DL, VT);
11364
11376
SDValue Sra = DAG.getNode(ISD::SRA, DL, VT, Cond0, ShiftAmt);
11365
- return DAG.getNode(ISD::AND, DL, VT, Sra, N1 );
11377
+ return DAG.getNode(ISD::AND, DL, VT, Sra, FreezeIfNeeded(N1) );
11366
11378
}
11367
11379
11368
11380
// (Cond0 s< 0) ? -1 : N2 --> (Cond0 s>> BW-1) | N2
11369
11381
if (isAllOnesOrAllOnesSplat(N1)) {
11370
11382
SDLoc DL(N);
11371
11383
SDValue ShiftAmt = DAG.getConstant(VT.getScalarSizeInBits() - 1, DL, VT);
11372
11384
SDValue Sra = DAG.getNode(ISD::SRA, DL, VT, Cond0, ShiftAmt);
11373
- return DAG.getNode(ISD::OR, DL, VT, Sra, N2 );
11385
+ return DAG.getNode(ISD::OR, DL, VT, Sra, FreezeIfNeeded(N2) );
11374
11386
}
11375
11387
11376
11388
// If we have to invert the sign bit mask, only do that transform if the
@@ -11382,7 +11394,7 @@ static SDValue foldVSelectToSignBitSplatMask(SDNode *N, SelectionDAG &DAG) {
11382
11394
SDValue ShiftAmt = DAG.getConstant(VT.getScalarSizeInBits() - 1, DL, VT);
11383
11395
SDValue Sra = DAG.getNode(ISD::SRA, DL, VT, Cond0, ShiftAmt);
11384
11396
SDValue Not = DAG.getNOT(DL, Sra, VT);
11385
- return DAG.getNode(ISD::AND, DL, VT, Not, N2 );
11397
+ return DAG.getNode(ISD::AND, DL, VT, Not, FreezeIfNeeded(N2) );
11386
11398
}
11387
11399
11388
11400
// TODO: There's another pattern in this family, but it may require
0 commit comments