mirror of
https://github.com/c64scene-ar/llvm-6502.git
synced 2025-09-24 23:28:41 +00:00
SelectionDAG: Try to expand all condition codes using getCCSwappedOperands()
This is useful for targets like R600, which only support GT, GE, NE, and EQ condition codes as it removes the need to handle unsupported condition codes in target specific code. There are no tests with this commit, but R600 has been updated to take advantage of this new feature, so its existing selectcc tests are now testing the swapped operands path. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@191601 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
@@ -1615,8 +1615,13 @@ bool SelectionDAGLegalize::LegalizeSetCCCondCode(EVT VT,
|
||||
// Nothing to do.
|
||||
break;
|
||||
case TargetLowering::Expand: {
|
||||
ISD::CondCode InvCC = ISD::getSetCCSwappedOperands(CCCode);
|
||||
if (TLI.isCondCodeLegal(InvCC, OpVT)) {
|
||||
std::swap(LHS, RHS);
|
||||
CC = DAG.getCondCode(InvCC);
|
||||
return true;
|
||||
}
|
||||
ISD::CondCode CC1 = ISD::SETCC_INVALID, CC2 = ISD::SETCC_INVALID;
|
||||
ISD::CondCode InvCC = ISD::SETCC_INVALID;
|
||||
unsigned Opc = 0;
|
||||
switch (CCCode) {
|
||||
default: llvm_unreachable("Don't know how to expand this condition!");
|
||||
@@ -1658,15 +1663,9 @@ bool SelectionDAGLegalize::LegalizeSetCCCondCode(EVT VT,
|
||||
case ISD::SETLT:
|
||||
case ISD::SETNE:
|
||||
case ISD::SETEQ:
|
||||
InvCC = ISD::getSetCCSwappedOperands(CCCode);
|
||||
if (TLI.getCondCodeAction(InvCC, OpVT) == TargetLowering::Expand) {
|
||||
// We only support using the inverted operation and not a
|
||||
// different manner of supporting expanding these cases.
|
||||
llvm_unreachable("Don't know how to expand this condition!");
|
||||
}
|
||||
std::swap(LHS, RHS);
|
||||
CC = DAG.getCondCode(InvCC);
|
||||
return true;
|
||||
// We only support using the inverted operation, which is computed above
|
||||
// and not a different manner of supporting expanding these cases.
|
||||
llvm_unreachable("Don't know how to expand this condition!");
|
||||
}
|
||||
|
||||
SDValue SetCC1, SetCC2;
|
||||
|
@@ -1645,7 +1645,12 @@ SDValue SelectionDAG::FoldSetCC(EVT VT, SDValue N1,
|
||||
}
|
||||
} else {
|
||||
// Ensure that the constant occurs on the RHS.
|
||||
return getSetCC(dl, VT, N2, N1, ISD::getSetCCSwappedOperands(Cond));
|
||||
ISD::CondCode SwappedCond = ISD::getSetCCSwappedOperands(Cond);
|
||||
MVT CompVT = N1.getValueType().getSimpleVT();
|
||||
if (!TM.getTargetLowering()->isCondCodeLegal(SwappedCond, CompVT))
|
||||
return SDValue();
|
||||
|
||||
return getSetCC(dl, VT, N2, N1, SwappedCond);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -1089,8 +1089,11 @@ TargetLowering::SimplifySetCC(EVT VT, SDValue N0, SDValue N1,
|
||||
|
||||
// Ensure that the constant occurs on the RHS, and fold constant
|
||||
// comparisons.
|
||||
if (isa<ConstantSDNode>(N0.getNode()))
|
||||
return DAG.getSetCC(dl, VT, N1, N0, ISD::getSetCCSwappedOperands(Cond));
|
||||
ISD::CondCode SwappedCC = ISD::getSetCCSwappedOperands(Cond);
|
||||
if (isa<ConstantSDNode>(N0.getNode()) &&
|
||||
(DCI.isBeforeLegalizeOps() ||
|
||||
isCondCodeLegal(SwappedCC, N0.getSimpleValueType())))
|
||||
return DAG.getSetCC(dl, VT, N1, N0, SwappedCC);
|
||||
|
||||
if (ConstantSDNode *N1C = dyn_cast<ConstantSDNode>(N1.getNode())) {
|
||||
const APInt &C1 = N1C->getAPIntValue();
|
||||
@@ -1330,7 +1333,9 @@ TargetLowering::SimplifySetCC(EVT VT, SDValue N0, SDValue N1,
|
||||
ISD::CondCode CC = cast<CondCodeSDNode>(N0.getOperand(2))->get();
|
||||
CC = ISD::getSetCCInverse(CC,
|
||||
N0.getOperand(0).getValueType().isInteger());
|
||||
return DAG.getSetCC(dl, VT, N0.getOperand(0), N0.getOperand(1), CC);
|
||||
if (DCI.isBeforeLegalizeOps() ||
|
||||
isCondCodeLegal(CC, N0.getOperand(0).getSimpleValueType()))
|
||||
return DAG.getSetCC(dl, VT, N0.getOperand(0), N0.getOperand(1), CC);
|
||||
}
|
||||
|
||||
if ((N0.getOpcode() == ISD::XOR ||
|
||||
@@ -1767,16 +1772,22 @@ TargetLowering::SimplifySetCC(EVT VT, SDValue N0, SDValue N1,
|
||||
if (N0.getOperand(0) == N1 || N0.getOperand(1) == N1) {
|
||||
if (ValueHasExactlyOneBitSet(N1, DAG)) {
|
||||
Cond = ISD::getSetCCInverse(Cond, /*isInteger=*/true);
|
||||
SDValue Zero = DAG.getConstant(0, N1.getValueType());
|
||||
return DAG.getSetCC(dl, VT, N0, Zero, Cond);
|
||||
if (DCI.isBeforeLegalizeOps() ||
|
||||
isCondCodeLegal(Cond, N0.getSimpleValueType())) {
|
||||
SDValue Zero = DAG.getConstant(0, N1.getValueType());
|
||||
return DAG.getSetCC(dl, VT, N0, Zero, Cond);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (N1.getOpcode() == ISD::AND)
|
||||
if (N1.getOperand(0) == N0 || N1.getOperand(1) == N0) {
|
||||
if (ValueHasExactlyOneBitSet(N0, DAG)) {
|
||||
Cond = ISD::getSetCCInverse(Cond, /*isInteger=*/true);
|
||||
SDValue Zero = DAG.getConstant(0, N0.getValueType());
|
||||
return DAG.getSetCC(dl, VT, N1, Zero, Cond);
|
||||
if (DCI.isBeforeLegalizeOps() ||
|
||||
isCondCodeLegal(Cond, N1.getSimpleValueType())) {
|
||||
SDValue Zero = DAG.getConstant(0, N0.getValueType());
|
||||
return DAG.getSetCC(dl, VT, N1, Zero, Cond);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user