@@ -10387,16 +10387,20 @@ SDValue TargetLowering::expandCMP(SDNode *Node, SelectionDAG &DAG) const {
10387
10387
// We can't perform arithmetic on i1 values. Extending them would
10388
10388
// probably result in worse codegen, so let's just use two selects instead.
10389
10389
// Some targets are also just better off using selects rather than subtraction
10390
- // because one of the conditions can be merged with one of the selects
10391
- EVT BoolElVT = BoolVT.isVector () ? BoolVT.getVectorElementType () : BoolVT;
10392
- if (shouldExpandCmpUsingSelects () || !BoolElVT.knownBitsGT (MVT::i1)) {
10390
+ // because one of the conditions can be merged with one of the selects.
10391
+ // And finally, if we don't know the contents of high bits of a boolean value
10392
+ // we can't perform any arithmetic either.
10393
+ if (shouldExpandCmpUsingSelects () || BoolVT.getScalarSizeInBits () == 1 ||
10394
+ getBooleanContents (BoolVT) == UndefinedBooleanContent) {
10393
10395
SDValue SelectZeroOrOne =
10394
10396
DAG.getSelect (dl, ResVT, IsGT, DAG.getConstant (1 , dl, ResVT),
10395
10397
DAG.getConstant (0 , dl, ResVT));
10396
10398
return DAG.getSelect (dl, ResVT, IsLT, DAG.getConstant (-1 , dl, ResVT),
10397
10399
SelectZeroOrOne);
10398
10400
}
10399
10401
10402
+ if (getBooleanContents (BoolVT) == ZeroOrNegativeOneBooleanContent)
10403
+ std::swap (LHS, RHS);
10400
10404
return DAG.getSExtOrTrunc (DAG.getNode (ISD::SUB, dl, BoolVT, IsGT, IsLT), dl,
10401
10405
ResVT);
10402
10406
}
0 commit comments