@@ -2436,6 +2436,16 @@ SDValue SelectionDAG::FoldSetCC(EVT VT, SDValue N1, SDValue N2,
2436
2436
ISD::CondCode Cond, const SDLoc &dl) {
2437
2437
EVT OpVT = N1.getValueType ();
2438
2438
2439
+ auto GetUndefBooleanConstant = [&]() {
2440
+ if (VT.getScalarType () == MVT::i1 ||
2441
+ TLI->getBooleanContents (OpVT) ==
2442
+ TargetLowering::UndefinedBooleanContent)
2443
+ return getUNDEF (VT);
2444
+ // ZeroOrOne / ZeroOrNegative require specific values for the high bits,
2445
+ // so we cannot use getUNDEF(). Return zero instead.
2446
+ return getConstant (0 , dl, VT);
2447
+ };
2448
+
2439
2449
// These setcc operations always fold.
2440
2450
switch (Cond) {
2441
2451
default : break ;
@@ -2465,12 +2475,12 @@ SDValue SelectionDAG::FoldSetCC(EVT VT, SDValue N1, SDValue N2,
2465
2475
// icmp eq/ne X, undef -> undef.
2466
2476
if ((N1.isUndef () || N2.isUndef ()) &&
2467
2477
(Cond == ISD::SETEQ || Cond == ISD::SETNE))
2468
- return getUNDEF(VT );
2478
+ return GetUndefBooleanConstant ( );
2469
2479
2470
2480
// If both operands are undef, we can return undef for int comparison.
2471
2481
// icmp undef, undef -> undef.
2472
2482
if (N1.isUndef () && N2.isUndef ())
2473
- return getUNDEF(VT );
2483
+ return GetUndefBooleanConstant ( );
2474
2484
2475
2485
// icmp X, X -> true/false
2476
2486
// icmp X, undef -> true/false because undef could be X.
@@ -2496,34 +2506,34 @@ SDValue SelectionDAG::FoldSetCC(EVT VT, SDValue N1, SDValue N2,
2496
2506
switch (Cond) {
2497
2507
default : break ;
2498
2508
case ISD::SETEQ: if (R==APFloat::cmpUnordered)
2499
- return getUNDEF(VT );
2509
+ return GetUndefBooleanConstant ( );
2500
2510
[[fallthrough]];
2501
2511
case ISD::SETOEQ: return getBoolConstant (R==APFloat::cmpEqual, dl, VT,
2502
2512
OpVT);
2503
2513
case ISD::SETNE: if (R==APFloat::cmpUnordered)
2504
- return getUNDEF(VT );
2514
+ return GetUndefBooleanConstant ( );
2505
2515
[[fallthrough]];
2506
2516
case ISD::SETONE: return getBoolConstant (R==APFloat::cmpGreaterThan ||
2507
2517
R==APFloat::cmpLessThan, dl, VT,
2508
2518
OpVT);
2509
2519
case ISD::SETLT: if (R==APFloat::cmpUnordered)
2510
- return getUNDEF(VT );
2520
+ return GetUndefBooleanConstant ( );
2511
2521
[[fallthrough]];
2512
2522
case ISD::SETOLT: return getBoolConstant (R==APFloat::cmpLessThan, dl, VT,
2513
2523
OpVT);
2514
2524
case ISD::SETGT: if (R==APFloat::cmpUnordered)
2515
- return getUNDEF(VT );
2525
+ return GetUndefBooleanConstant ( );
2516
2526
[[fallthrough]];
2517
2527
case ISD::SETOGT: return getBoolConstant (R==APFloat::cmpGreaterThan, dl,
2518
2528
VT, OpVT);
2519
2529
case ISD::SETLE: if (R==APFloat::cmpUnordered)
2520
- return getUNDEF(VT );
2530
+ return GetUndefBooleanConstant ( );
2521
2531
[[fallthrough]];
2522
2532
case ISD::SETOLE: return getBoolConstant (R==APFloat::cmpLessThan ||
2523
2533
R==APFloat::cmpEqual, dl, VT,
2524
2534
OpVT);
2525
2535
case ISD::SETGE: if (R==APFloat::cmpUnordered)
2526
- return getUNDEF(VT );
2536
+ return GetUndefBooleanConstant ( );
2527
2537
[[fallthrough]];
2528
2538
case ISD::SETOGE: return getBoolConstant (R==APFloat::cmpGreaterThan ||
2529
2539
R==APFloat::cmpEqual, dl, VT, OpVT);
@@ -2568,7 +2578,7 @@ SDValue SelectionDAG::FoldSetCC(EVT VT, SDValue N1, SDValue N2,
2568
2578
case 1 : // Known true.
2569
2579
return getBoolConstant (true , dl, VT, OpVT);
2570
2580
case 2 : // Undefined.
2571
- return getUNDEF(VT );
2581
+ return GetUndefBooleanConstant ( );
2572
2582
}
2573
2583
}
2574
2584
0 commit comments