summaryrefslogtreecommitdiffstats
path: root/llvm/test/Transforms/IndVarSimplify
diff options
context:
space:
mode:
authorHongbin Zheng <etherzhhb@gmail.com>2017-09-27 03:11:46 +0000
committerHongbin Zheng <etherzhhb@gmail.com>2017-09-27 03:11:46 +0000
commitd1b7b2efba67fcedcc803b2bf7dda808b9a5c401 (patch)
tree97ce25fd46f47439ddec103a08336485ddfcc350 /llvm/test/Transforms/IndVarSimplify
parent1d23cb4e7e8dbdff6fd5d8b365b14964254ca243 (diff)
downloadbcm5719-llvm-d1b7b2efba67fcedcc803b2bf7dda808b9a5c401.tar.gz
bcm5719-llvm-d1b7b2efba67fcedcc803b2bf7dda808b9a5c401.zip
[SimplifyIndVar] Constant fold IV users
This patch tries to transform cases like: for (unsigned i = 0; i < N; i += 2) { bool c0 = (i & 0x1) == 0; bool c1 = ((i + 1) & 0x1) == 1; } To for (unsigned i = 0; i < N; i += 2) { bool c0 = true; bool c1 = true; } This commit also update test/Transforms/IndVarSimplify/replace-srem-by-urem.ll to prevent constant folding. Differential Revision: https://reviews.llvm.org/D38272 llvm-svn: 314266
Diffstat (limited to 'llvm/test/Transforms/IndVarSimplify')
-rw-r--r--llvm/test/Transforms/IndVarSimplify/constant-fold.ll47
-rw-r--r--llvm/test/Transforms/IndVarSimplify/replace-srem-by-urem.ll2
2 files changed, 48 insertions, 1 deletions
diff --git a/llvm/test/Transforms/IndVarSimplify/constant-fold.ll b/llvm/test/Transforms/IndVarSimplify/constant-fold.ll
new file mode 100644
index 00000000000..a35349aa1f5
--- /dev/null
+++ b/llvm/test/Transforms/IndVarSimplify/constant-fold.ll
@@ -0,0 +1,47 @@
+; RUN: opt -indvars -S < %s | FileCheck %s
+
+define void @test0(i32* %x) {
+entry:
+ br label %for.inc
+
+for.inc: ; preds = %for.inc, %entry
+ %i.01 = phi i32 [ 0, %entry ], [ %add, %for.inc ]
+ %and = and i32 %i.01, 3
+ %cmp1 = icmp eq i32 %and, 0
+ %cond = select i1 %cmp1, i32 0, i32 1
+ store i32 %cond, i32* %x, align 4
+ %add = add i32 %i.01, 4
+ %cmp = icmp ult i32 %add, 8
+ br i1 %cmp, label %for.inc, label %for.end
+
+for.end: ; preds = %for.inc
+ ret void
+}
+
+; Should fold the condition of the select into constant
+; CHECK-LABEL: void @test
+; CHECK: icmp eq i32 0, 0
+
+define void @test1(i32* %a) {
+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
+ %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
+}
+
+; Should fold the rem since %mul is multiple of 8
+; CHECK-LABEL: @test1(
+; CHECK-NOT: rem
+; CHECK: sext i32 0 to i64
diff --git a/llvm/test/Transforms/IndVarSimplify/replace-srem-by-urem.ll b/llvm/test/Transforms/IndVarSimplify/replace-srem-by-urem.ll
index 6629420df55..ec1ccffbc5c 100644
--- a/llvm/test/Transforms/IndVarSimplify/replace-srem-by-urem.ll
+++ b/llvm/test/Transforms/IndVarSimplify/replace-srem-by-urem.ll
@@ -71,7 +71,7 @@ entry:
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
+ %rem = srem i32 %mul, 7
; CHECK: urem
; CHECK-NOT: srem
%idxprom = sext i32 %rem to i64
OpenPOWER on IntegriCloud