[llvm-commits] [llvm] r124532 - /llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp

Benjamin Kramer benny.kra at googlemail.com
Sat Jan 29 04:34:05 PST 2011


Author: d0k
Date: Sat Jan 29 06:34:05 2011
New Revision: 124532

URL: http://llvm.org/viewvc/llvm-project?rev=124532&view=rev
Log:
Add the missing sub identity "A-(A-B) -> B" to DAGCombine.

This happens e.g. for code like "X - X%10" where we lower the modulo operation
to a series of multiplies and shifts that are then subtracted from X, leading to
this missed optimization.

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

Modified: llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp?rev=124532&r1=124531&r2=124532&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp (original)
+++ llvm/trunk/lib/CodeGen/SelectionDAG/DAGCombiner.cpp Sat Jan 29 06:34:05 2011
@@ -1542,6 +1542,9 @@
   // Canonicalize (sub -1, x) -> ~x, i.e. (xor x, -1)
   if (N0C && N0C->isAllOnesValue())
     return DAG.getNode(ISD::XOR, N->getDebugLoc(), VT, N1, N0);
+  // fold A-(A-B) -> B
+  if (N1.getOpcode() == ISD::SUB && N0 == N1.getOperand(0))
+    return N1.getOperand(1);
   // fold (A+B)-A -> B
   if (N0.getOpcode() == ISD::ADD && N0.getOperand(0) == N1)
     return N0.getOperand(1);





More information about the llvm-commits mailing list