summaryrefslogtreecommitdiffstats
path: root/llvm/test/Transforms/IndVarSimplify
diff options
context:
space:
mode:
authorMax Kazantsev <max.kazantsev@azul.com>2017-07-05 06:38:49 +0000
committerMax Kazantsev <max.kazantsev@azul.com>2017-07-05 06:38:49 +0000
commit80bc4a5554226f1f4a14ea204acf1ae2cac6bbb2 (patch)
tree0a2dd4fcd34b51ad257a95481fbf09f4fd698fa8 /llvm/test/Transforms/IndVarSimplify
parent9d5571a2269277af458ca7c93e5afc019d09695c (diff)
downloadbcm5719-llvm-80bc4a5554226f1f4a14ea204acf1ae2cac6bbb2.tar.gz
bcm5719-llvm-80bc4a5554226f1f4a14ea204acf1ae2cac6bbb2.zip
[IndVars] Canonicalize comparisons between non-negative values and indvars
-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
Diffstat (limited to 'llvm/test/Transforms/IndVarSimplify')
-rw-r--r--llvm/test/Transforms/IndVarSimplify/canonicalize-cmp.ll52
-rw-r--r--llvm/test/Transforms/IndVarSimplify/eliminate-comparison.ll4
-rw-r--r--llvm/test/Transforms/IndVarSimplify/widen-loop-comp.ll2
3 files changed, 55 insertions, 3 deletions
diff --git a/llvm/test/Transforms/IndVarSimplify/canonicalize-cmp.ll b/llvm/test/Transforms/IndVarSimplify/canonicalize-cmp.ll
new file mode 100644
index 00000000000..93dc968af6a
--- /dev/null
+++ b/llvm/test/Transforms/IndVarSimplify/canonicalize-cmp.ll
@@ -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
+}
diff --git a/llvm/test/Transforms/IndVarSimplify/eliminate-comparison.ll b/llvm/test/Transforms/IndVarSimplify/eliminate-comparison.ll
index 612f01e3cad..a63617e62c0 100644
--- a/llvm/test/Transforms/IndVarSimplify/eliminate-comparison.ll
+++ b/llvm/test/Transforms/IndVarSimplify/eliminate-comparison.ll
@@ -111,7 +111,7 @@ return:
; Indvars should not turn the second loop into an infinite one.
; CHECK-LABEL: @func_11(
-; CHECK: %tmp5 = icmp slt i32 %__key6.0, 10
+; CHECK: %tmp5 = icmp ult i32 %__key6.0, 10
; CHECK-NOT: br i1 true, label %noassert68, label %unrolledend
define i32 @func_11() nounwind uwtable {
@@ -163,7 +163,7 @@ declare void @llvm.trap() noreturn nounwind
; In this case the second loop only has a single iteration, fold the header away
; CHECK-LABEL: @func_12(
-; CHECK: %tmp5 = icmp slt i32 %__key6.0, 10
+; CHECK: %tmp5 = icmp ult i32 %__key6.0, 10
; CHECK: br i1 true, label %noassert68, label %unrolledend
define i32 @func_12() nounwind uwtable {
entry:
diff --git a/llvm/test/Transforms/IndVarSimplify/widen-loop-comp.ll b/llvm/test/Transforms/IndVarSimplify/widen-loop-comp.ll
index b87cd055019..2d24cd732ce 100644
--- a/llvm/test/Transforms/IndVarSimplify/widen-loop-comp.ll
+++ b/llvm/test/Transforms/IndVarSimplify/widen-loop-comp.ll
@@ -64,7 +64,7 @@ for.end:
; CHECK-LABEL: @test2
; CHECK: for.body4.us
; CHECK: %indvars.iv.next = add nuw nsw i64 %indvars.iv, 1
-; CHECK: %cmp2.us = icmp slt i64
+; CHECK: %cmp2.us = icmp ult i64
; CHECK-NOT: %2 = trunc i64 %indvars.iv.next to i32
; CHECK-NOT: %cmp2.us = icmp slt i32
OpenPOWER on IntegriCloud