-
Notifications
You must be signed in to change notification settings - Fork 11.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[IndVars] Canonicalize comparisons between non-negative values and in…
…dvars -If there is a IndVar which is known to be non-negative, and there is a value which is also non-negative, then signed and unsigned comparisons between them produce the same result. Both of those can be seen in the same loop. To allow other optimizations to simplify them, we turn all instructions like %c = icmp slt i32 %iv, %b to %c = icmp ult i32 %iv, %b if both %iv and %b are known to be non-negative. Differential Revision: https://reviews.llvm.org/D34979 llvm-svn: 307126
- Loading branch information
Max Kazantsev
committed
Jul 5, 2017
1 parent
9d5571a
commit 80bc4a5
Showing
5 changed files
with
62 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
; RUN: opt -S -indvars < %s | FileCheck %s | ||
|
||
; Check that we replace signed comparisons between non-negative values with | ||
; unsigned comparisons if we can. | ||
|
||
target datalayout = "n8:16:32:64" | ||
|
||
define i32 @test_01(i32 %a, i32 %b, i32* %p) { | ||
|
||
; CHECK-LABEL: @test_01( | ||
; CHECK-NOT: icmp slt | ||
; CHECK: %cmp1 = icmp ult i32 %iv, 100 | ||
; CHECK: %cmp2 = icmp ult i32 %iv, 100 | ||
; CHECK-NOT: %cmp3 | ||
; CHECK: %exitcond = icmp ne i32 %iv.next, 1000 | ||
|
||
entry: | ||
br label %loop.entry | ||
|
||
loop.entry: | ||
%iv = phi i32 [ 0, %entry ], [ %iv.next, %loop.be ] | ||
%cmp1 = icmp slt i32 %iv, 100 | ||
br i1 %cmp1, label %b1, label %b2 | ||
|
||
b1: | ||
store i32 %iv, i32* %p | ||
br label %merge | ||
|
||
b2: | ||
store i32 %a, i32* %p | ||
br label %merge | ||
|
||
merge: | ||
%cmp2 = icmp ult i32 %iv, 100 | ||
br i1 %cmp2, label %b3, label %b4 | ||
|
||
b3: | ||
store i32 %iv, i32* %p | ||
br label %loop.be | ||
|
||
b4: | ||
store i32 %b, i32* %p | ||
br label %loop.be | ||
|
||
loop.be: | ||
%iv.next = add i32 %iv, 1 | ||
%cmp3 = icmp slt i32 %iv.next, 1000 | ||
br i1 %cmp3, label %loop.entry, label %exit | ||
|
||
exit: | ||
ret i32 %iv | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters