1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; This testcase comes from this C fragment:
4 ; void test(unsigned Num, int *Array) {
7 ; for (i = 0; i != Num; ++i)
8 ; for (j = 0; j != Num; ++j)
9 ; for (k = 0; k != Num; ++k)
10 ; printf("%d\n", i+k+j); /* Reassociate to (i+j)+k */
13 ; In this case, we want to reassociate the specified expr so that i+j can be
14 ; hoisted out of the inner most loop.
16 ; RUN: opt < %s -reassociate -S | FileCheck %s
18 @.LC0 = internal global [4 x i8] c"%d\0A\00" ; <[4 x i8]*> [#uses=1]
20 declare i32 @printf(i8*, ...)
22 ; Check that (i+j) has been reassociated (i=reg115, j=reg116)
23 define void @test(i32 %Num, i32* %Array) {
26 ; CHECK-NEXT: [[COND221:%.*]] = icmp eq i32 0, [[NUM:%.*]]
27 ; CHECK-NEXT: br i1 [[COND221]], label [[BB7:%.*]], label [[BB2:%.*]]
29 ; CHECK-NEXT: [[REG115:%.*]] = phi i32 [ [[REG120:%.*]], [[BB6:%.*]] ], [ 0, [[BB0:%.*]] ]
30 ; CHECK-NEXT: br i1 [[COND221]], label [[BB6]], label [[BB3:%.*]]
32 ; CHECK-NEXT: [[REG116:%.*]] = phi i32 [ [[REG119:%.*]], [[BB5:%.*]] ], [ 0, [[BB2]] ]
33 ; CHECK-NEXT: br i1 [[COND221]], label [[BB5]], label [[BB4:%.*]]
35 ; CHECK-NEXT: [[REG117:%.*]] = phi i32 [ [[REG118:%.*]], [[BB4]] ], [ 0, [[BB3]] ]
36 ; CHECK-NEXT: [[REG113:%.*]] = add i32 [[REG116]], [[REG115]]
37 ; CHECK-NEXT: [[REG114:%.*]] = add i32 [[REG113]], [[REG117]]
38 ; CHECK-NEXT: [[CAST227:%.*]] = getelementptr [4 x i8], [4 x i8]* @.LC0, i64 0, i64 0
39 ; CHECK-NEXT: [[TMP0:%.*]] = call i32 (i8*, ...) @printf(i8* [[CAST227]], i32 [[REG114]])
40 ; CHECK-NEXT: [[REG118]] = add i32 [[REG117]], 1
41 ; CHECK-NEXT: [[COND224:%.*]] = icmp ne i32 [[REG118]], [[NUM]]
42 ; CHECK-NEXT: br i1 [[COND224]], label [[BB4]], label [[BB5]]
44 ; CHECK-NEXT: [[REG119]] = add i32 [[REG116]], 1
45 ; CHECK-NEXT: [[COND225:%.*]] = icmp ne i32 [[REG119]], [[NUM]]
46 ; CHECK-NEXT: br i1 [[COND225]], label [[BB3]], label [[BB6]]
48 ; CHECK-NEXT: [[REG120]] = add i32 [[REG115]], 1
49 ; CHECK-NEXT: [[COND226:%.*]] = icmp ne i32 [[REG120]], [[NUM]]
50 ; CHECK-NEXT: br i1 [[COND226]], label [[BB2]], label [[BB7]]
52 ; CHECK-NEXT: ret void
55 %cond221 = icmp eq i32 0, %Num ; <i1> [#uses=3]
56 br i1 %cond221, label %bb7, label %bb2
57 bb2: ; preds = %bb6, %bb0
58 %reg115 = phi i32 [ %reg120, %bb6 ], [ 0, %bb0 ] ; <i32> [#uses=2]
59 br i1 %cond221, label %bb6, label %bb3
60 bb3: ; preds = %bb5, %bb2
61 %reg116 = phi i32 [ %reg119, %bb5 ], [ 0, %bb2 ] ; <i32> [#uses=2]
62 br i1 %cond221, label %bb5, label %bb4
63 bb4: ; preds = %bb4, %bb3
64 %reg117 = phi i32 [ %reg118, %bb4 ], [ 0, %bb3 ] ; <i32> [#uses=2]
65 %reg113 = add i32 %reg115, %reg117 ; <i32> [#uses=1]
66 %reg114 = add i32 %reg113, %reg116 ; <i32> [#uses=1]
67 %cast227 = getelementptr [4 x i8], [4 x i8]* @.LC0, i64 0, i64 0 ; <i8*> [#uses=1]
68 call i32 (i8*, ...) @printf( i8* %cast227, i32 %reg114 ) ; <i32>:0 [#uses=0]
69 %reg118 = add i32 %reg117, 1 ; <i32> [#uses=2]
70 %cond224 = icmp ne i32 %reg118, %Num ; <i1> [#uses=1]
71 br i1 %cond224, label %bb4, label %bb5
72 bb5: ; preds = %bb4, %bb3
73 %reg119 = add i32 %reg116, 1 ; <i32> [#uses=2]
74 %cond225 = icmp ne i32 %reg119, %Num ; <i1> [#uses=1]
75 br i1 %cond225, label %bb3, label %bb6
76 bb6: ; preds = %bb5, %bb2
77 %reg120 = add i32 %reg115, 1 ; <i32> [#uses=2]
78 %cond226 = icmp ne i32 %reg120, %Num ; <i1> [#uses=1]
79 br i1 %cond226, label %bb2, label %bb7
80 bb7: ; preds = %bb6, %bb0