[llvm-commits] [llvm] r60043 - /llvm/trunk/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp

Bill Wendling isanbard at gmail.com
Tue Nov 25 11:40:19 PST 2008


Author: void
Date: Tue Nov 25 13:40:17 2008
New Revision: 60043

URL: http://llvm.org/viewvc/llvm-project?rev=60043&view=rev
Log:
A simplification for checking whether the signs of the operands and sum differ. Thanks, Duncan.

Modified:
    llvm/trunk/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp

Modified: llvm/trunk/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp?rev=60043&r1=60042&r2=60043&view=diff

==============================================================================
--- llvm/trunk/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp (original)
+++ llvm/trunk/lib/CodeGen/SelectionDAG/LegalizeDAG.cpp Tue Nov 25 13:40:17 2008
@@ -4187,21 +4187,20 @@
 
       SDValue Zero = DAG.getConstant(0, LHS.getValueType());
 
-      SDValue LHSPos = DAG.getSetCC(OType, LHS, Zero, ISD::SETGE);
-      SDValue RHSPos = DAG.getSetCC(OType, RHS, Zero, ISD::SETGE);
-      SDValue And1 = DAG.getNode(ISD::AND, OType, LHSPos, RHSPos);
+      //   LHSSign -> LHS >= 0
+      //   RHSSign -> RHS >= 0
+      //   SumSign -> Sum >= 0
+      //
+      //   Overflow -> (LHSSign == RHSSign) && (LHSSign != SumSign)
+      //
+      SDValue LHSSign = DAG.getSetCC(OType, LHS, Zero, ISD::SETGE);
+      SDValue RHSSign = DAG.getSetCC(OType, RHS, Zero, ISD::SETGE);
+      SDValue SignsEq = DAG.getSetCC(OType, LHSSign, RHSSign, ISD::SETEQ);
 
-      And1 = DAG.getNode(ISD::AND, OType, And1,
-                         DAG.getSetCC(OType, Sum, Zero, ISD::SETLT));
+      SDValue SumSign = DAG.getSetCC(OType, Sum, Zero, ISD::SETGE);
+      SDValue SumSignNE = DAG.getSetCC(OType, LHSSign, SumSign, ISD::SETNE);
 
-      SDValue LHSNeg = DAG.getSetCC(OType, LHS, Zero, ISD::SETLT);
-      SDValue RHSNeg = DAG.getSetCC(OType, RHS, Zero, ISD::SETLT);
-      SDValue And2 = DAG.getNode(ISD::AND, OType, LHSNeg, RHSNeg);
-
-      And2 = DAG.getNode(ISD::AND, OType, And2,
-                         DAG.getSetCC(OType, Sum, Zero, ISD::SETGE));
-
-      SDValue Cmp = DAG.getNode(ISD::OR, OType, And1, And2);
+      SDValue Cmp = DAG.getNode(ISD::AND, OType, SignsEq, SumSignNE);
 
       MVT ValueVTs[] = { LHS.getValueType(), OType };
       SDValue Ops[] = { Sum, Cmp };





More information about the llvm-commits mailing list