• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1; RUN: opt -S -loop-rotate < %s -verify-loop-info -verify-dom-info | FileCheck %s
2; RUN: opt -S -loop-rotate < %s -verify-loop-info -verify-dom-info -enable-mssa-loop-dependency=true -verify-memoryssa | FileCheck %s
3
4target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128"
5target triple = "x86_64-apple-macosx10.8.0"
6
7; PR7447
8define i32 @test1([100 x i32]* nocapture %a) nounwind readonly {
9entry:
10  br label %for.cond
11
12for.cond:                                         ; preds = %for.cond1, %entry
13  %sum.0 = phi i32 [ 0, %entry ], [ %sum.1, %for.cond1 ]
14  %i.0 = phi i1 [ true, %entry ], [ false, %for.cond1 ]
15  br i1 %i.0, label %for.cond1, label %return
16
17for.cond1:                                        ; preds = %for.cond, %land.rhs
18  %sum.1 = phi i32 [ %add, %land.rhs ], [ %sum.0, %for.cond ]
19  %i.1 = phi i32 [ %inc, %land.rhs ], [ 0, %for.cond ]
20  %cmp2 = icmp ult i32 %i.1, 100
21  br i1 %cmp2, label %land.rhs, label %for.cond
22
23land.rhs:                                         ; preds = %for.cond1
24  %conv = zext i32 %i.1 to i64
25  %arrayidx = getelementptr inbounds [100 x i32], [100 x i32]* %a, i64 0, i64 %conv
26  %0 = load i32, i32* %arrayidx, align 4
27  %add = add i32 %0, %sum.1
28  %cmp4 = icmp ugt i32 %add, 1000
29  %inc = add i32 %i.1, 1
30  br i1 %cmp4, label %return, label %for.cond1
31
32return:                                           ; preds = %for.cond, %land.rhs
33  %retval.0 = phi i32 [ 1000, %land.rhs ], [ %sum.0, %for.cond ]
34  ret i32 %retval.0
35
36; CHECK-LABEL: @test1(
37; CHECK: for.cond1.preheader:
38; CHECK: %sum.04 = phi i32 [ 0, %entry ], [ %sum.1.lcssa, %for.cond.loopexit ]
39; CHECK: br label %for.cond1
40
41; CHECK: for.cond1:
42; CHECK: %sum.1 = phi i32 [ %add, %land.rhs ], [ %sum.04, %for.cond1.preheader ]
43; CHECK: %i.1 = phi i32 [ %inc, %land.rhs ], [ 0, %for.cond1.preheader ]
44; CHECK: %cmp2 = icmp ult i32 %i.1, 100
45; CHECK: br i1 %cmp2, label %land.rhs, label %for.cond.loopexit
46}
47
48define void @test2(i32 %x) nounwind {
49entry:
50  br label %for.cond
51
52for.cond:                                         ; preds = %if.end, %entry
53  %i.0 = phi i32 [ 0, %entry ], [ %inc, %if.end ]
54  %cmp = icmp eq i32 %i.0, %x
55  br i1 %cmp, label %return.loopexit, label %for.body
56
57for.body:                                         ; preds = %for.cond
58  %call = tail call i32 @foo(i32 %i.0) nounwind
59  %tobool = icmp eq i32 %call, 0
60  br i1 %tobool, label %if.end, label %a
61
62if.end:                                           ; preds = %for.body
63  %call1 = tail call i32 @foo(i32 42) nounwind
64  %inc = add i32 %i.0, 1
65  br label %for.cond
66
67a:                                                ; preds = %for.body
68  %call2 = tail call i32 @bar(i32 1) nounwind
69  br label %return
70
71return.loopexit:                                  ; preds = %for.cond
72  br label %return
73
74return:                                           ; preds = %return.loopexit, %a
75  ret void
76
77; CHECK-LABEL: @test2(
78; CHECK: if.end:
79; CHECK: %inc = add i32 %i.02, 1
80; CHECK: %cmp = icmp eq i32 %inc, %x
81; CHECK: br i1 %cmp, label %for.cond.return.loopexit_crit_edge, label %for.body
82}
83
84declare i32 @foo(i32)
85
86declare i32 @bar(i32)
87
88@_ZTIi = external constant i8*
89
90; Verify dominators.
91define void @test3(i32 %x) personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*) {
92entry:
93  %cmp2 = icmp eq i32 0, %x
94  br i1 %cmp2, label %try.cont.loopexit, label %for.body.lr.ph
95
96for.body.lr.ph:                                   ; preds = %entry
97  br label %for.body
98
99for.body:                                         ; preds = %for.body.lr.ph, %for.inc
100  %i.03 = phi i32 [ 0, %for.body.lr.ph ], [ %inc, %for.inc ]
101  invoke void @_Z3fooi(i32 %i.03)
102          to label %for.inc unwind label %lpad
103
104for.inc:                                          ; preds = %for.body
105  %inc = add i32 %i.03, 1
106  %cmp = icmp eq i32 %inc, %x
107  br i1 %cmp, label %for.cond.try.cont.loopexit_crit_edge, label %for.body
108
109lpad:                                             ; preds = %for.body
110  %0 = landingpad { i8*, i32 }
111          catch i8* bitcast (i8** @_ZTIi to i8*)
112  %1 = extractvalue { i8*, i32 } %0, 0
113  %2 = extractvalue { i8*, i32 } %0, 1
114  %3 = tail call i32 @llvm.eh.typeid.for(i8* bitcast (i8** @_ZTIi to i8*)) nounwind
115  %matches = icmp eq i32 %2, %3
116  br i1 %matches, label %catch, label %eh.resume
117
118catch:                                            ; preds = %lpad
119  %4 = tail call i8* @__cxa_begin_catch(i8* %1) nounwind
120  br i1 true, label %invoke.cont2.loopexit, label %for.body.i.lr.ph
121
122for.body.i.lr.ph:                                 ; preds = %catch
123  br label %for.body.i
124
125for.body.i:                                       ; preds = %for.body.i.lr.ph, %for.inc.i
126  %i.0.i1 = phi i32 [ 0, %for.body.i.lr.ph ], [ %inc.i, %for.inc.i ]
127  invoke void @_Z3fooi(i32 %i.0.i1)
128          to label %for.inc.i unwind label %lpad.i
129
130for.inc.i:                                        ; preds = %for.body.i
131  %inc.i = add i32 %i.0.i1, 1
132  %cmp.i = icmp eq i32 %inc.i, 0
133  br i1 %cmp.i, label %for.cond.i.invoke.cont2.loopexit_crit_edge, label %for.body.i
134
135lpad.i:                                           ; preds = %for.body.i
136  %5 = landingpad { i8*, i32 }
137          catch i8* bitcast (i8** @_ZTIi to i8*)
138  %6 = extractvalue { i8*, i32 } %5, 0
139  %7 = extractvalue { i8*, i32 } %5, 1
140  %matches.i = icmp eq i32 %7, %3
141  br i1 %matches.i, label %catch.i, label %lpad1.body
142
143catch.i:                                          ; preds = %lpad.i
144  %8 = tail call i8* @__cxa_begin_catch(i8* %6) nounwind
145  invoke void @test3(i32 0)
146          to label %invoke.cont2.i unwind label %lpad1.i
147
148invoke.cont2.i:                                   ; preds = %catch.i
149  tail call void @__cxa_end_catch() nounwind
150  br label %invoke.cont2
151
152lpad1.i:                                          ; preds = %catch.i
153  %9 = landingpad { i8*, i32 }
154          cleanup
155  %10 = extractvalue { i8*, i32 } %9, 0
156  %11 = extractvalue { i8*, i32 } %9, 1
157  tail call void @__cxa_end_catch() nounwind
158  br label %lpad1.body
159
160for.cond.i.invoke.cont2.loopexit_crit_edge:       ; preds = %for.inc.i
161  br label %invoke.cont2.loopexit
162
163invoke.cont2.loopexit:                            ; preds = %for.cond.i.invoke.cont2.loopexit_crit_edge, %catch
164  br label %invoke.cont2
165
166invoke.cont2:                                     ; preds = %invoke.cont2.loopexit, %invoke.cont2.i
167  tail call void @__cxa_end_catch() nounwind
168  br label %try.cont
169
170for.cond.try.cont.loopexit_crit_edge:             ; preds = %for.inc
171  br label %try.cont.loopexit
172
173try.cont.loopexit:                                ; preds = %for.cond.try.cont.loopexit_crit_edge, %entry
174  br label %try.cont
175
176try.cont:                                         ; preds = %try.cont.loopexit, %invoke.cont2
177  ret void
178
179lpad1.body:                                       ; preds = %lpad1.i, %lpad.i
180  %exn.slot.0.i = phi i8* [ %10, %lpad1.i ], [ %6, %lpad.i ]
181  %ehselector.slot.0.i = phi i32 [ %11, %lpad1.i ], [ %7, %lpad.i ]
182  tail call void @__cxa_end_catch() nounwind
183  br label %eh.resume
184
185eh.resume:                                        ; preds = %lpad1.body, %lpad
186  %exn.slot.0 = phi i8* [ %exn.slot.0.i, %lpad1.body ], [ %1, %lpad ]
187  %ehselector.slot.0 = phi i32 [ %ehselector.slot.0.i, %lpad1.body ], [ %2, %lpad ]
188  %lpad.val = insertvalue { i8*, i32 } undef, i8* %exn.slot.0, 0
189  %lpad.val5 = insertvalue { i8*, i32 } %lpad.val, i32 %ehselector.slot.0, 1
190  resume { i8*, i32 } %lpad.val5
191}
192
193declare void @_Z3fooi(i32)
194
195declare i32 @__gxx_personality_v0(...)
196
197declare i32 @llvm.eh.typeid.for(i8*) nounwind readnone
198
199declare i8* @__cxa_begin_catch(i8*)
200
201declare void @__cxa_end_catch()
202
203define void @test4() nounwind uwtable {
204entry:
205  br label %"7"
206
207"3":                                              ; preds = %"7"
208  br i1 undef, label %"31", label %"4"
209
210"4":                                              ; preds = %"3"
211  %. = select i1 undef, float 0x3F50624DE0000000, float undef
212  %0 = add i32 %1, 1
213  br label %"7"
214
215"7":                                              ; preds = %"4", %entry
216  %1 = phi i32 [ %0, %"4" ], [ 0, %entry ]
217  %2 = icmp slt i32 %1, 100
218  br i1 %2, label %"3", label %"8"
219
220"8":                                              ; preds = %"7"
221  br i1 undef, label %"9", label %"31"
222
223"9":                                              ; preds = %"8"
224  br label %"33"
225
226"27":                                             ; preds = %"31"
227  unreachable
228
229"31":                                             ; preds = %"8", %"3"
230  br i1 undef, label %"27", label %"32"
231
232"32":                                             ; preds = %"31"
233  br label %"33"
234
235"33":                                             ; preds = %"32", %"9"
236  ret void
237}
238