@@ -2470,6 +2470,16 @@ SDValue SelectionDAG::FoldSetCC(EVT VT, SDValue N1, SDValue N2,
2470
2470
ISD::CondCode Cond, const SDLoc &dl) {
2471
2471
EVT OpVT = N1.getValueType ();
2472
2472
2473
+ auto GetUndefBooleanConstant = [&]() {
2474
+ if (VT.getScalarType () == MVT::i1 ||
2475
+ TLI->getBooleanContents (OpVT) ==
2476
+ TargetLowering::UndefinedBooleanContent)
2477
+ return getUNDEF (VT);
2478
+ // ZeroOrOne / ZeroOrNegative require specific values for the high bits,
2479
+ // so we cannot use getUNDEF(). Return zero instead.
2480
+ return getConstant (0 , dl, VT);
2481
+ };
2482
+
2473
2483
// These setcc operations always fold.
2474
2484
switch (Cond) {
2475
2485
default : break ;
@@ -2499,12 +2509,12 @@ SDValue SelectionDAG::FoldSetCC(EVT VT, SDValue N1, SDValue N2,
2499
2509
// icmp eq/ne X, undef -> undef.
2500
2510
if ((N1.isUndef () || N2.isUndef ()) &&
2501
2511
(Cond == ISD::SETEQ || Cond == ISD::SETNE))
2502
- return getUNDEF (VT );
2512
+ return GetUndefBooleanConstant ( );
2503
2513
2504
2514
// If both operands are undef, we can return undef for int comparison.
2505
2515
// icmp undef, undef -> undef.
2506
2516
if (N1.isUndef () && N2.isUndef ())
2507
- return getUNDEF (VT );
2517
+ return GetUndefBooleanConstant ( );
2508
2518
2509
2519
// icmp X, X -> true/false
2510
2520
// icmp X, undef -> true/false because undef could be X.
@@ -2530,34 +2540,34 @@ SDValue SelectionDAG::FoldSetCC(EVT VT, SDValue N1, SDValue N2,
2530
2540
switch (Cond) {
2531
2541
default : break ;
2532
2542
case ISD::SETEQ: if (R==APFloat::cmpUnordered)
2533
- return getUNDEF (VT );
2543
+ return GetUndefBooleanConstant ( );
2534
2544
[[fallthrough]];
2535
2545
case ISD::SETOEQ: return getBoolConstant (R==APFloat::cmpEqual, dl, VT,
2536
2546
OpVT);
2537
2547
case ISD::SETNE: if (R==APFloat::cmpUnordered)
2538
- return getUNDEF (VT );
2548
+ return GetUndefBooleanConstant ( );
2539
2549
[[fallthrough]];
2540
2550
case ISD::SETONE: return getBoolConstant (R==APFloat::cmpGreaterThan ||
2541
2551
R==APFloat::cmpLessThan, dl, VT,
2542
2552
OpVT);
2543
2553
case ISD::SETLT: if (R==APFloat::cmpUnordered)
2544
- return getUNDEF (VT );
2554
+ return GetUndefBooleanConstant ( );
2545
2555
[[fallthrough]];
2546
2556
case ISD::SETOLT: return getBoolConstant (R==APFloat::cmpLessThan, dl, VT,
2547
2557
OpVT);
2548
2558
case ISD::SETGT: if (R==APFloat::cmpUnordered)
2549
- return getUNDEF (VT );
2559
+ return GetUndefBooleanConstant ( );
2550
2560
[[fallthrough]];
2551
2561
case ISD::SETOGT: return getBoolConstant (R==APFloat::cmpGreaterThan, dl,
2552
2562
VT, OpVT);
2553
2563
case ISD::SETLE: if (R==APFloat::cmpUnordered)
2554
- return getUNDEF (VT );
2564
+ return GetUndefBooleanConstant ( );
2555
2565
[[fallthrough]];
2556
2566
case ISD::SETOLE: return getBoolConstant (R==APFloat::cmpLessThan ||
2557
2567
R==APFloat::cmpEqual, dl, VT,
2558
2568
OpVT);
2559
2569
case ISD::SETGE: if (R==APFloat::cmpUnordered)
2560
- return getUNDEF (VT );
2570
+ return GetUndefBooleanConstant ( );
2561
2571
[[fallthrough]];
2562
2572
case ISD::SETOGE: return getBoolConstant (R==APFloat::cmpGreaterThan ||
2563
2573
R==APFloat::cmpEqual, dl, VT, OpVT);
@@ -2602,7 +2612,7 @@ SDValue SelectionDAG::FoldSetCC(EVT VT, SDValue N1, SDValue N2,
2602
2612
case 1 : // Known true.
2603
2613
return getBoolConstant (true , dl, VT, OpVT);
2604
2614
case 2 : // Undefined.
2605
- return getUNDEF (VT );
2615
+ return GetUndefBooleanConstant ( );
2606
2616
}
2607
2617
}
2608
2618
0 commit comments