1 ; RUN: opt -loop-reduce -S < %s | FileCheck %s
3 ; <rdar://problem/11049788> Segmentation fault: 11 in LoopStrengthReduce
5 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"
6 target triple = "x86_64-apple-darwin10.0.0"
8 ; IVUsers should not consider tmp128 a valid user because it is not in a
9 ; simplified loop nest.
10 ; CHECK-LABEL: @nopreheader(
12 ; CHECK: %tmp128 = add i64 %0, %indvar65
13 define void @nopreheader(i8* %cmd) nounwind ssp {
15 indirectbr i8* undef, [label %while.cond]
17 while.cond: ; preds = %while.body, %entry
18 %0 = phi i64 [ %indvar.next48, %while.body ], [ 0, %entry ]
19 indirectbr i8* undef, [label %while.end, label %while.body]
21 while.body: ; preds = %lor.rhs, %lor.lhs.false17, %lor.lhs.false11, %lor.lhs.false, %land.rhs
22 %indvar.next48 = add i64 %0, 1
23 indirectbr i8* undef, [label %while.cond]
25 while.end: ; preds = %lor.rhs, %while.cond
26 indirectbr i8* undef, [label %if.end152]
28 if.end152: ; preds = %lor.lhs.false144, %if.end110
29 indirectbr i8* undef, [label %lor.lhs.false184, label %for.cond]
31 lor.lhs.false184: ; preds = %lor.lhs.false177
32 indirectbr i8* undef, [label %return, label %for.cond]
34 for.cond: ; preds = %for.inc, %lor.lhs.false184, %if.end152
35 %indvar65 = phi i64 [ %indvar.next66, %for.inc ], [ 0, %lor.lhs.false184 ], [ 0, %if.end152 ]
36 %tmp128 = add i64 %0, %indvar65
37 %s.4 = getelementptr i8, i8* %cmd, i64 %tmp128
38 %tmp195 = load i8, i8* %s.4, align 1
39 indirectbr i8* undef, [label %return, label %land.rhs198]
41 land.rhs198: ; preds = %for.cond
42 indirectbr i8* undef, [label %return, label %for.inc]
44 for.inc: ; preds = %lor.rhs234, %land.lhs.true228, %land.lhs.true216, %land.lhs.true204
45 %indvar.next66 = add i64 %indvar65, 1
46 indirectbr i8* undef, [label %for.cond]
48 return: ; preds = %if.end677, %doshell, %if.then96
52 ; Another case with a dominating loop that does not contain the IV
53 ; User. Just make sure it doesn't assert.
54 define void @nopreheader2() nounwind ssp {
56 indirectbr i8* undef, [label %while.cond, label %return]
58 while.cond: ; preds = %while.cond.backedge, %entry
59 indirectbr i8* undef, [label %while.cond.backedge, label %lor.rhs]
61 lor.rhs: ; preds = %while.cond
62 indirectbr i8* undef, [label %while.cond.backedge, label %while.end]
64 while.cond.backedge: ; preds = %lor.rhs, %while.cond
65 indirectbr i8* undef, [label %while.cond]
67 while.end: ; preds = %lor.rhs
68 indirectbr i8* undef, [label %if.then18, label %return]
70 if.then18: ; preds = %while.end
71 indirectbr i8* undef, [label %if.end35, label %lor.lhs.false]
73 lor.lhs.false: ; preds = %if.then18
74 indirectbr i8* undef, [label %if.end35, label %return]
76 if.end35: ; preds = %lor.lhs.false, %if.then18
77 indirectbr i8* undef, [label %while.cond36]
79 while.cond36: ; preds = %while.body49, %if.end35
80 %0 = phi i64 [ %indvar.next13, %while.body49 ], [ 0, %if.end35 ]
81 indirectbr i8* undef, [label %while.body49, label %lor.rhs42]
83 lor.rhs42: ; preds = %while.cond36
84 indirectbr i8* undef, [label %while.body49, label %while.end52]
86 while.body49: ; preds = %lor.rhs42, %while.cond36
87 %indvar.next13 = add i64 %0, 1
88 indirectbr i8* undef, [label %while.cond36]
90 while.end52: ; preds = %lor.rhs42
91 indirectbr i8* undef, [label %land.lhs.true, label %return]
93 land.lhs.true: ; preds = %while.end52
94 indirectbr i8* undef, [label %while.cond66.preheader, label %return]
96 while.cond66.preheader: ; preds = %land.lhs.true
97 indirectbr i8* undef, [label %while.cond66]
99 while.cond66: ; preds = %while.body77, %while.cond66.preheader
100 indirectbr i8* undef, [label %land.rhs, label %while.cond81.preheader]
102 land.rhs: ; preds = %while.cond66
103 indirectbr i8* undef, [label %while.body77, label %while.cond81.preheader]
105 while.cond81.preheader: ; preds = %land.rhs, %while.cond66
106 %tmp45 = add i64 undef, %0
107 %tmp46 = add i64 %tmp45, undef
108 indirectbr i8* undef, [label %while.cond81]
110 while.body77: ; preds = %land.rhs
111 indirectbr i8* undef, [label %while.cond66]
113 while.cond81: ; preds = %while.body94, %while.cond81.preheader
114 %tmp25 = add i64 %tmp46, undef
115 indirectbr i8* undef, [label %while.body94, label %lor.rhs87]
117 lor.rhs87: ; preds = %while.cond81
118 indirectbr i8* undef, [label %while.body94, label %return]
120 while.body94: ; preds = %lor.rhs87, %while.cond81
121 indirectbr i8* undef, [label %while.cond81]
123 return: ; preds = %if.end216, %land.lhs.true183, %land.lhs.true, %while.end52, %lor.lhs.false, %while.end, %entry
127 ; Test a phi operand IV User dominated by a no-preheader loop.
128 define void @nopreheader3() nounwind uwtable ssp align 2 {
130 indirectbr i8* blockaddress(@nopreheader3, %if.end10), [label %if.end22, label %if.end10]
132 if.end10: ; preds = %entry
133 indirectbr i8* blockaddress(@nopreheader3, %if.end6.i), [label %if.end22, label %if.end6.i]
135 if.end6.i: ; preds = %if.end10
136 indirectbr i8* blockaddress(@nopreheader3, %while.cond2.preheader.i.i), [label %if.then12, label %while.cond2.preheader.i.i]
138 while.cond2.preheader.i.i: ; preds = %while.end.i18.i, %if.end6.i
139 indirectbr i8* blockaddress(@nopreheader3, %while.cond2.i.i), [label %while.cond2.i.i]
141 while.cond2.i.i: ; preds = %while.cond2.i.i, %while.cond2.preheader.i.i
142 %i1.1.i14.i = phi i32 [ %add.i15.i, %while.cond2.i.i ], [ undef, %while.cond2.preheader.i.i ]
143 %add.i15.i = add nsw i32 %i1.1.i14.i, undef
144 indirectbr i8* blockaddress(@nopreheader3, %while.end.i18.i), [label %while.cond2.i.i, label %while.end.i18.i]
146 while.end.i18.i: ; preds = %while.cond2.i.i
147 indirectbr i8* blockaddress(@nopreheader3, %while.cond2.preheader.i.i), [label %if.then12, label %while.cond2.preheader.i.i]
149 if.then12: ; preds = %while.end.i18.i, %if.end6.i
150 %i1.0.lcssa.i.i = phi i32 [ undef, %if.end6.i ], [ %i1.1.i14.i, %while.end.i18.i ]
151 indirectbr i8* blockaddress(@nopreheader3, %if.end22), [label %if.end22]
153 if.end22: ; preds = %if.then12, %if.end10, %entry