1*cee313d2SEric Christopher; Loop Simplify should turn phi nodes like X = phi [X, Y]  into just Y, eliminating them.
2*cee313d2SEric Christopher; RUN: opt < %s -loop-simplify -S | grep phi | count 6
3*cee313d2SEric Christopher
4*cee313d2SEric Christopher@A = weak global [3000000 x i32] zeroinitializer		; <[3000000 x i32]*> [#uses=1]
5*cee313d2SEric Christopher@B = weak global [20000 x i32] zeroinitializer		; <[20000 x i32]*> [#uses=1]
6*cee313d2SEric Christopher@C = weak global [100 x i32] zeroinitializer		; <[100 x i32]*> [#uses=1]
7*cee313d2SEric Christopher@Z = weak global i32 0		; <i32*> [#uses=2]
8*cee313d2SEric Christopher
9*cee313d2SEric Christopherdefine i32 @main() {
10*cee313d2SEric Christopherentry:
11*cee313d2SEric Christopher	tail call void @__main( )
12*cee313d2SEric Christopher	br label %loopentry.1
13*cee313d2SEric Christopherloopentry.1:		; preds = %loopexit.1, %entry
14*cee313d2SEric Christopher	%indvar20 = phi i32 [ 0, %entry ], [ %indvar.next21, %loopexit.1 ]		; <i32> [#uses=1]
15*cee313d2SEric Christopher	%a.1 = phi i32* [ getelementptr ([3000000 x i32], [3000000 x i32]* @A, i32 0, i32 0), %entry ], [ %inc.0, %loopexit.1 ]		; <i32*> [#uses=1]
16*cee313d2SEric Christopher	br label %no_exit.2
17*cee313d2SEric Christopherno_exit.2:		; preds = %loopexit.2, %no_exit.2, %loopentry.1
18*cee313d2SEric Christopher	%a.0.4.ph = phi i32* [ %a.1, %loopentry.1 ], [ %inc.0, %loopexit.2 ], [ %a.0.4.ph, %no_exit.2 ]		; <i32*> [#uses=3]
19*cee313d2SEric Christopher	%b.1.4.ph = phi i32* [ getelementptr ([20000 x i32], [20000 x i32]* @B, i32 0, i32 0), %loopentry.1 ], [ %inc.1, %loopexit.2 ], [ %b.1.4.ph, %no_exit.2 ]		; <i32*> [#uses=3]
20*cee313d2SEric Christopher	%indvar17 = phi i32 [ 0, %loopentry.1 ], [ %indvar.next18, %loopexit.2 ], [ %indvar17, %no_exit.2 ]		; <i32> [#uses=2]
21*cee313d2SEric Christopher	%indvar = phi i32 [ %indvar.next, %no_exit.2 ], [ 0, %loopexit.2 ], [ 0, %loopentry.1 ]		; <i32> [#uses=5]
22*cee313d2SEric Christopher	%b.1.4.rec = bitcast i32 %indvar to i32		; <i32> [#uses=1]
23*cee313d2SEric Christopher	%gep.upgrd.1 = zext i32 %indvar to i64		; <i64> [#uses=1]
24*cee313d2SEric Christopher	%c.2.4 = getelementptr [100 x i32], [100 x i32]* @C, i32 0, i64 %gep.upgrd.1		; <i32*> [#uses=1]
25*cee313d2SEric Christopher	%gep.upgrd.2 = zext i32 %indvar to i64		; <i64> [#uses=1]
26*cee313d2SEric Christopher	%a.0.4 = getelementptr i32, i32* %a.0.4.ph, i64 %gep.upgrd.2		; <i32*> [#uses=1]
27*cee313d2SEric Christopher	%gep.upgrd.3 = zext i32 %indvar to i64		; <i64> [#uses=1]
28*cee313d2SEric Christopher	%b.1.4 = getelementptr i32, i32* %b.1.4.ph, i64 %gep.upgrd.3		; <i32*> [#uses=1]
29*cee313d2SEric Christopher	%inc.0.rec = add i32 %b.1.4.rec, 1		; <i32> [#uses=2]
30*cee313d2SEric Christopher	%inc.0 = getelementptr i32, i32* %a.0.4.ph, i32 %inc.0.rec		; <i32*> [#uses=2]
31*cee313d2SEric Christopher	%tmp.13 = load i32, i32* %a.0.4		; <i32> [#uses=1]
32*cee313d2SEric Christopher	%inc.1 = getelementptr i32, i32* %b.1.4.ph, i32 %inc.0.rec		; <i32*> [#uses=1]
33*cee313d2SEric Christopher	%tmp.15 = load i32, i32* %b.1.4		; <i32> [#uses=1]
34*cee313d2SEric Christopher	%tmp.18 = load i32, i32* %c.2.4		; <i32> [#uses=1]
35*cee313d2SEric Christopher	%tmp.16 = mul i32 %tmp.15, %tmp.13		; <i32> [#uses=1]
36*cee313d2SEric Christopher	%tmp.19 = mul i32 %tmp.16, %tmp.18		; <i32> [#uses=1]
37*cee313d2SEric Christopher	%tmp.20 = load i32, i32* @Z		; <i32> [#uses=1]
38*cee313d2SEric Christopher	%tmp.21 = add i32 %tmp.19, %tmp.20		; <i32> [#uses=1]
39*cee313d2SEric Christopher	store i32 %tmp.21, i32* @Z
40*cee313d2SEric Christopher	%indvar.next = add i32 %indvar, 1		; <i32> [#uses=2]
41*cee313d2SEric Christopher	%exitcond = icmp eq i32 %indvar.next, 100		; <i1> [#uses=1]
42*cee313d2SEric Christopher	br i1 %exitcond, label %loopexit.2, label %no_exit.2
43*cee313d2SEric Christopherloopexit.2:		; preds = %no_exit.2
44*cee313d2SEric Christopher	%indvar.next18 = add i32 %indvar17, 1		; <i32> [#uses=2]
45*cee313d2SEric Christopher	%exitcond19 = icmp eq i32 %indvar.next18, 200		; <i1> [#uses=1]
46*cee313d2SEric Christopher	br i1 %exitcond19, label %loopexit.1, label %no_exit.2
47*cee313d2SEric Christopherloopexit.1:		; preds = %loopexit.2
48*cee313d2SEric Christopher	%indvar.next21 = add i32 %indvar20, 1		; <i32> [#uses=2]
49*cee313d2SEric Christopher	%exitcond22 = icmp eq i32 %indvar.next21, 300		; <i1> [#uses=1]
50*cee313d2SEric Christopher	br i1 %exitcond22, label %return, label %loopentry.1
51*cee313d2SEric Christopherreturn:		; preds = %loopexit.1
52*cee313d2SEric Christopher	ret i32 undef
53*cee313d2SEric Christopher}
54*cee313d2SEric Christopher
55*cee313d2SEric Christopherdeclare void @__main()
56