enhance x-(-A) -> x+A to preserve NUW/NSW.

Use the presence of NSW/NUW to fold "icmp (x+cst), x" to a constant in
cases where it would otherwise be undefined behavior.

Surprisingly (to me at least), this triggers hundreds of the times in
a few benchmarks: lencode, ldecode, and 466.h264ref seem to *really*
like this.



git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@91812 91177308-0d34-0410-b5e6-96231b3b80d8
This commit is contained in:
Chris Lattner
2009-12-21 04:04:05 +00:00
parent 2799bafb98
commit 3bf6815556
2 changed files with 60 additions and 11 deletions

View File

@@ -69,6 +69,7 @@ entry:
%a = add i32 %x, -1
%b = icmp ult i32 %a, %x
ret i1 %b
; CHECK: @test7
; CHECK: %b = icmp ne i32 %x, 0
; CHECK: ret i1 %b
}
@@ -78,6 +79,7 @@ entry:
%a = add i32 %x, -1
%b = icmp eq i32 %a, %x
ret i1 %b
; CHECK: @test8
; CHECK: ret i1 false
}
@@ -86,6 +88,7 @@ entry:
%a = add i32 %x, -2
%b = icmp ugt i32 %x, %a
ret i1 %b
; CHECK: @test9
; CHECK: icmp ugt i32 %x, 1
; CHECK: ret i1 %b
}
@@ -96,6 +99,16 @@ entry:
%b = icmp slt i32 %a, %x
ret i1 %b
; CHECK: @test10
; CHECK: %b = icmp ne i32 %x, -2147483648
; CHECK: ret i1 %b
}
define i1 @test11(i32 %x) {
%a = add nsw i32 %x, 8
%b = icmp slt i32 %x, %a
ret i1 %b
; CHECK: @test11
; CHECK: ret i1 true
}