1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2025-02-01 05:01:59 +01:00

[InstCombine] Use m_c_Add to shorten some code. Add testcases for this fold since they were missing. NFC

llvm-svn: 299853
This commit is contained in:
Craig Topper 2017-04-10 16:59:40 +00:00
parent 786bd13a82
commit bd8800adbc
2 changed files with 19 additions and 2 deletions

View 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

View 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 }