@@ -24084,13 +24084,13 @@ static SDValue LowerSELECTWithCmpZero(SDValue CmpVal, SDValue LHS, SDValue RHS,
24084
24084
if (!CmpVT.isScalarInteger() || !VT.isScalarInteger())
24085
24085
return SDValue();
24086
24086
24087
+ // Convert OR/XOR 'identity' patterns (iff X is 0 or 1):
24088
+ // select (X != 0), Y, (OR Y, Z) -> (OR Y, (AND (0 - X), Z))
24089
+ // select (X != 0), Y, (XOR Y, Z) -> (XOR Y, (AND (0 - X), Z))
24087
24090
if (!Subtarget.canUseCMOV() && X86CC == X86::COND_E &&
24088
24091
CmpVal.getOpcode() == ISD::AND && isOneConstant(CmpVal.getOperand(1))) {
24089
24092
SDValue Src1, Src2;
24090
- // true if RHS is XOR or OR operator and one of its operands
24091
- // is equal to LHS
24092
- // ( a , a op b) || ( b , a op b)
24093
- auto isOrXorPattern = [&]() {
24093
+ auto isIdentityPattern = [&]() {
24094
24094
if ((RHS.getOpcode() == ISD::XOR || RHS.getOpcode() == ISD::OR) &&
24095
24095
(RHS.getOperand(0) == LHS || RHS.getOperand(1) == LHS)) {
24096
24096
Src1 = RHS.getOperand(RHS.getOperand(0) == LHS ? 1 : 0);
@@ -24100,20 +24100,17 @@ static SDValue LowerSELECTWithCmpZero(SDValue CmpVal, SDValue LHS, SDValue RHS,
24100
24100
return false;
24101
24101
};
24102
24102
24103
- if (isOrXorPattern()) {
24104
- SDValue Neg;
24105
- unsigned int CmpSz = CmpVT.getSizeInBits();
24103
+ if (isIdentityPattern()) {
24106
24104
// we need mask of all zeros or ones with same size of the other
24107
24105
// operands.
24108
- if (CmpSz > VT.getSizeInBits())
24106
+ SDValue Neg = CmpVal;
24107
+ if (CmpVT.bitsGT(VT))
24109
24108
Neg = DAG.getNode(ISD::TRUNCATE, DL, VT, CmpVal);
24110
- else if (CmpSz < VT.getSizeInBits( ))
24109
+ else if (CmpVT.bitsLT(VT ))
24111
24110
Neg = DAG.getNode(
24112
24111
ISD::AND, DL, VT,
24113
24112
DAG.getNode(ISD::ANY_EXTEND, DL, VT, CmpVal.getOperand(0)),
24114
24113
DAG.getConstant(1, DL, VT));
24115
- else
24116
- Neg = CmpVal;
24117
24114
SDValue Mask = DAG.getNegative(Neg, DL, VT); // -(and (x, 0x1))
24118
24115
SDValue And = DAG.getNode(ISD::AND, DL, VT, Mask, Src1); // Mask & z
24119
24116
return DAG.getNode(RHS.getOpcode(), DL, VT, And, Src2); // And Op y
0 commit comments