For completeness, generalize the (X + Y) - Y -> X transform and add X - (X + 1) -> -1.

These were not recommended by my auto-simplifier since they don't fire often enough.
However they do fire from time to time, for example they remove one subtraction from
the final bitcode for 483.xalancbmk.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@123755 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Duncan Sands
2011-01-18 11:50:19 +00:00
parent fe02c69f84
commit b2f3c383ec
2 changed files with 77 additions and 15 deletions
@@ -70,3 +70,23 @@ define i32 @sub1(i32 %x, i32 %y) {
ret i32 %r
; CHECK: ret i32 %y
}
define i32 @sub2(i32 %x) {
; CHECK: @sub2
; X - (X + 1) -> -1
%xp1 = add i32 %x, 1
%r = sub i32 %x, %xp1
ret i32 %r
; CHECK: ret i32 -1
}
define i32 @sub3(i32 %x, i32 %y) {
; CHECK: @sub3
; ((X + 1) + Y) - (Y + 1) -> X
%xp1 = add i32 %x, 1
%lhs = add i32 %xp1, %y
%rhs = add i32 %y, 1
%r = sub i32 %lhs, %rhs
ret i32 %r
; CHECK: ret i32 %x
}