[llvm] 4b04e11 - [DAGCombiner] Sub/SUBSAT - use general SelectionDAG::FoldConstantArithmetic

Simon Pilgrim via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 29 08:57:32 PST 2020


Author: Simon Pilgrim
Date: 2020-01-29T16:57:13Z
New Revision: 4b04e117357553205b9c9a95da7e44f026cd842f

URL: https://github.com/llvm/llvm-project/commit/4b04e117357553205b9c9a95da7e44f026cd842f
DIFF: https://github.com/llvm/llvm-project/commit/4b04e117357553205b9c9a95da7e44f026cd842f.diff

LOG: [DAGCombiner] Sub/SUBSAT - use general SelectionDAG::FoldConstantArithmetic

This handles all the constant splat / opaque testing for us.

Added: 
    

Modified: 
    llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
index fc297253b2fd..792d17719999 100644
--- a/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
@@ -2976,11 +2976,10 @@ SDValue DAGCombiner::visitSUB(SDNode *N) {
   // FIXME: Refactor this and xor and other similar operations together.
   if (N0 == N1)
     return tryFoldToZero(DL, TLI, VT, DAG, LegalOperations);
-  if (DAG.isConstantIntBuildVectorOrConstantInt(N0) &&
-      DAG.isConstantIntBuildVectorOrConstantInt(N1)) {
-    // fold (sub c1, c2) -> c1-c2
-    return DAG.FoldConstantArithmetic(ISD::SUB, DL, VT, {N0, N1});
-  }
+
+  // fold (sub c1, c2) -> c3
+  if (SDValue C = DAG.FoldConstantArithmetic(ISD::SUB, DL, VT, {N0, N1}))
+    return C;
 
   if (SDValue NewSel = foldBinOpIntoSelect(N))
     return NewSel;
@@ -3300,11 +3299,9 @@ SDValue DAGCombiner::visitSUBSAT(SDNode *N) {
   if (N0 == N1)
     return DAG.getConstant(0, DL, VT);
 
-  if (DAG.isConstantIntBuildVectorOrConstantInt(N0) &&
-      DAG.isConstantIntBuildVectorOrConstantInt(N1)) {
-    // fold (sub_sat c1, c2) -> c3
-    return DAG.FoldConstantArithmetic(N->getOpcode(), DL, VT, {N0, N1});
-  }
+  // fold (sub_sat c1, c2) -> c3
+  if (SDValue C = DAG.FoldConstantArithmetic(N->getOpcode(), DL, VT, {N0, N1}))
+    return C;
 
   // fold (sub_sat x, 0) -> x
   if (isNullConstant(N1))


        


More information about the llvm-commits mailing list