[llvm] 029e83b - [DAG] getNode - don't bother creating ADDO(X,0) or SUBO(X,0) nodes.

Simon Pilgrim via llvm-commits llvm-commits at lists.llvm.org
Wed Jul 20 04:04:51 PDT 2022


Author: Simon Pilgrim
Date: 2022-07-20T12:04:33+01:00
New Revision: 029e83b401564db2562f0dc68c55563806570872

URL: https://github.com/llvm/llvm-project/commit/029e83b401564db2562f0dc68c55563806570872
DIFF: https://github.com/llvm/llvm-project/commit/029e83b401564db2562f0dc68c55563806570872.diff

LOG: [DAG] getNode - don't bother creating ADDO(X,0) or SUBO(X,0) nodes.

Similar to what we already do in getNode for basic ADD/SUB nodes, return the X operand directly, but here we know that there will be no/zero overflow as well.

As noted on D127115 - this path is being exercised by llvm/test/CodeGen/ARM/dsp-mlal.ll, although I haven't been able to get any codegen without a topological worklist.

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
index fe82a8291fbd..6ac7972d8e5a 100644
--- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAG.cpp
@@ -9040,14 +9040,25 @@ SDValue SelectionDAG::getNode(unsigned Opcode, const SDLoc &DL, SDVTList VTList,
   case ISD::SADDO:
   case ISD::UADDO:
   case ISD::SSUBO:
-  case ISD::USUBO:
+  case ISD::USUBO: {
     assert(VTList.NumVTs == 2 && Ops.size() == 2 &&
            "Invalid add/sub overflow op!");
     assert(VTList.VTs[0].isInteger() && VTList.VTs[1].isInteger() &&
            Ops[0].getValueType() == Ops[1].getValueType() &&
            Ops[0].getValueType() == VTList.VTs[0] &&
            "Binary operator types must match!");
+    SDValue N1 = Ops[0], N2 = Ops[1];
+    canonicalizeCommutativeBinop(Opcode, N1, N2);
+
+    // (X +- 0) -> X with zero-overflow.
+    ConstantSDNode *N2CV = isConstOrConstSplat(N2, /*AllowUndefs*/ false,
+                                               /*AllowTruncation*/ true);
+    if (N2CV && N2CV->isZero()) {
+      SDValue ZeroOverFlow = getConstant(0, DL, VTList.VTs[1]);
+      return getNode(ISD::MERGE_VALUES, DL, VTList, {N1, ZeroOverFlow}, Flags);
+    }
     break;
+  }
   case ISD::STRICT_FP_EXTEND:
     assert(VTList.NumVTs == 2 && Ops.size() == 2 &&
            "Invalid STRICT_FP_EXTEND!");


        


More information about the llvm-commits mailing list