New testcase for LICM reassociation
[oota-llvm.git] / test / Transforms / Reassociate / looptest.ll
1 ; This testcase comes from this C fragment:
2 ;
3 ; void test(unsigned Num, int *Array) {
4 ;  unsigned i, j, k;
5 ;
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 */
10 ;}
11 ;
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.
14 ;
15 ; RUN: if as < %s | opt -reassociate | dis | grep 115 | grep 117
16 ; RUN: then exit 1
17 ; RUN: else exit 0
18 ; RUN: fi
19
20 %.LC0 = internal global [4 x sbyte] c"%d\0A\00"         ; <[4 x sbyte]*> [#uses=1]
21
22 declare int "printf"(sbyte*, ...)
23
24 void "test"(uint %Num, int* %Array) {
25 bb0:                                    ;[#uses=1]
26         %cond221 = seteq uint 0, %Num           ; <bool> [#uses=3]
27         br bool %cond221, label %bb7, label %bb2
28
29 bb2:                                    ;[#uses=3]
30         %reg115 = phi uint [ %reg120, %bb6 ], [ 0, %bb0 ]               ; <uint> [#uses=2]
31         br bool %cond221, label %bb6, label %bb3
32
33 bb3:                                    ;[#uses=3]
34         %reg116 = phi uint [ %reg119, %bb5 ], [ 0, %bb2 ]               ; <uint> [#uses=2]
35         br bool %cond221, label %bb5, label %bb4
36
37 bb4:                                    ;[#uses=3]
38         %reg117 = phi uint [ %reg118, %bb4 ], [ 0, %bb3 ]               ; <uint> [#uses=2]
39         %reg113 = add uint %reg115, %reg117             ; <uint> [#uses=1]
40         %reg114 = add uint %reg113, %reg116             ; <uint> [#uses=1]
41         %cast227 = getelementptr [4 x sbyte]* %.LC0, uint 0, uint 0             ; <sbyte*> [#uses=1]
42         call int (sbyte*, ...)* %printf( sbyte* %cast227, uint %reg114 )                ; <int>:0 [#uses=0]
43         %reg118 = add uint %reg117, 1           ; <uint> [#uses=2]
44         %cond224 = setne uint %reg118, %Num             ; <bool> [#uses=1]
45         br bool %cond224, label %bb4, label %bb5
46
47 bb5:                                    ;[#uses=3]
48         %reg119 = add uint %reg116, 1           ; <uint> [#uses=2]
49         %cond225 = setne uint %reg119, %Num             ; <bool> [#uses=1]
50         br bool %cond225, label %bb3, label %bb6
51
52 bb6:                                    ;[#uses=3]
53         %reg120 = add uint %reg115, 1           ; <uint> [#uses=2]
54         %cond226 = setne uint %reg120, %Num             ; <bool> [#uses=1]
55         br bool %cond226, label %bb2, label %bb7
56
57 bb7:                                    ;[#uses=2]
58         ret void
59 }