Skip to content

Commit 40fe1c7

Browse files
committed
Address review comments
1 parent e2e0635 commit 40fe1c7

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10387,16 +10387,20 @@ SDValue TargetLowering::expandCMP(SDNode *Node, SelectionDAG &DAG) const {
1038710387
// We can't perform arithmetic on i1 values. Extending them would
1038810388
// probably result in worse codegen, so let's just use two selects instead.
1038910389
// 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) {
1039310395
SDValue SelectZeroOrOne =
1039410396
DAG.getSelect(dl, ResVT, IsGT, DAG.getConstant(1, dl, ResVT),
1039510397
DAG.getConstant(0, dl, ResVT));
1039610398
return DAG.getSelect(dl, ResVT, IsLT, DAG.getConstant(-1, dl, ResVT),
1039710399
SelectZeroOrOne);
1039810400
}
1039910401

10402+
if (getBooleanContents(BoolVT) == ZeroOrNegativeOneBooleanContent)
10403+
std::swap(LHS, RHS);
1040010404
return DAG.getSExtOrTrunc(DAG.getNode(ISD::SUB, dl, BoolVT, IsGT, IsLT), dl,
1040110405
ResVT);
1040210406
}

0 commit comments

Comments
 (0)