[PATCH] D33840: [DAGCombine] Do not try to deduplicate commutative operations if both operand are the same.

Amaury SECHET via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Jul 31 12:34:00 PDT 2017


deadalnix updated this revision to Diff 108974.
deadalnix added a comment.

rebase


https://reviews.llvm.org/D33840

Files:
  lib/CodeGen/SelectionDAG/DAGCombiner.cpp


Index: lib/CodeGen/SelectionDAG/DAGCombiner.cpp
===================================================================
--- lib/CodeGen/SelectionDAG/DAGCombiner.cpp
+++ lib/CodeGen/SelectionDAG/DAGCombiner.cpp
@@ -1612,15 +1612,15 @@
     }
   }
 
-  // If N is a commutative binary node, try commuting it to enable more
-  // sdisel CSE.
+  // If N is a commutative binary node, try eliminate it if the commuted
+  // version is already present in the DAG.
   if (!RV.getNode() && TLI.isCommutativeBinOp(N->getOpcode()) &&
       N->getNumValues() == 1) {
     SDValue N0 = N->getOperand(0);
     SDValue N1 = N->getOperand(1);
 
     // Constant operands are canonicalized to RHS.
-    if (isa<ConstantSDNode>(N0) || !isa<ConstantSDNode>(N1)) {
+    if (N0 != N1 && (isa<ConstantSDNode>(N0) || !isa<ConstantSDNode>(N1))) {
       SDValue Ops[] = {N1, N0};
       SDNode *CSENode = DAG.getNodeIfExists(N->getOpcode(), N->getVTList(), Ops,
                                             N->getFlags());


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D33840.108974.patch
Type: text/x-patch
Size: 997 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170731/91d170e9/attachment.bin>


More information about the llvm-commits mailing list