blob: ace74ffb8622d143961cb8a33889f1c0f0c2d516 [file] [log] [blame]
Andrew Trick037d1c02011-07-06 20:50:43 +00001; RUN: opt < %s -indvars -instcombine -S | FileCheck %s
2; RUN: opt < %s -indvars -disable-iv-rewrite -instcombine -S | FileCheck %s
3;
Chris Lattnera12489e2005-08-10 01:11:24 +00004; Test that -indvars can reduce variable stride IVs. If it can reduce variable
Andrew Trick037d1c02011-07-06 20:50:43 +00005; stride iv's, it will make %iv. and %m.0.0 isomorphic to each other without
Chris Lattnera12489e2005-08-10 01:11:24 +00006; cycles, allowing the tmp.21 subtraction to be eliminated.
7
Tanya Lattnerec9a35a2008-03-01 09:15:35 +00008define void @vnum_test8(i32* %data) {
Chris Lattnera12489e2005-08-10 01:11:24 +00009entry:
Tanya Lattnerec9a35a2008-03-01 09:15:35 +000010 %tmp.1 = getelementptr i32* %data, i32 3 ; <i32*> [#uses=1]
11 %tmp.2 = load i32* %tmp.1 ; <i32> [#uses=2]
12 %tmp.4 = getelementptr i32* %data, i32 4 ; <i32*> [#uses=1]
13 %tmp.5 = load i32* %tmp.4 ; <i32> [#uses=2]
14 %tmp.8 = getelementptr i32* %data, i32 2 ; <i32*> [#uses=1]
15 %tmp.9 = load i32* %tmp.8 ; <i32> [#uses=3]
16 %tmp.125 = icmp sgt i32 %tmp.2, 0 ; <i1> [#uses=1]
17 br i1 %tmp.125, label %no_exit.preheader, label %return
Chris Lattnera12489e2005-08-10 01:11:24 +000018
19no_exit.preheader: ; preds = %entry
Tanya Lattnerec9a35a2008-03-01 09:15:35 +000020 %tmp.16 = getelementptr i32* %data, i32 %tmp.9 ; <i32*> [#uses=1]
Chris Lattnera12489e2005-08-10 01:11:24 +000021 br label %no_exit
22
Andrew Trick037d1c02011-07-06 20:50:43 +000023; CHECK: store i32 0
Chris Lattnera12489e2005-08-10 01:11:24 +000024no_exit: ; preds = %no_exit, %no_exit.preheader
Tanya Lattnerec9a35a2008-03-01 09:15:35 +000025 %iv.ui = phi i32 [ 0, %no_exit.preheader ], [ %iv..inc.ui, %no_exit ] ; <i32> [#uses=1]
26 %iv. = phi i32 [ %tmp.5, %no_exit.preheader ], [ %iv..inc, %no_exit ] ; <i32> [#uses=2]
27 %m.0.0 = phi i32 [ %tmp.5, %no_exit.preheader ], [ %tmp.24, %no_exit ] ; <i32> [#uses=2]
28 store i32 2, i32* %tmp.16
29 %tmp.21 = sub i32 %m.0.0, %iv. ; <i32> [#uses=1]
30 store i32 %tmp.21, i32* %data
31 %tmp.24 = add i32 %m.0.0, %tmp.9 ; <i32> [#uses=1]
32 %iv..inc = add i32 %tmp.9, %iv. ; <i32> [#uses=1]
33 %iv..inc.ui = add i32 %iv.ui, 1 ; <i32> [#uses=2]
34 %iv..inc1 = bitcast i32 %iv..inc.ui to i32 ; <i32> [#uses=1]
35 %tmp.12 = icmp slt i32 %iv..inc1, %tmp.2 ; <i1> [#uses=1]
36 br i1 %tmp.12, label %no_exit, label %return.loopexit
Chris Lattnera12489e2005-08-10 01:11:24 +000037
38return.loopexit: ; preds = %no_exit
39 br label %return
40
41return: ; preds = %return.loopexit, %entry
42 ret void
43}
44