1 ; This testcase comes from this C fragment:
3 ; void test(unsigned Num, int *Array) {
6 ; for (i = 0; i != Num; ++i)
7 ; for (j = 0; j != Num; ++j)
8 ; for (k = 0; k != Num; ++k)
9 ; printf("%d\n", i+k+j); /* Reassociate to (i+j)+k */
12 ; In this case, we want to reassociate the specified expr so that i+j can be
13 ; hoisted out of the inner most loop.
15 ; RUN: opt %s -reassociate -S | grep 115 | not grep 117
17 @.LC0 = internal global [4 x i8] c"%d\0A\00" ; <[4 x i8]*> [#uses=1]
19 declare i32 @printf(i8*, ...)
21 define void @test(i32 %Num, i32* %Array) {
23 %cond221 = icmp eq i32 0, %Num ; <i1> [#uses=3]
24 br i1 %cond221, label %bb7, label %bb2
25 bb2: ; preds = %bb6, %bb0
26 %reg115 = phi i32 [ %reg120, %bb6 ], [ 0, %bb0 ] ; <i32> [#uses=2]
27 br i1 %cond221, label %bb6, label %bb3
28 bb3: ; preds = %bb5, %bb2
29 %reg116 = phi i32 [ %reg119, %bb5 ], [ 0, %bb2 ] ; <i32> [#uses=2]
30 br i1 %cond221, label %bb5, label %bb4
31 bb4: ; preds = %bb4, %bb3
32 %reg117 = phi i32 [ %reg118, %bb4 ], [ 0, %bb3 ] ; <i32> [#uses=2]
33 %reg113 = add i32 %reg115, %reg117 ; <i32> [#uses=1]
34 %reg114 = add i32 %reg113, %reg116 ; <i32> [#uses=1]
35 %cast227 = getelementptr [4 x i8]* @.LC0, i64 0, i64 0 ; <i8*> [#uses=1]
36 call i32 (i8*, ...)* @printf( i8* %cast227, i32 %reg114 ) ; <i32>:0 [#uses=0]
37 %reg118 = add i32 %reg117, 1 ; <i32> [#uses=2]
38 %cond224 = icmp ne i32 %reg118, %Num ; <i1> [#uses=1]
39 br i1 %cond224, label %bb4, label %bb5
40 bb5: ; preds = %bb4, %bb3
41 %reg119 = add i32 %reg116, 1 ; <i32> [#uses=2]
42 %cond225 = icmp ne i32 %reg119, %Num ; <i1> [#uses=1]
43 br i1 %cond225, label %bb3, label %bb6
44 bb6: ; preds = %bb5, %bb2
45 %reg120 = add i32 %reg115, 1 ; <i32> [#uses=2]
46 %cond226 = icmp ne i32 %reg120, %Num ; <i1> [#uses=1]
47 br i1 %cond226, label %bb2, label %bb7
48 bb7: ; preds = %bb6, %bb0