From 6328488e882bb8b08c952aed01d05290a8fb602e Mon Sep 17 00:00:00 2001 From: Sanjay Patel Date: Wed, 6 Mar 2019 14:34:59 +0000 Subject: [PATCH] [TargetLowering] simplify code for uaddsat/usubsat expansion; NFC git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@355508 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/CodeGen/SelectionDAG/TargetLowering.cpp | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/lib/CodeGen/SelectionDAG/TargetLowering.cpp b/lib/CodeGen/SelectionDAG/TargetLowering.cpp index a1112b7de5f..f9d02af8959 100644 --- a/lib/CodeGen/SelectionDAG/TargetLowering.cpp +++ b/lib/CodeGen/SelectionDAG/TargetLowering.cpp @@ -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 -- 2.50.1