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
4 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"
5 target triple = "x86_64-apple-macosx10.8.0"
8 define i32 @test1([100 x i32]* nocapture %a) nounwind readonly {
12 for.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
17 for.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
23 land.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
32 return: ; preds = %for.cond, %land.rhs
33 %retval.0 = phi i32 [ 1000, %land.rhs ], [ %sum.0, %for.cond ]
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
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
48 define void @test2(i32 %x) nounwind {
52 for.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
57 for.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
62 if.end: ; preds = %for.body
63 %call1 = tail call i32 @foo(i32 42) nounwind
64 %inc = add i32 %i.0, 1
67 a: ; preds = %for.body
68 %call2 = tail call i32 @bar(i32 1) nounwind
71 return.loopexit: ; preds = %for.cond
74 return: ; preds = %return.loopexit, %a
77 ; CHECK-LABEL: @test2(
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
88 @_ZTIi = external constant i8*
91 define void @test3(i32 %x) personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*) {
93 %cmp2 = icmp eq i32 0, %x
94 br i1 %cmp2, label %try.cont.loopexit, label %for.body.lr.ph
96 for.body.lr.ph: ; preds = %entry
99 for.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
104 for.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
109 lpad: ; 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
118 catch: ; 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
122 for.body.i.lr.ph: ; preds = %catch
125 for.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
130 for.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
135 lpad.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
143 catch.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
148 invoke.cont2.i: ; preds = %catch.i
149 tail call void @__cxa_end_catch() nounwind
150 br label %invoke.cont2
152 lpad1.i: ; preds = %catch.i
153 %9 = landingpad { i8*, i32 }
155 %10 = extractvalue { i8*, i32 } %9, 0
156 %11 = extractvalue { i8*, i32 } %9, 1
157 tail call void @__cxa_end_catch() nounwind
160 for.cond.i.invoke.cont2.loopexit_crit_edge: ; preds = %for.inc.i
161 br label %invoke.cont2.loopexit
163 invoke.cont2.loopexit: ; preds = %for.cond.i.invoke.cont2.loopexit_crit_edge, %catch
164 br label %invoke.cont2
166 invoke.cont2: ; preds = %invoke.cont2.loopexit, %invoke.cont2.i
167 tail call void @__cxa_end_catch() nounwind
170 for.cond.try.cont.loopexit_crit_edge: ; preds = %for.inc
171 br label %try.cont.loopexit
173 try.cont.loopexit: ; preds = %for.cond.try.cont.loopexit_crit_edge, %entry
176 try.cont: ; preds = %try.cont.loopexit, %invoke.cont2
179 lpad1.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
185 eh.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
193 declare void @_Z3fooi(i32)
195 declare i32 @__gxx_personality_v0(...)
197 declare i32 @llvm.eh.typeid.for(i8*) nounwind readnone
199 declare i8* @__cxa_begin_catch(i8*)
201 declare void @__cxa_end_catch()
203 define void @test4() nounwind uwtable {
208 br i1 undef, label %"31", label %"4"
211 %. = select i1 undef, float 0x3F50624DE0000000, float undef
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"
221 br i1 undef, label %"9", label %"31"
226 "27": ; preds = %"31"
229 "31": ; preds = %"8", %"3"
230 br i1 undef, label %"27", label %"32"
232 "32": ; preds = %"31"
235 "33": ; preds = %"32", %"9"