Revert "Disable codegen prepare critical edge splitting. Machine instruction passes...
[oota-llvm.git] / test / CodeGen / X86 / postra-licm.ll
1 ; RUN: llc < %s -mtriple=i386-apple-darwin -relocation-model=pic -disable-fp-elim | FileCheck %s -check-prefix=X86-32
2 ; RUN: llc < %s -mtriple=x86_64-apple-darwin -relocation-model=pic -disable-fp-elim | FileCheck %s -check-prefix=X86-64
3
4 ; MachineLICM should be able to hoist loop invariant reload out of the loop.
5 ; rdar://7233099
6
7 %struct.FILE = type { i8*, i32, i32, i16, i16, %struct.__sbuf, i32, i8*, i32 (i8*)*, i32 (i8*, i8*, i32)*, i64 (i8*, i64, i32)*, i32 (i8*, i8*, i32)*, %struct.__sbuf, %struct.__sFILEX*, i32, [3 x i8], [1 x i8], %struct.__sbuf, i32, i64 }
8 %struct.__sFILEX = type opaque
9 %struct.__sbuf = type { i8*, i32 }
10 %struct.epoch_t = type { %struct.trans_t*, %struct.trans_t*, i32, i32, i32, i32, i32 }
11 %struct.trans_t = type { i32, i32, i32, i8* }
12
13 @.str12 = external constant [2 x i8], align 1     ; <[2 x i8]*> [#uses=1]
14 @.str19 = external constant [7 x i8], align 1     ; <[7 x i8]*> [#uses=1]
15 @.str24 = external constant [4 x i8], align 1     ; <[4 x i8]*> [#uses=1]
16
17 define i32 @t1(i32 %c, i8** nocapture %v) nounwind ssp {
18 ; X86-32: t1:
19 entry:
20   br i1 undef, label %bb, label %bb3
21
22 bb:                                               ; preds = %entry
23   unreachable
24
25 bb3:                                              ; preds = %entry
26   br i1 undef, label %bb.i, label %bb.nph41
27
28 bb.i:                                             ; preds = %bb3
29   unreachable
30
31 bb.nph41:                                         ; preds = %bb3
32   %0 = call %struct.FILE* @"\01_fopen$UNIX2003"(i8* undef, i8* getelementptr inbounds ([2 x i8]* @.str12, i32 0, i32 0)) nounwind ; <%struct.FILE*> [#uses=3]
33   br i1 undef, label %bb4, label %bb5.preheader
34
35 bb5.preheader:                                    ; preds = %bb.nph41
36   br label %bb5
37
38 bb4:                                              ; preds = %bb.nph41
39   unreachable
40
41 bb5:                                              ; preds = %bb5, %bb5.preheader
42   br i1 undef, label %bb7, label %bb5
43
44 bb7:                                              ; preds = %bb5
45   br i1 undef, label %bb9, label %bb12
46
47 bb9:                                              ; preds = %bb7
48   unreachable
49
50 bb12:                                             ; preds = %bb7
51   br i1 undef, label %bb16, label %bb22
52
53 bb16:                                             ; preds = %bb12
54   unreachable
55
56 bb22:                                             ; preds = %bb12
57   br label %bb.i1
58
59 bb.i1:                                            ; preds = %bb.i1, %bb22
60   %1 = icmp eq i8 undef, 69                       ; <i1> [#uses=1]
61   br i1 %1, label %imix_test.exit, label %bb.i1
62
63 imix_test.exit:                                   ; preds = %bb.i1
64   br i1 undef, label %bb23, label %bb26.preheader
65
66 bb26.preheader:                                   ; preds = %imix_test.exit
67   br i1 undef, label %bb28, label %bb30
68
69 bb23:                                             ; preds = %imix_test.exit
70   unreachable
71 ; X86-32: %bb26.preheader.bb28_crit_edge
72 ; X86-32: movl -16(%ebp),
73 ; X86-32-NEXT: .align 4
74 ; X86-32-NEXT: %bb28
75
76 bb28:                                             ; preds = %bb28, %bb26.preheader
77   %counter.035 = phi i32 [ %3, %bb28 ], [ 0, %bb26.preheader ] ; <i32> [#uses=2]
78   %tmp56 = shl i32 %counter.035, 2                ; <i32> [#uses=0]
79   %2 = call i8* @fgets(i8* undef, i32 50, %struct.FILE* %0) nounwind ; <i8*> [#uses=0]
80   %3 = add nsw i32 %counter.035, 1                ; <i32> [#uses=1]
81   %4 = call i32 @feof(%struct.FILE* %0) nounwind  ; <i32> [#uses=0]
82   br label %bb28
83
84 bb30:                                             ; preds = %bb26.preheader
85   %5 = call i32 @strcmp(i8* undef, i8* getelementptr inbounds ([7 x i8]* @.str19, i32 0, i32 0)) nounwind readonly ; <i32> [#uses=0]
86   br i1 undef, label %bb34, label %bb70
87
88 bb32.loopexit:                                    ; preds = %bb45
89   %6 = icmp eq i32 undef, 0                       ; <i1> [#uses=1]
90   %indvar.next55 = add i32 %indvar54, 1           ; <i32> [#uses=1]
91   br i1 %6, label %bb34, label %bb70
92
93 bb34:                                             ; preds = %bb32.loopexit, %bb30
94   %indvar54 = phi i32 [ %indvar.next55, %bb32.loopexit ], [ 0, %bb30 ] ; <i32> [#uses=3]
95   br i1 false, label %bb35, label %bb39.preheader
96
97 bb35:                                             ; preds = %bb34
98   unreachable
99
100 bb39.preheader:                                   ; preds = %bb34
101   %7 = getelementptr inbounds %struct.epoch_t* undef, i32 %indvar54, i32 3 ; <i32*> [#uses=1]
102   %8 = getelementptr inbounds %struct.epoch_t* undef, i32 %indvar54, i32 2 ; <i32*> [#uses=0]
103   br i1 false, label %bb42, label %bb45
104
105 bb42:                                             ; preds = %bb39.preheader
106   unreachable
107
108 bb45:                                             ; preds = %bb39.preheader
109   %9 = call i32 @strcmp(i8* undef, i8* getelementptr inbounds ([4 x i8]* @.str24, i32 0, i32 0)) nounwind readonly ; <i32> [#uses=0]
110   br i1 false, label %bb47, label %bb32.loopexit
111
112 bb47:                                             ; preds = %bb45
113   %10 = load i32* %7, align 4                     ; <i32> [#uses=0]
114   unreachable
115
116 bb70:                                             ; preds = %bb32.loopexit, %bb30
117   br i1 undef, label %bb78, label %bb76
118
119 bb76:                                             ; preds = %bb70
120   unreachable
121
122 bb78:                                             ; preds = %bb70
123   br i1 undef, label %bb83, label %bb79
124
125 bb79:                                             ; preds = %bb78
126   unreachable
127
128 bb83:                                             ; preds = %bb78
129   call void @rewind(%struct.FILE* %0) nounwind
130   unreachable
131 }
132
133 declare %struct.FILE* @"\01_fopen$UNIX2003"(i8*, i8*)
134
135 declare i8* @fgets(i8*, i32, %struct.FILE* nocapture) nounwind
136
137 declare void @rewind(%struct.FILE* nocapture) nounwind
138
139 declare i32 @feof(%struct.FILE* nocapture) nounwind
140
141 declare i32 @strcmp(i8* nocapture, i8* nocapture) nounwind readonly
142
143 @map_4_to_16 = external constant [16 x i16], align 32 ; <[16 x i16]*> [#uses=2]
144
145 define void @t2(i8* nocapture %bufp, i8* nocapture %data, i32 %dsize) nounwind ssp {
146 ; X86-64: t2:
147 entry:
148   br i1 undef, label %return, label %bb.nph
149
150 bb.nph:                                           ; preds = %entry
151 ; X86-64: movq _map_4_to_16@GOTPCREL(%rip)
152 ; X86-64: .align 4
153   %tmp5 = zext i32 undef to i64                   ; <i64> [#uses=1]
154   %tmp6 = add i64 %tmp5, 1                        ; <i64> [#uses=1]
155   %tmp11 = shl i64 undef, 1                       ; <i64> [#uses=1]
156   %tmp14 = mul i64 undef, 3                       ; <i64> [#uses=1]
157   br label %bb
158
159 bb:                                               ; preds = %bb, %bb.nph
160   %tmp9 = mul i64 undef, undef                    ; <i64> [#uses=2]
161   %tmp12 = add i64 %tmp11, %tmp9                  ; <i64> [#uses=1]
162   %scevgep13 = getelementptr i8* %bufp, i64 %tmp12 ; <i8*> [#uses=1]
163   %tmp15 = add i64 %tmp14, %tmp9                  ; <i64> [#uses=1]
164   %scevgep16 = getelementptr i8* %bufp, i64 %tmp15 ; <i8*> [#uses=1]
165   %0 = load i8* undef, align 1                    ; <i8> [#uses=1]
166   %1 = zext i8 %0 to i32                          ; <i32> [#uses=1]
167   %2 = getelementptr inbounds [16 x i16]* @map_4_to_16, i64 0, i64 0 ; <i16*> [#uses=1]
168   %3 = load i16* %2, align 2                      ; <i16> [#uses=1]
169   %4 = trunc i16 %3 to i8                         ; <i8> [#uses=1]
170   store i8 %4, i8* undef, align 1
171   %5 = and i32 %1, 15                             ; <i32> [#uses=1]
172   %6 = zext i32 %5 to i64                         ; <i64> [#uses=1]
173   %7 = getelementptr inbounds [16 x i16]* @map_4_to_16, i64 0, i64 %6 ; <i16*> [#uses=1]
174   %8 = load i16* %7, align 2                      ; <i16> [#uses=2]
175   %9 = lshr i16 %8, 8                             ; <i16> [#uses=1]
176   %10 = trunc i16 %9 to i8                        ; <i8> [#uses=1]
177   store i8 %10, i8* %scevgep13, align 1
178   %11 = trunc i16 %8 to i8                        ; <i8> [#uses=1]
179   store i8 %11, i8* %scevgep16, align 1
180   %exitcond = icmp eq i64 undef, %tmp6            ; <i1> [#uses=1]
181   br i1 %exitcond, label %return, label %bb
182
183 return:                                           ; preds = %bb, %entry
184   ret void
185 }