]> granicus.if.org Git - llvm/commitdiff
[TargetLowering] simplify code for uaddsat/usubsat expansion; NFC
authorSanjay Patel <spatel@rotateright.com>
Wed, 6 Mar 2019 14:34:59 +0000 (14:34 +0000)
committerSanjay Patel <spatel@rotateright.com>
Wed, 6 Mar 2019 14:34:59 +0000 (14:34 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@355508 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/SelectionDAG/TargetLowering.cpp

index a1112b7de5f96bc74bed6cc7f1c83bd3afcdc00d..f9d02af895978e6e95bc8a0567013b63aaec1d53 100644 (file)
@@ -5438,17 +5438,14 @@ SDValue TargetLowering::expandAddSubSat(SDNode *Node, SelectionDAG &DAG) const {
   SDValue SumDiff = Result.getValue(0);
   SDValue Overflow = Result.getValue(1);
   SDValue Zero = DAG.getConstant(0, dl, ResultType);
+  SDValue AllOnes = DAG.getAllOnesConstant(dl, ResultType);
 
   if (Opcode == ISD::UADDSAT) {
-    // Just need to check overflow for SatMax.
-    APInt MaxVal = APInt::getMaxValue(BitWidth);
-    SDValue SatMax = DAG.getConstant(MaxVal, dl, ResultType);
-    return DAG.getSelect(dl, ResultType, Overflow, SatMax, SumDiff);
+    // Overflow ? 0xffff.... : (LHS + RHS)
+    return DAG.getSelect(dl, ResultType, Overflow, AllOnes, SumDiff);
   } else if (Opcode == ISD::USUBSAT) {
-    // Just need to check overflow for SatMin.
-    APInt MinVal = APInt::getMinValue(BitWidth);
-    SDValue SatMin = DAG.getConstant(MinVal, dl, ResultType);
-    return DAG.getSelect(dl, ResultType, Overflow, SatMin, SumDiff);
+    // Overflow ? 0 : (LHS - RHS)
+    return DAG.getSelect(dl, ResultType, Overflow, Zero, SumDiff);
   } else {
     // SatMax -> Overflow && SumDiff < 0
     // SatMin -> Overflow && SumDiff >= 0