Add support for promoting SETCC operations.

llvm-svn: 76987
This commit is contained in:
Jakob Stoklund Olesen 2009-07-24 18:22:59 +00:00
parent 666c912ce3
commit 1ae0736830
5 changed files with 25 additions and 15 deletions

View File

@ -797,14 +797,17 @@ public:
struct DAGCombinerInfo { struct DAGCombinerInfo {
void *DC; // The DAG Combiner object. void *DC; // The DAG Combiner object.
bool BeforeLegalize; bool BeforeLegalize;
bool BeforeLegalizeOps;
bool CalledByLegalizer; bool CalledByLegalizer;
public: public:
SelectionDAG &DAG; SelectionDAG &DAG;
DAGCombinerInfo(SelectionDAG &dag, bool bl, bool cl, void *dc) DAGCombinerInfo(SelectionDAG &dag, bool bl, bool blo, bool cl, void *dc)
: DC(dc), BeforeLegalize(bl), CalledByLegalizer(cl), DAG(dag) {} : DC(dc), BeforeLegalize(bl), BeforeLegalizeOps(blo),
CalledByLegalizer(cl), DAG(dag) {}
bool isBeforeLegalize() const { return BeforeLegalize; } bool isBeforeLegalize() const { return BeforeLegalize; }
bool isBeforeLegalizeOps() const { return BeforeLegalizeOps; }
bool isCalledByLegalizer() const { return CalledByLegalizer; } bool isCalledByLegalizer() const { return CalledByLegalizer; }
void AddToWorklist(SDNode *N); void AddToWorklist(SDNode *N);

View File

@ -802,7 +802,7 @@ SDValue DAGCombiner::combine(SDNode *N) {
// Expose the DAG combiner to the target combiner impls. // Expose the DAG combiner to the target combiner impls.
TargetLowering::DAGCombinerInfo TargetLowering::DAGCombinerInfo
DagCombineInfo(DAG, Level == Unrestricted, false, this); DagCombineInfo(DAG, !LegalTypes, !LegalOperations, false, this);
RV = TLI.PerformDAGCombine(N, DagCombineInfo); RV = TLI.PerformDAGCombine(N, DagCombineInfo);
} }
@ -6005,7 +6005,7 @@ SDValue DAGCombiner::SimplifySetCC(MVT VT, SDValue N0,
SDValue N1, ISD::CondCode Cond, SDValue N1, ISD::CondCode Cond,
DebugLoc DL, bool foldBooleans) { DebugLoc DL, bool foldBooleans) {
TargetLowering::DAGCombinerInfo TargetLowering::DAGCombinerInfo
DagCombineInfo(DAG, Level == Unrestricted, false, this); DagCombineInfo(DAG, !LegalTypes, !LegalOperations, false, this);
return TLI.SimplifySetCC(VT, N0, N1, Cond, foldBooleans, DagCombineInfo, DL); return TLI.SimplifySetCC(VT, N0, N1, Cond, foldBooleans, DagCombineInfo, DL);
} }

View File

@ -3086,12 +3086,14 @@ void SelectionDAGLegalize::PromoteNode(SDNode *Node,
break; break;
} }
case ISD::SETCC: { case ISD::SETCC: {
if (NVT.isInteger()) unsigned ExtOp = ISD::FP_EXTEND;
llvm_unreachable("Cannot promote Legal Integer SETCC yet"); if (NVT.isInteger()) {
else { ISD::CondCode CCCode =
Tmp1 = DAG.getNode(ISD::FP_EXTEND, dl, NVT, Node->getOperand(0)); cast<CondCodeSDNode>(Node->getOperand(2))->get();
Tmp2 = DAG.getNode(ISD::FP_EXTEND, dl, NVT, Node->getOperand(1)); ExtOp = isSignedIntSetCC(CCCode) ? ISD::SIGN_EXTEND : ISD::ZERO_EXTEND;
} }
Tmp1 = DAG.getNode(ExtOp, dl, NVT, Node->getOperand(0));
Tmp2 = DAG.getNode(ExtOp, dl, NVT, Node->getOperand(1));
Results.push_back(DAG.getNode(ISD::SETCC, dl, Node->getValueType(0), Results.push_back(DAG.getNode(ISD::SETCC, dl, Node->getValueType(0),
Tmp1, Tmp2, Node->getOperand(2))); Tmp1, Tmp2, Node->getOperand(2)));
break; break;

View File

@ -2067,7 +2067,7 @@ void DAGTypeLegalizer::IntegerExpandSetCCOperands(SDValue &NewLHS,
// NOTE: on targets without efficient SELECT of bools, we can always use // NOTE: on targets without efficient SELECT of bools, we can always use
// this identity: (B1 ? B2 : B3) --> (B1 & B2)|(!B1&B3) // this identity: (B1 ? B2 : B3) --> (B1 & B2)|(!B1&B3)
TargetLowering::DAGCombinerInfo DagCombineInfo(DAG, false, true, NULL); TargetLowering::DAGCombinerInfo DagCombineInfo(DAG, false, true, true, NULL);
SDValue Tmp1, Tmp2; SDValue Tmp1, Tmp2;
Tmp1 = TLI.SimplifySetCC(TLI.getSetCCResultType(LHSLo.getValueType()), Tmp1 = TLI.SimplifySetCC(TLI.getSetCCResultType(LHSLo.getValueType()),
LHSLo, RHSLo, LowCC, false, DagCombineInfo, dl); LHSLo, RHSLo, LowCC, false, DagCombineInfo, dl);

View File

@ -1641,11 +1641,16 @@ TargetLowering::SimplifySetCC(MVT VT, SDValue N0, SDValue N1,
case ISD::SETUGT: case ISD::SETUGT:
case ISD::SETUGE: case ISD::SETUGE:
case ISD::SETULT: case ISD::SETULT:
case ISD::SETULE: case ISD::SETULE: {
return DAG.getSetCC(dl, VT, N0.getOperand(0), MVT newVT = N0.getOperand(0).getValueType();
DAG.getConstant(APInt(C1).trunc(InSize), if (DCI.isBeforeLegalizeOps() ||
N0.getOperand(0).getValueType()), (isOperationLegal(ISD::SETCC, newVT) &&
Cond); getCondCodeAction(Cond, newVT)==Legal))
return DAG.getSetCC(dl, VT, N0.getOperand(0),
DAG.getConstant(APInt(C1).trunc(InSize), newVT),
Cond);
break;
}
default: default:
break; // todo, be more careful with signed comparisons break; // todo, be more careful with signed comparisons
} }