mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-10-19 11:02:59 +02:00
[X86] Use X86ISD::SUB instead of X86ISD::CMP in some places.
Our normal lowering for ISD::SETCC uses X86ISD::SUB to enable CSE unless the RHS is 0. optimizeCompareInstr called by the peephole pass can turn subs with unused results into cmps to clean this up. This commit makes other places that create X86ISD::CMP have the same behavior.
This commit is contained in:
parent
d0a2237efb
commit
17e0830226
@ -22230,25 +22230,25 @@ SDValue X86TargetLowering::LowerSELECT(SDValue Op, SelectionDAG &DAG) const {
|
||||
SDValue Y = isAllOnesConstant(Op2) ? Op1 : Op2;
|
||||
SDValue CmpOp0 = Cmp.getOperand(0);
|
||||
|
||||
SDVTList VTs = DAG.getVTList(Op.getValueType(), MVT::i32);
|
||||
|
||||
// Apply further optimizations for special cases
|
||||
// (select (x != 0), -1, 0) -> neg & sbb
|
||||
// (select (x == 0), 0, -1) -> neg & sbb
|
||||
if (isNullConstant(Y) &&
|
||||
(isAllOnesConstant(Op1) == (CondCode == X86::COND_NE))) {
|
||||
SDValue Zero = DAG.getConstant(0, DL, CmpOp0.getValueType());
|
||||
SDValue CmpZero = DAG.getNode(X86ISD::CMP, DL, MVT::i32, Zero, CmpOp0);
|
||||
SDVTList VTs = DAG.getVTList(Op.getValueType(), MVT::i32);
|
||||
SDValue Neg = DAG.getNode(X86ISD::SUB, DL, VTs, Zero, CmpOp0);
|
||||
Zero = DAG.getConstant(0, DL, Op.getValueType());
|
||||
return DAG.getNode(X86ISD::SBB, DL, VTs, Zero, Zero, CmpZero);
|
||||
return DAG.getNode(X86ISD::SBB, DL, VTs, Zero, Zero, Neg.getValue(1));
|
||||
}
|
||||
|
||||
Cmp = DAG.getNode(X86ISD::CMP, DL, MVT::i32,
|
||||
Cmp = DAG.getNode(X86ISD::SUB, DL, VTs,
|
||||
CmpOp0, DAG.getConstant(1, DL, CmpOp0.getValueType()));
|
||||
|
||||
SDVTList VTs = DAG.getVTList(Op.getValueType(), MVT::i32);
|
||||
SDValue Zero = DAG.getConstant(0, DL, Op.getValueType());
|
||||
SDValue Res = // Res = 0 or -1.
|
||||
DAG.getNode(X86ISD::SBB, DL, VTs, Zero, Zero, Cmp);
|
||||
DAG.getNode(X86ISD::SBB, DL, VTs, Zero, Zero, Cmp.getValue(1));
|
||||
|
||||
if (isAllOnesConstant(Op1) != (CondCode == X86::COND_E))
|
||||
Res = DAG.getNOT(DL, Res, Res.getValueType());
|
||||
@ -45010,15 +45010,18 @@ static SDValue combineAddOrSubToADCOrSBB(SDNode *N, SelectionDAG &DAG) {
|
||||
if ((IsSub && CC == X86::COND_E && ConstantX->isNullValue()) ||
|
||||
(!IsSub && CC == X86::COND_NE && ConstantX->isAllOnesValue())) {
|
||||
SDValue One = DAG.getConstant(1, DL, ZVT);
|
||||
SDValue Cmp1 = DAG.getNode(X86ISD::CMP, DL, MVT::i32, Z, One);
|
||||
SDVTList X86SubVTs = DAG.getVTList(ZVT, MVT::i32);
|
||||
SDValue Cmp1 = DAG.getNode(X86ISD::SUB, DL, X86SubVTs, Z, One);
|
||||
return DAG.getNode(X86ISD::SETCC_CARRY, DL, VT,
|
||||
DAG.getTargetConstant(X86::COND_B, DL, MVT::i8), Cmp1);
|
||||
DAG.getTargetConstant(X86::COND_B, DL, MVT::i8),
|
||||
Cmp1.getValue(1));
|
||||
}
|
||||
}
|
||||
|
||||
// (cmp Z, 1) sets the carry flag if Z is 0.
|
||||
SDValue One = DAG.getConstant(1, DL, ZVT);
|
||||
SDValue Cmp1 = DAG.getNode(X86ISD::CMP, DL, MVT::i32, Z, One);
|
||||
SDVTList X86SubVTs = DAG.getVTList(ZVT, MVT::i32);
|
||||
SDValue Cmp1 = DAG.getNode(X86ISD::SUB, DL, X86SubVTs, Z, One);
|
||||
|
||||
// Add the flags type for ADC/SBB nodes.
|
||||
SDVTList VTs = DAG.getVTList(VT, MVT::i32);
|
||||
@ -45027,12 +45030,12 @@ static SDValue combineAddOrSubToADCOrSBB(SDNode *N, SelectionDAG &DAG) {
|
||||
// X + (Z != 0) --> add X, (zext(setne Z, 0)) --> sbb X, -1, (cmp Z, 1)
|
||||
if (CC == X86::COND_NE)
|
||||
return DAG.getNode(IsSub ? X86ISD::ADC : X86ISD::SBB, DL, VTs, X,
|
||||
DAG.getConstant(-1ULL, DL, VT), Cmp1);
|
||||
DAG.getConstant(-1ULL, DL, VT), Cmp1.getValue(1));
|
||||
|
||||
// X - (Z == 0) --> sub X, (zext(sete Z, 0)) --> sbb X, 0, (cmp Z, 1)
|
||||
// X + (Z == 0) --> add X, (zext(sete Z, 0)) --> adc X, 0, (cmp Z, 1)
|
||||
return DAG.getNode(IsSub ? X86ISD::SBB : X86ISD::ADC, DL, VTs, X,
|
||||
DAG.getConstant(0, DL, VT), Cmp1);
|
||||
DAG.getConstant(0, DL, VT), Cmp1.getValue(1));
|
||||
}
|
||||
|
||||
static SDValue combineLoopMAddPattern(SDNode *N, SelectionDAG &DAG,
|
||||
|
Loading…
Reference in New Issue
Block a user