1 ; RUN: opt -S -passes=loop-rotate < %s -verify-loop-info -verify-dom-info -verify-memoryssa | FileCheck %s
3 target 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"
4 target triple = "x86_64-apple-macosx10.8.0"
7 define i32 @test1(ptr nocapture %a) nounwind readonly {
11 for.cond: ; preds = %for.cond1, %entry
12 %sum.0 = phi i32 [ 0, %entry ], [ %sum.1, %for.cond1 ]
13 %i.0 = phi i1 [ true, %entry ], [ false, %for.cond1 ]
14 br i1 %i.0, label %for.cond1, label %return
16 for.cond1: ; preds = %for.cond, %land.rhs
17 %sum.1 = phi i32 [ %add, %land.rhs ], [ %sum.0, %for.cond ]
18 %i.1 = phi i32 [ %inc, %land.rhs ], [ 0, %for.cond ]
19 %cmp2 = icmp ult i32 %i.1, 100
20 br i1 %cmp2, label %land.rhs, label %for.cond
22 land.rhs: ; preds = %for.cond1
23 %conv = zext i32 %i.1 to i64
24 %arrayidx = getelementptr inbounds [100 x i32], ptr %a, i64 0, i64 %conv
25 %0 = load i32, ptr %arrayidx, align 4
26 %add = add i32 %0, %sum.1
27 %cmp4 = icmp ugt i32 %add, 1000
28 %inc = add i32 %i.1, 1
29 br i1 %cmp4, label %return, label %for.cond1
31 return: ; preds = %for.cond, %land.rhs
32 %retval.0 = phi i32 [ 1000, %land.rhs ], [ %sum.0, %for.cond ]
35 ; CHECK-LABEL: @test1(
36 ; CHECK: for.cond1.preheader:
37 ; CHECK: %sum.04 = phi i32 [ 0, %entry ], [ %sum.1.lcssa, %for.cond.loopexit ]
38 ; CHECK: br label %for.cond1
41 ; CHECK: %sum.1 = phi i32 [ %add, %land.rhs ], [ %sum.04, %for.cond1.preheader ]
42 ; CHECK: %i.1 = phi i32 [ %inc, %land.rhs ], [ 0, %for.cond1.preheader ]
43 ; CHECK: %cmp2 = icmp ult i32 %i.1, 100
44 ; CHECK: br i1 %cmp2, label %land.rhs, label %for.cond.loopexit
47 define void @test2(i32 %x) nounwind {
51 for.cond: ; preds = %if.end, %entry
52 %i.0 = phi i32 [ 0, %entry ], [ %inc, %if.end ]
53 %cmp = icmp eq i32 %i.0, %x
54 br i1 %cmp, label %return.loopexit, label %for.body
56 for.body: ; preds = %for.cond
57 %call = tail call i32 @foo(i32 %i.0) nounwind
58 %tobool = icmp eq i32 %call, 0
59 br i1 %tobool, label %if.end, label %a
61 if.end: ; preds = %for.body
62 %call1 = tail call i32 @foo(i32 42) nounwind
63 %inc = add i32 %i.0, 1
66 a: ; preds = %for.body
67 %call2 = tail call i32 @bar(i32 1) nounwind
70 return.loopexit: ; preds = %for.cond
73 return: ; preds = %return.loopexit, %a
76 ; CHECK-LABEL: @test2(
78 ; CHECK: %inc = add i32 %i.02, 1
79 ; CHECK: %cmp = icmp eq i32 %inc, %x
80 ; CHECK: br i1 %cmp, label %for.cond.return.loopexit_crit_edge, label %for.body
87 @_ZTIi = external constant ptr
90 define void @test3(i32 %x) personality ptr @__gxx_personality_v0 {
92 %cmp2 = icmp eq i32 0, %x
93 br i1 %cmp2, label %try.cont.loopexit, label %for.body.lr.ph
95 for.body.lr.ph: ; preds = %entry
98 for.body: ; preds = %for.body.lr.ph, %for.inc
99 %i.03 = phi i32 [ 0, %for.body.lr.ph ], [ %inc, %for.inc ]
100 invoke void @_Z3fooi(i32 %i.03)
101 to label %for.inc unwind label %lpad
103 for.inc: ; preds = %for.body
104 %inc = add i32 %i.03, 1
105 %cmp = icmp eq i32 %inc, %x
106 br i1 %cmp, label %for.cond.try.cont.loopexit_crit_edge, label %for.body
108 lpad: ; preds = %for.body
109 %0 = landingpad { ptr, i32 }
111 %1 = extractvalue { ptr, i32 } %0, 0
112 %2 = extractvalue { ptr, i32 } %0, 1
113 %3 = tail call i32 @llvm.eh.typeid.for(ptr @_ZTIi) nounwind
114 %matches = icmp eq i32 %2, %3
115 br i1 %matches, label %catch, label %eh.resume
117 catch: ; preds = %lpad
118 %4 = tail call ptr @__cxa_begin_catch(ptr %1) nounwind
119 br i1 true, label %invoke.cont2.loopexit, label %for.body.i.lr.ph
121 for.body.i.lr.ph: ; preds = %catch
124 for.body.i: ; preds = %for.body.i.lr.ph, %for.inc.i
125 %i.0.i1 = phi i32 [ 0, %for.body.i.lr.ph ], [ %inc.i, %for.inc.i ]
126 invoke void @_Z3fooi(i32 %i.0.i1)
127 to label %for.inc.i unwind label %lpad.i
129 for.inc.i: ; preds = %for.body.i
130 %inc.i = add i32 %i.0.i1, 1
131 %cmp.i = icmp eq i32 %inc.i, 0
132 br i1 %cmp.i, label %for.cond.i.invoke.cont2.loopexit_crit_edge, label %for.body.i
134 lpad.i: ; preds = %for.body.i
135 %5 = landingpad { ptr, i32 }
137 %6 = extractvalue { ptr, i32 } %5, 0
138 %7 = extractvalue { ptr, i32 } %5, 1
139 %matches.i = icmp eq i32 %7, %3
140 br i1 %matches.i, label %catch.i, label %lpad1.body
142 catch.i: ; preds = %lpad.i
143 %8 = tail call ptr @__cxa_begin_catch(ptr %6) nounwind
144 invoke void @test3(i32 0)
145 to label %invoke.cont2.i unwind label %lpad1.i
147 invoke.cont2.i: ; preds = %catch.i
148 tail call void @__cxa_end_catch() nounwind
149 br label %invoke.cont2
151 lpad1.i: ; preds = %catch.i
152 %9 = landingpad { ptr, i32 }
154 %10 = extractvalue { ptr, i32 } %9, 0
155 %11 = extractvalue { ptr, i32 } %9, 1
156 tail call void @__cxa_end_catch() nounwind
159 for.cond.i.invoke.cont2.loopexit_crit_edge: ; preds = %for.inc.i
160 br label %invoke.cont2.loopexit
162 invoke.cont2.loopexit: ; preds = %for.cond.i.invoke.cont2.loopexit_crit_edge, %catch
163 br label %invoke.cont2
165 invoke.cont2: ; preds = %invoke.cont2.loopexit, %invoke.cont2.i
166 tail call void @__cxa_end_catch() nounwind
169 for.cond.try.cont.loopexit_crit_edge: ; preds = %for.inc
170 br label %try.cont.loopexit
172 try.cont.loopexit: ; preds = %for.cond.try.cont.loopexit_crit_edge, %entry
175 try.cont: ; preds = %try.cont.loopexit, %invoke.cont2
178 lpad1.body: ; preds = %lpad1.i, %lpad.i
179 %exn.slot.0.i = phi ptr [ %10, %lpad1.i ], [ %6, %lpad.i ]
180 %ehselector.slot.0.i = phi i32 [ %11, %lpad1.i ], [ %7, %lpad.i ]
181 tail call void @__cxa_end_catch() nounwind
184 eh.resume: ; preds = %lpad1.body, %lpad
185 %exn.slot.0 = phi ptr [ %exn.slot.0.i, %lpad1.body ], [ %1, %lpad ]
186 %ehselector.slot.0 = phi i32 [ %ehselector.slot.0.i, %lpad1.body ], [ %2, %lpad ]
187 %lpad.val = insertvalue { ptr, i32 } undef, ptr %exn.slot.0, 0
188 %lpad.val5 = insertvalue { ptr, i32 } %lpad.val, i32 %ehselector.slot.0, 1
189 resume { ptr, i32 } %lpad.val5
192 declare void @_Z3fooi(i32)
194 declare i32 @__gxx_personality_v0(...)
196 declare i32 @llvm.eh.typeid.for(ptr) nounwind readnone
198 declare ptr @__cxa_begin_catch(ptr)
200 declare void @__cxa_end_catch()
202 define void @test4() nounwind uwtable {
207 br i1 undef, label %"31", label %"4"
210 %. = select i1 undef, float 0x3F50624DE0000000, float undef
214 "7": ; preds = %"4", %entry
215 %1 = phi i32 [ %0, %"4" ], [ 0, %entry ]
216 %2 = icmp slt i32 %1, 100
217 br i1 %2, label %"3", label %"8"
220 br i1 undef, label %"9", label %"31"
225 "27": ; preds = %"31"
228 "31": ; preds = %"8", %"3"
229 br i1 undef, label %"27", label %"32"
231 "32": ; preds = %"31"
234 "33": ; preds = %"32", %"9"