[InstCombine] Use m_c_Add to shorten some code. Add testcases for this fold since...
authorCraig Topper <craig.topper@gmail.com>
Mon, 10 Apr 2017 16:59:40 +0000 (16:59 +0000)
committerCraig Topper <craig.topper@gmail.com>
Mon, 10 Apr 2017 16:59:40 +0000 (16:59 +0000)
llvm-svn: 299853

llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
llvm/test/Transforms/InstCombine/sub.ll

index 65f72d0..f66726e 100644 (file)
@@ -1623,8 +1623,7 @@ Instruction *InstCombiner::visitSub(BinaryOperator &I) {
   {
     Value *Y;
     // X-(X+Y) == -Y    X-(Y+X) == -Y
-    if (match(Op1, m_Add(m_Specific(Op0), m_Value(Y))) ||
-        match(Op1, m_Add(m_Value(Y), m_Specific(Op0))))
+    if (match(Op1, m_c_Add(m_Specific(Op0), m_Value(Y))))
       return BinaryOperator::CreateNeg(Y);
 
     // (X-Y)-X == -Y
index 8e5844d..ac38e5e 100644 (file)
@@ -851,3 +851,21 @@ final:
   %value = sub <2 x i32> <i32 123, i32 333>, %A
   ret <2 x i32> %value
 }
+
+define i32 @test56(i32 %A, i32 %B) {
+; CHECK-LABEL: @test56(
+; CHECK-NEXT:    [[Y:%.*]] = sub i32 0, [[B:%.*]]
+; CHECK-NEXT:    ret i32 [[Y]]
+;
+  %X = add i32 %A, %B
+  %Y = sub i32 %A, %X
+  ret i32 %Y                                                                                                                                                                                                                                             }
+
+define i32 @test57(i32 %A, i32 %B) {
+; CHECK-LABEL: @test57(
+; CHECK-NEXT:    [[Y:%.*]] = sub i32 0, [[B:%.*]]
+; CHECK-NEXT:    ret i32 [[Y]]
+;
+  %X = add i32 %B, %A
+  %Y = sub i32 %A, %X
+  ret i32 %Y                                                                                                                                                                                                                                             }