summaryrefslogtreecommitdiff
path: root/test/Transforms/IndVarSimplify
diff options
context:
space:
mode:
authorDimitry Andric <dim@FreeBSD.org>2011-07-17 15:36:56 +0000
committerDimitry Andric <dim@FreeBSD.org>2011-07-17 15:36:56 +0000
commit411bd29eea3c360d5b48a18a17b5e87f5671af0e (patch)
treec8086addb211fa670a9d2b1038d8c2e453229755 /test/Transforms/IndVarSimplify
parent56fe8f14099930935e3870e3e823c322a85c1c89 (diff)
Notes
Diffstat (limited to 'test/Transforms/IndVarSimplify')
-rw-r--r--test/Transforms/IndVarSimplify/2008-09-02-IVType.ll2
-rw-r--r--test/Transforms/IndVarSimplify/ada-loops.ll18
-rw-r--r--test/Transforms/IndVarSimplify/iv-zext.ll1
-rw-r--r--test/Transforms/IndVarSimplify/no-iv-rewrite.ll199
-rw-r--r--test/Transforms/IndVarSimplify/preserve-signed-wrap.ll10
-rw-r--r--test/Transforms/IndVarSimplify/variable-stride-ivs-0.ll9
6 files changed, 223 insertions, 16 deletions
diff --git a/test/Transforms/IndVarSimplify/2008-09-02-IVType.ll b/test/Transforms/IndVarSimplify/2008-09-02-IVType.ll
index 288431aa8bcf..a00483164fb1 100644
--- a/test/Transforms/IndVarSimplify/2008-09-02-IVType.ll
+++ b/test/Transforms/IndVarSimplify/2008-09-02-IVType.ll
@@ -16,7 +16,7 @@
%struct.YUVGeneralParams = type { i16*, i8*, i8*, i8*, i8*, i8*, void (i8*, i16**, i32, %struct.YUVGeneralParams*)*, i16, i16, i16, [6 x i8], void (i8*, i16**, i32, %struct.YUVGeneralParams*)*, i16, i16 }
@llvm.used = appending global [1 x i8*] [ i8* bitcast (i16 (%struct.JPEGGlobals*)* @ExtractBufferedBlocksIgnored to i8*) ], section "llvm.metadata" ; <[1 x i8*]*> [#uses=0]
-define i16 @ExtractBufferedBlocksIgnored(%struct.JPEGGlobals* %globp) signext nounwind {
+define signext i16 @ExtractBufferedBlocksIgnored(%struct.JPEGGlobals* %globp) nounwind {
entry:
%tmp4311 = getelementptr %struct.JPEGGlobals* %globp, i32 0, i32 70 ; <i32*> [#uses=1]
%tmp4412 = load i32* %tmp4311, align 16 ; <i32> [#uses=2]
diff --git a/test/Transforms/IndVarSimplify/ada-loops.ll b/test/Transforms/IndVarSimplify/ada-loops.ll
index 4a07d997e7d7..9e635fdc0067 100644
--- a/test/Transforms/IndVarSimplify/ada-loops.ll
+++ b/test/Transforms/IndVarSimplify/ada-loops.ll
@@ -1,14 +1,18 @@
-; RUN: opt < %s -indvars -S > %t
-; RUN: grep phi %t | count 4
-; RUN: grep {= phi i32} %t | count 4
-; RUN: not grep {sext i} %t
-; RUN: not grep {zext i} %t
-; RUN: not grep {trunc i} %t
-; RUN: not grep {add i8} %t
+; RUN: opt < %s -indvars -S | FileCheck %s
+; RUN: opt < %s -indvars -disable-iv-rewrite -S | FileCheck %s
+;
; PR1301
; Do a bunch of analysis and prove that the loops can use an i32 trip
; count without casting.
+;
+; Note that all four functions should actually be converted to
+; memset. However, this test case validates indvars behavior. We
+; don't check that phis are "folded together" because that is a job
+; for loop strength reduction. But indvars must remove sext, zext,
+; trunc, and add i8.
+;
+; CHECK-NOT: {{sext|zext|trunc|add i8}}
; ModuleID = 'ada.bc'
target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-n:8:16:32"
diff --git a/test/Transforms/IndVarSimplify/iv-zext.ll b/test/Transforms/IndVarSimplify/iv-zext.ll
index 00018ec6f176..3a05c893fb49 100644
--- a/test/Transforms/IndVarSimplify/iv-zext.ll
+++ b/test/Transforms/IndVarSimplify/iv-zext.ll
@@ -1,4 +1,5 @@
; RUN: opt < %s -indvars -S | FileCheck %s
+; RUN: opt < %s -indvars -disable-iv-rewrite -S | FileCheck %s
; CHECK-NOT: and
; CHECK-NOT: zext
diff --git a/test/Transforms/IndVarSimplify/no-iv-rewrite.ll b/test/Transforms/IndVarSimplify/no-iv-rewrite.ll
index c35feef26f9b..9605670b86e1 100644
--- a/test/Transforms/IndVarSimplify/no-iv-rewrite.ll
+++ b/test/Transforms/IndVarSimplify/no-iv-rewrite.ll
@@ -23,6 +23,7 @@ ph:
; sext should be eliminated while preserving gep inboundsness.
; CHECK-NOT: sext
; CHECK: getelementptr inbounds
+; CHECK: exit:
loop:
%i.02 = phi i32 [ 0, %ph ], [ %iinc, %loop ]
%s.01 = phi i32 [ 0, %ph ], [ %sinc, %loop ]
@@ -63,6 +64,7 @@ ph:
; CHECK: getelementptr inbounds
; %vall sext should obviously not be eliminated
; CHECK: sext
+; CHECK: exit:
loop:
%i.02 = phi i32 [ 0, %ph ], [ %iinc, %loop ]
%s.01 = phi i64 [ 0, %ph ], [ %sinc, %loop ]
@@ -106,6 +108,7 @@ ph:
; Preserve gep inboundsness, and don't factor it.
; CHECK: getelementptr inbounds i32* %ptriv, i32 1
; CHECK-NOT: add
+; CHECK: exit:
loop:
%ptriv = phi i32* [ %first, %ph ], [ %ptrpost, %loop ]
%ofs = sext i32 %idx to i64
@@ -121,3 +124,199 @@ exit:
return:
ret void
}
+
+%struct = type { i32 }
+
+define void @bitcastiv(i32 %start, i32 %limit, i32 %step, %struct* %base)
+nounwind
+{
+entry:
+ br label %loop
+
+; CHECK: loop:
+;
+; Preserve casts
+; CHECK: phi i32
+; CHECK: bitcast
+; CHECK: getelementptr
+; CHECK: exit:
+loop:
+ %iv = phi i32 [%start, %entry], [%next, %loop]
+ %p = phi %struct* [%base, %entry], [%pinc, %loop]
+ %adr = getelementptr %struct* %p, i32 0, i32 0
+ store i32 3, i32* %adr
+ %pp = bitcast %struct* %p to i32*
+ store i32 4, i32* %pp
+ %pinc = getelementptr %struct* %p, i32 1
+ %next = add i32 %iv, 1
+ %cond = icmp ne i32 %next, %limit
+ br i1 %cond, label %loop, label %exit
+
+exit:
+ ret void
+}
+
+define void @maxvisitor(i32 %limit, i32* %base) nounwind {
+entry:
+ br label %loop
+
+; Test inserting a truncate at a phi use.
+;
+; CHECK: loop:
+; CHECK: phi i64
+; CHECK: trunc
+; CHECK: exit:
+loop:
+ %idx = phi i32 [ 0, %entry ], [ %idx.next, %loop.inc ]
+ %max = phi i32 [ 0, %entry ], [ %max.next, %loop.inc ]
+ %idxprom = sext i32 %idx to i64
+ %adr = getelementptr inbounds i32* %base, i64 %idxprom
+ %val = load i32* %adr
+ %cmp19 = icmp sgt i32 %val, %max
+ br i1 %cmp19, label %if.then, label %if.else
+
+if.then:
+ br label %loop.inc
+
+if.else:
+ br label %loop.inc
+
+loop.inc:
+ %max.next = phi i32 [ %idx, %if.then ], [ %max, %if.else ]
+ %idx.next = add nsw i32 %idx, 1
+ %cmp = icmp slt i32 %idx.next, %limit
+ br i1 %cmp, label %loop, label %exit
+
+exit:
+ ret void
+}
+
+define void @identityphi(i32 %limit) nounwind {
+entry:
+ br label %loop
+
+; Test an edge case of removing an identity phi that directly feeds
+; back to the loop iv.
+;
+; CHECK: loop:
+; CHECK: phi i32
+; CHECK-NOT: phi
+; CHECK: exit:
+loop:
+ %iv = phi i32 [ 0, %entry], [ %iv.next, %control ]
+ br i1 undef, label %if.then, label %control
+
+if.then:
+ br label %control
+
+control:
+ %iv.next = phi i32 [ %iv, %loop ], [ undef, %if.then ]
+ %cmp = icmp slt i32 %iv.next, %limit
+ br i1 %cmp, label %loop, label %exit
+
+exit:
+ ret void
+}
+
+define i64 @cloneOr(i32 %limit, i64* %base) nounwind {
+entry:
+ ; ensure that the loop can't overflow
+ %halfLim = ashr i32 %limit, 2
+ br label %loop
+
+; Test cloning an or, which is not an OverflowBinaryOperator.
+;
+; CHECK: loop:
+; CHECK: phi i64
+; CHECK-NOT: sext
+; CHECK: or i64
+; CHECK: exit:
+loop:
+ %iv = phi i32 [ 0, %entry], [ %iv.next, %loop ]
+ %t1 = sext i32 %iv to i64
+ %adr = getelementptr i64* %base, i64 %t1
+ %val = load i64* %adr
+ %t2 = or i32 %iv, 1
+ %t3 = sext i32 %t2 to i64
+ %iv.next = add i32 %iv, 2
+ %cmp = icmp slt i32 %iv.next, %halfLim
+ br i1 %cmp, label %loop, label %exit
+
+exit:
+ %result = and i64 %val, %t3
+ ret i64 %result
+}
+
+; The i induction variable looks like a wrap-around, but it really is just
+; a simple affine IV. Make sure that indvars simplifies through.
+define i32 @indirectRecurrence() nounwind {
+entry:
+ br label %loop
+
+; ReplaceLoopExitValue should fold the return value to constant 9.
+; CHECK: loop:
+; CHECK: phi i32
+; CHECK: ret i32 9
+loop:
+ %j.0 = phi i32 [ 1, %entry ], [ %j.next, %cond_true ]
+ %i.0 = phi i32 [ 0, %entry ], [ %j.0, %cond_true ]
+ %tmp = icmp ne i32 %j.0, 10
+ br i1 %tmp, label %cond_true, label %return
+
+cond_true:
+ %j.next = add i32 %j.0, 1
+ br label %loop
+
+return:
+ ret i32 %i.0
+}
+
+; Eliminate the congruent phis j, k, and l.
+; Eliminate the redundant IV increments k.next and l.next.
+; Two phis should remain, one starting at %init, and one at %init1.
+; Two increments should remain, one by %step and one by %step1.
+; CHECK: loop:
+; CHECK: phi i32
+; CHECK: phi i32
+; CHECK-NOT: phi
+; CHECK: add i32
+; CHECK: add i32
+; CHECK-NOT: add
+; CHECK: return:
+;
+; Five live-outs should remain.
+; CHECK: lcssa = phi
+; CHECK: lcssa = phi
+; CHECK: lcssa = phi
+; CHECK: lcssa = phi
+; CHECK: lcssa = phi
+; CHECK-NOT: phi
+; CHECK: ret
+define i32 @isomorphic(i32 %init, i32 %step, i32 %lim) nounwind {
+entry:
+ %step1 = add i32 %step, 1
+ %init1 = add i32 %init, %step1
+ %l.0 = sub i32 %init1, %step1
+ br label %loop
+
+loop:
+ %ii = phi i32 [ %init1, %entry ], [ %ii.next, %loop ]
+ %i = phi i32 [ %init, %entry ], [ %ii, %loop ]
+ %j = phi i32 [ %init, %entry ], [ %j.next, %loop ]
+ %k = phi i32 [ %init1, %entry ], [ %k.next, %loop ]
+ %l = phi i32 [ %l.0, %entry ], [ %l.next, %loop ]
+ %ii.next = add i32 %ii, %step1
+ %j.next = add i32 %j, %step1
+ %k.next = add i32 %k, %step1
+ %l.step = add i32 %l, %step
+ %l.next = add i32 %l.step, 1
+ %cmp = icmp ne i32 %ii.next, %lim
+ br i1 %cmp, label %loop, label %return
+
+return:
+ %sum1 = add i32 %i, %j.next
+ %sum2 = add i32 %sum1, %k.next
+ %sum3 = add i32 %sum1, %l.step
+ %sum4 = add i32 %sum1, %l.next
+ ret i32 %sum4
+}
diff --git a/test/Transforms/IndVarSimplify/preserve-signed-wrap.ll b/test/Transforms/IndVarSimplify/preserve-signed-wrap.ll
index 9e46a78ffc76..5063b1745442 100644
--- a/test/Transforms/IndVarSimplify/preserve-signed-wrap.ll
+++ b/test/Transforms/IndVarSimplify/preserve-signed-wrap.ll
@@ -1,7 +1,5 @@
-; RUN: opt < %s -indvars -S > %t
-; RUN: grep sext %t | count 1
-; RUN: grep phi %t | count 1
-; RUN: grep {phi i64} %t
+; RUN: opt < %s -indvars -S | FileCheck %s
+; RUN: opt < %s -indvars -disable-iv-rewrite -S | FileCheck %s
; Indvars should insert a 64-bit induction variable to eliminate the
; sext for the addressing, however it shouldn't eliminate the sext
@@ -15,6 +13,10 @@ entry:
bb.nph: ; preds = %entry
br label %bb
+; CHECK: bb:
+; CHECK: phi i64
+; CHECK: sext i8
+; CHECK-NOT: sext
bb: ; preds = %bb1, %bb.nph
%i.02 = phi i32 [ %5, %bb1 ], [ 0, %bb.nph ] ; <i32> [#uses=2]
%p.01 = phi i8 [ %4, %bb1 ], [ -1, %bb.nph ] ; <i8> [#uses=2]
diff --git a/test/Transforms/IndVarSimplify/variable-stride-ivs-0.ll b/test/Transforms/IndVarSimplify/variable-stride-ivs-0.ll
index 0c8857f85789..ace74ffb8622 100644
--- a/test/Transforms/IndVarSimplify/variable-stride-ivs-0.ll
+++ b/test/Transforms/IndVarSimplify/variable-stride-ivs-0.ll
@@ -1,9 +1,9 @@
-; RUN: opt < %s -indvars -instcombine -S | \
-; RUN: grep {store i32 0}
+; RUN: opt < %s -indvars -instcombine -S | FileCheck %s
+; RUN: opt < %s -indvars -disable-iv-rewrite -instcombine -S | FileCheck %s
+;
; Test that -indvars can reduce variable stride IVs. If it can reduce variable
-; stride iv's, it will make %iv. and %m.0.0 isomorphic to each other without
+; stride iv's, it will make %iv. and %m.0.0 isomorphic to each other without
; cycles, allowing the tmp.21 subtraction to be eliminated.
-; END.
define void @vnum_test8(i32* %data) {
entry:
@@ -20,6 +20,7 @@ no_exit.preheader: ; preds = %entry
%tmp.16 = getelementptr i32* %data, i32 %tmp.9 ; <i32*> [#uses=1]
br label %no_exit
+; CHECK: store i32 0
no_exit: ; preds = %no_exit, %no_exit.preheader
%iv.ui = phi i32 [ 0, %no_exit.preheader ], [ %iv..inc.ui, %no_exit ] ; <i32> [#uses=1]
%iv. = phi i32 [ %tmp.5, %no_exit.preheader ], [ %iv..inc, %no_exit ] ; <i32> [#uses=2]