From 89e534746fc8b9ac4103d1d337a60871503e95be 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 llvm-svn: 355508 --- llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp b/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp index a1112b7de5f9..f9d02af89597 100644 --- a/llvm/lib/CodeGen/SelectionDAG/TargetLowering.cpp +++ b/llvm/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