diff --git a/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp b/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp index 3bd2494ceaa..7965e141a54 100644 --- a/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp +++ b/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp @@ -768,6 +768,16 @@ SDOperand SelectionDAGLegalize::LegalizeOp(SDOperand Op) { DAG.getConstant(0, Tmp1.getValueType())); break; default: + // If this is a comparison of the sign bit, just look at the top part. + // X > -1, x < 0 + if (ConstantSDNode *CST = dyn_cast(Node->getOperand(1))) + if ((cast(Node)->getCondition() == ISD::SETLT && + CST->getValue() == 0) || // X < 0 + (cast(Node)->getCondition() == ISD::SETGT && + (CST->isAllOnesValue()))) // X > -1 + return DAG.getSetCC(cast(Node)->getCondition(), + Node->getValueType(0), LHSHi, RHSHi); + // FIXME: This generated code sucks. ISD::CondCode LowCC; switch (cast(Node)->getCondition()) {