@@ -2381,6 +2381,16 @@ SDValue SelectionDAG::FoldSetCC(EVT VT, SDValue N1, SDValue N2,
2381
2381
ISD::CondCode Cond, const SDLoc &dl) {
2382
2382
EVT OpVT = N1.getValueType ();
2383
2383
2384
+ auto GetUndefBooleanConstant = [&]() {
2385
+ if (VT.getScalarType () == MVT::i1 ||
2386
+ TLI->getBooleanContents (OpVT) ==
2387
+ TargetLowering::UndefinedBooleanContent)
2388
+ return getUNDEF (VT);
2389
+ // ZeroOrOne / ZeroOrNegative require specific values for the high bits,
2390
+ // so we cannot use getUNDEF(). Return zero instead.
2391
+ return getConstant (0 , dl, VT);
2392
+ };
2393
+
2384
2394
// These setcc operations always fold.
2385
2395
switch (Cond) {
2386
2396
default : break ;
@@ -2410,12 +2420,12 @@ SDValue SelectionDAG::FoldSetCC(EVT VT, SDValue N1, SDValue N2,
2410
2420
// icmp eq/ne X, undef -> undef.
2411
2421
if ((N1.isUndef () || N2.isUndef ()) &&
2412
2422
(Cond == ISD::SETEQ || Cond == ISD::SETNE))
2413
- return getUNDEF (VT );
2423
+ return GetUndefBooleanConstant ( );
2414
2424
2415
2425
// If both operands are undef, we can return undef for int comparison.
2416
2426
// icmp undef, undef -> undef.
2417
2427
if (N1.isUndef () && N2.isUndef ())
2418
- return getUNDEF (VT );
2428
+ return GetUndefBooleanConstant ( );
2419
2429
2420
2430
// icmp X, X -> true/false
2421
2431
// icmp X, undef -> true/false because undef could be X.
@@ -2441,34 +2451,34 @@ SDValue SelectionDAG::FoldSetCC(EVT VT, SDValue N1, SDValue N2,
2441
2451
switch (Cond) {
2442
2452
default : break ;
2443
2453
case ISD::SETEQ: if (R==APFloat::cmpUnordered)
2444
- return getUNDEF (VT );
2454
+ return GetUndefBooleanConstant ( );
2445
2455
[[fallthrough]];
2446
2456
case ISD::SETOEQ: return getBoolConstant (R==APFloat::cmpEqual, dl, VT,
2447
2457
OpVT);
2448
2458
case ISD::SETNE: if (R==APFloat::cmpUnordered)
2449
- return getUNDEF (VT );
2459
+ return GetUndefBooleanConstant ( );
2450
2460
[[fallthrough]];
2451
2461
case ISD::SETONE: return getBoolConstant (R==APFloat::cmpGreaterThan ||
2452
2462
R==APFloat::cmpLessThan, dl, VT,
2453
2463
OpVT);
2454
2464
case ISD::SETLT: if (R==APFloat::cmpUnordered)
2455
- return getUNDEF (VT );
2465
+ return GetUndefBooleanConstant ( );
2456
2466
[[fallthrough]];
2457
2467
case ISD::SETOLT: return getBoolConstant (R==APFloat::cmpLessThan, dl, VT,
2458
2468
OpVT);
2459
2469
case ISD::SETGT: if (R==APFloat::cmpUnordered)
2460
- return getUNDEF (VT );
2470
+ return GetUndefBooleanConstant ( );
2461
2471
[[fallthrough]];
2462
2472
case ISD::SETOGT: return getBoolConstant (R==APFloat::cmpGreaterThan, dl,
2463
2473
VT, OpVT);
2464
2474
case ISD::SETLE: if (R==APFloat::cmpUnordered)
2465
- return getUNDEF (VT );
2475
+ return GetUndefBooleanConstant ( );
2466
2476
[[fallthrough]];
2467
2477
case ISD::SETOLE: return getBoolConstant (R==APFloat::cmpLessThan ||
2468
2478
R==APFloat::cmpEqual, dl, VT,
2469
2479
OpVT);
2470
2480
case ISD::SETGE: if (R==APFloat::cmpUnordered)
2471
- return getUNDEF (VT );
2481
+ return GetUndefBooleanConstant ( );
2472
2482
[[fallthrough]];
2473
2483
case ISD::SETOGE: return getBoolConstant (R==APFloat::cmpGreaterThan ||
2474
2484
R==APFloat::cmpEqual, dl, VT, OpVT);
@@ -2513,7 +2523,7 @@ SDValue SelectionDAG::FoldSetCC(EVT VT, SDValue N1, SDValue N2,
2513
2523
case 1 : // Known true.
2514
2524
return getBoolConstant (true , dl, VT, OpVT);
2515
2525
case 2 : // Undefined.
2516
- return getUNDEF (VT );
2526
+ return GetUndefBooleanConstant ( );
2517
2527
}
2518
2528
}
2519
2529
0 commit comments