add a trivial fold
authorChris Lattner <sabre@nondot.org>
Mon, 17 Oct 2005 01:07:11 +0000 (01:07 +0000)
committerChris Lattner <sabre@nondot.org>
Mon, 17 Oct 2005 01:07:11 +0000 (01:07 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@23764 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/SelectionDAG/DAGCombiner.cpp

index 5b1d10335cf4499c4930d8f3a18ad1885426561b..69478e3b8460c1804826e9ede43b867e70204369 100644 (file)
@@ -532,6 +532,10 @@ SDOperand DAGCombiner::visitSUB(SDNode *N) {
   ConstantSDNode *N0C = dyn_cast<ConstantSDNode>(N0.Val);
   ConstantSDNode *N1C = dyn_cast<ConstantSDNode>(N1.Val);
   
+  // fold (sub x, x) -> 0
+  if (N0 == N1)
+    return DAG.getConstant(0, N->getValueType(0));
+  
   // fold (sub c1, c2) -> c1-c2
   if (N0C && N1C)
     return DAG.getConstant(N0C->getValue() - N1C->getValue(),