summaryrefslogtreecommitdiffstats
path: root/llvm/test
diff options
context:
space:
mode:
authorHongbin Zheng <etherzhhb@gmail.com>2017-09-25 17:39:40 +0000
committerHongbin Zheng <etherzhhb@gmail.com>2017-09-25 17:39:40 +0000
commitf0093e45c4fb5a765ddf94367ddd675f3efb6bc3 (patch)
treeb3f22ef8a7ccfbec412b150d018f9c0a327e3042 /llvm/test
parent310389691408b89a89c197ad7cdc98494b22e2b4 (diff)
downloadbcm5719-llvm-f0093e45c4fb5a765ddf94367ddd675f3efb6bc3.tar.gz
bcm5719-llvm-f0093e45c4fb5a765ddf94367ddd675f3efb6bc3.zip
[SimplifyIndvar] Replace the srem used by IV if we can prove both of its operands are non-negative
Since now SCEV can handle 'urem', an 'urem' is a better canonical form than an 'srem' because it has well-defined behavior This is a follow up of D34598 Differential Revision: https://reviews.llvm.org/D38072 llvm-svn: 314125
Diffstat (limited to 'llvm/test')
-rw-r--r--llvm/test/Transforms/IndVarSimplify/eliminate-rem.ll6
-rw-r--r--llvm/test/Transforms/IndVarSimplify/replace-srem-by-urem.ll109
2 files changed, 112 insertions, 3 deletions
diff --git a/llvm/test/Transforms/IndVarSimplify/eliminate-rem.ll b/llvm/test/Transforms/IndVarSimplify/eliminate-rem.ll
index 6f8e6bbac77..8c1ea81263f 100644
--- a/llvm/test/Transforms/IndVarSimplify/eliminate-rem.ll
+++ b/llvm/test/Transforms/IndVarSimplify/eliminate-rem.ll
@@ -33,9 +33,9 @@ bb12: ; preds = %bb11, %bb
; Indvars should be able to eliminate the (i+1)%n.
; CHECK-LABEL: @f(
-; CHECK-NOT: rem
-; CHECK: rem
-; CHECK-NOT: rem
+; CHECK-NOT: {{[us]}}rem
+; CHECK: {{[us]}}rem
+; CHECK-NOT: {{[us]}}rem
; CHECK: ret
define i32 @f(i64* %arg, i64 %arg1, i64 %arg2, i64 %arg3) nounwind {
diff --git a/llvm/test/Transforms/IndVarSimplify/replace-srem-by-urem.ll b/llvm/test/Transforms/IndVarSimplify/replace-srem-by-urem.ll
new file mode 100644
index 00000000000..6629420df55
--- /dev/null
+++ b/llvm/test/Transforms/IndVarSimplify/replace-srem-by-urem.ll
@@ -0,0 +1,109 @@
+; RUN: opt < %s -indvars -S | FileCheck %s
+
+define void @test0(i32* %a) {
+; CHECK-LABEL: @test0(
+entry:
+ br label %for.body
+
+for.body: ; preds = %entry, %for.body
+ %i.01 = phi i32 [ 0, %entry ], [ %inc, %for.body ]
+ %rem = srem i32 %i.01, 2
+; CHECK-NOT: srem
+; CHECK: urem
+ %idxprom = sext i32 %rem to i64
+ %arrayidx = getelementptr inbounds i32, i32* %a, i64 %idxprom
+ store i32 %i.01, i32* %arrayidx, align 4
+ %inc = add nsw i32 %i.01, 1
+ %cmp = icmp slt i32 %inc, 64
+ br i1 %cmp, label %for.body, label %for.end
+
+for.end: ; preds = %for.body
+ ret void
+}
+
+define void @test2(i32* %a, i32 %d) {
+; CHECK-LABEL: @test2(
+entry:
+ br label %for.body
+
+for.body: ; preds = %entry, %for.body
+ %i.01 = phi i32 [ 0, %entry ], [ %inc, %for.body ]
+ %mul = mul nsw i32 %i.01, 64
+ %rem = srem i32 %mul, %d
+; CHECK-NOT: urem
+ %idxprom = sext i32 %rem to i64
+ %arrayidx = getelementptr inbounds i32, i32* %a, i64 %idxprom
+ store i32 %i.01, i32* %arrayidx, align 4
+ %inc = add nsw i32 %i.01, 1
+ %cmp = icmp slt i32 %inc, 64
+ br i1 %cmp, label %for.body, label %for.end
+
+for.end: ; preds = %for.body
+ ret void
+}
+
+define void @test3(i32* %a) {
+; CHECK-LABEL: @test3(
+entry:
+ br label %for.body
+
+for.body: ; preds = %entry, %for.body
+ %i.01 = phi i32 [ 0, %entry ], [ %inc, %for.body ]
+ %rem = srem i32 2048, %i.01
+; CHECK: urem
+; CHECK-NOT: srem
+ %idxprom = sext i32 %rem to i64
+ %arrayidx = getelementptr inbounds i32, i32* %a, i64 %idxprom
+ store i32 %i.01, i32* %arrayidx, align 4
+ %inc = add nsw i32 %i.01, 1
+ %cmp = icmp slt i32 %inc, 64
+ br i1 %cmp, label %for.body, label %for.end
+
+for.end: ; preds = %for.body
+ ret void
+}
+
+define void @test4(i32* %a) {
+; CHECK-LABEL: @test4(
+entry:
+ br label %for.body
+
+for.body: ; preds = %entry, %for.body
+ %i.01 = phi i32 [ 0, %entry ], [ %inc, %for.body ]
+ %mul = mul nsw i32 %i.01, 64
+ %rem = srem i32 %mul, 8
+; CHECK: urem
+; CHECK-NOT: srem
+ %idxprom = sext i32 %rem to i64
+ %arrayidx = getelementptr inbounds i32, i32* %a, i64 %idxprom
+ store i32 %i.01, i32* %arrayidx, align 4
+ %inc = add nsw i32 %i.01, 1
+ %cmp = icmp slt i32 %inc, 64
+ br i1 %cmp, label %for.body, label %for.end
+
+for.end: ; preds = %for.body
+ ret void
+}
+
+define void @test5(i32* %a) {
+; CHECK-LABEL: @test5(
+entry:
+ br label %for.body
+
+for.body: ; preds = %entry, %for.body
+ %i.01 = phi i32 [ 0, %entry ], [ %inc, %for.body ]
+ %mul = mul nsw i32 %i.01, 64
+ %rem = srem i32 %mul, 6
+; CHECK: urem
+; CHECK-NOT: srem
+ %idxprom = sext i32 %rem to i64
+ %arrayidx = getelementptr inbounds i32, i32* %a, i64 %idxprom
+ store i32 %i.01, i32* %arrayidx, align 4
+ %inc = add nsw i32 %i.01, 1
+ %cmp = icmp slt i32 %inc, 64
+ br i1 %cmp, label %for.body, label %for.end
+
+for.end: ; preds = %for.body
+ ret void
+}
+
OpenPOWER on IntegriCloud