[llvm] r355508 - [TargetLowering] simplify code for uaddsat/usubsat expansion; NFC
Sanjay Patel via llvm-commits
llvm-commits at lists.llvm.org
Wed Mar 6 06:34:59 PST 2019
Author: spatel
Date: Wed Mar 6 06:34:59 2019
New Revision: 355508
URL: http://llvm.org/viewvc/llvm-project?rev=355508&view=rev
Log:
[TargetLowering] simplify code for uaddsat/usubsat expansion; NFC
Modified:
llvm/trunk/lib/CodeGen/SelectionDAG/TargetLowering.cpp
Modified: llvm/trunk/lib/CodeGen/SelectionDAG/TargetLowering.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/SelectionDAG/TargetLowering.cpp?rev=355508&r1=355507&r2=355508&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/SelectionDAG/TargetLowering.cpp (original)
+++ llvm/trunk/lib/CodeGen/SelectionDAG/TargetLowering.cpp Wed Mar 6 06:34:59 2019
@@ -5438,17 +5438,14 @@ SDValue TargetLowering::expandAddSubSat(
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
More information about the llvm-commits
mailing list