@@ -11344,28 +11344,34 @@ static SDValue foldBoolSelectToLogic(SDNode *N, SelectionDAG &DAG) {
11344
11344
if (VT != Cond.getValueType() || VT.getScalarSizeInBits() != 1)
11345
11345
return SDValue();
11346
11346
11347
- // select Cond, Cond, F --> or Cond, F
11348
- // select Cond, 1, F --> or Cond, F
11347
+ auto FreezeIfNeeded = [&](SDValue V) {
11348
+ if (!DAG.isGuaranteedNotToBePoison(V))
11349
+ return DAG.getFreeze(V);
11350
+ return V;
11351
+ };
11352
+
11353
+ // select Cond, Cond, F --> or Cond, freeze(F)
11354
+ // select Cond, 1, F --> or Cond, freeze(F)
11349
11355
if (Cond == T || isOneOrOneSplat(T, /* AllowUndefs */ true))
11350
- return matcher.getNode(ISD::OR, SDLoc(N), VT, Cond, F );
11356
+ return matcher.getNode(ISD::OR, SDLoc(N), VT, Cond, FreezeIfNeeded(F) );
11351
11357
11352
11358
// select Cond, T, Cond --> and Cond, T
11353
11359
// select Cond, T, 0 --> and Cond, T
11354
11360
if (Cond == F || isNullOrNullSplat(F, /* AllowUndefs */ true))
11355
- return matcher.getNode(ISD::AND, SDLoc(N), VT, Cond, T );
11361
+ return matcher.getNode(ISD::AND, SDLoc(N), VT, Cond, FreezeIfNeeded(T) );
11356
11362
11357
11363
// select Cond, T, 1 --> or (not Cond), T
11358
11364
if (isOneOrOneSplat(F, /* AllowUndefs */ true)) {
11359
11365
SDValue NotCond = matcher.getNode(ISD::XOR, SDLoc(N), VT, Cond,
11360
11366
DAG.getAllOnesConstant(SDLoc(N), VT));
11361
- return matcher.getNode(ISD::OR, SDLoc(N), VT, NotCond, T );
11367
+ return matcher.getNode(ISD::OR, SDLoc(N), VT, NotCond, FreezeIfNeeded(T) );
11362
11368
}
11363
11369
11364
11370
// select Cond, 0, F --> and (not Cond), F
11365
11371
if (isNullOrNullSplat(T, /* AllowUndefs */ true)) {
11366
11372
SDValue NotCond = matcher.getNode(ISD::XOR, SDLoc(N), VT, Cond,
11367
11373
DAG.getAllOnesConstant(SDLoc(N), VT));
11368
- return matcher.getNode(ISD::AND, SDLoc(N), VT, NotCond, F );
11374
+ return matcher.getNode(ISD::AND, SDLoc(N), VT, NotCond, FreezeIfNeeded(F) );
11369
11375
}
11370
11376
11371
11377
return SDValue();
@@ -11394,20 +11400,26 @@ static SDValue foldVSelectToSignBitSplatMask(SDNode *N, SelectionDAG &DAG) {
11394
11400
else
11395
11401
return SDValue();
11396
11402
11403
+ auto FreezeIfNeeded = [&](SDValue V) {
11404
+ if (!DAG.isGuaranteedNotToBePoison(V))
11405
+ return DAG.getFreeze(V);
11406
+ return V;
11407
+ };
11408
+
11397
11409
// (Cond0 s< 0) ? N1 : 0 --> (Cond0 s>> BW-1) & N1
11398
11410
if (isNullOrNullSplat(N2)) {
11399
11411
SDLoc DL(N);
11400
11412
SDValue ShiftAmt = DAG.getConstant(VT.getScalarSizeInBits() - 1, DL, VT);
11401
11413
SDValue Sra = DAG.getNode(ISD::SRA, DL, VT, Cond0, ShiftAmt);
11402
- return DAG.getNode(ISD::AND, DL, VT, Sra, N1 );
11414
+ return DAG.getNode(ISD::AND, DL, VT, Sra, FreezeIfNeeded(N1) );
11403
11415
}
11404
11416
11405
11417
// (Cond0 s< 0) ? -1 : N2 --> (Cond0 s>> BW-1) | N2
11406
11418
if (isAllOnesOrAllOnesSplat(N1)) {
11407
11419
SDLoc DL(N);
11408
11420
SDValue ShiftAmt = DAG.getConstant(VT.getScalarSizeInBits() - 1, DL, VT);
11409
11421
SDValue Sra = DAG.getNode(ISD::SRA, DL, VT, Cond0, ShiftAmt);
11410
- return DAG.getNode(ISD::OR, DL, VT, Sra, N2 );
11422
+ return DAG.getNode(ISD::OR, DL, VT, Sra, FreezeIfNeeded(N2) );
11411
11423
}
11412
11424
11413
11425
// If we have to invert the sign bit mask, only do that transform if the
@@ -11419,7 +11431,7 @@ static SDValue foldVSelectToSignBitSplatMask(SDNode *N, SelectionDAG &DAG) {
11419
11431
SDValue ShiftAmt = DAG.getConstant(VT.getScalarSizeInBits() - 1, DL, VT);
11420
11432
SDValue Sra = DAG.getNode(ISD::SRA, DL, VT, Cond0, ShiftAmt);
11421
11433
SDValue Not = DAG.getNOT(DL, Sra, VT);
11422
- return DAG.getNode(ISD::AND, DL, VT, Not, N2 );
11434
+ return DAG.getNode(ISD::AND, DL, VT, Not, FreezeIfNeeded(N2) );
11423
11435
}
11424
11436
11425
11437
// TODO: There's another pattern in this family, but it may require
0 commit comments