1 ; Check that we don't crash on corner cases.
2 ; RUN: opt < %s -S -passes=loop-unroll -unroll-max-iteration-count-to-analyze=1000 -unroll-threshold=1 -unroll-max-percent-threshold-boost=200 -o /dev/null
3 ; RUN: opt < %s -S -passes='require<opt-remark-emit>,loop(loop-unroll-full)' -unroll-max-iteration-count-to-analyze=1000 -unroll-threshold=1 -unroll-max-percent-threshold-boost=200 -o /dev/null
4 target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
6 @known_constant = internal unnamed_addr constant [10 x i32] [i32 1, i32 1, i32 1, i32 1, i32 1, i32 1, i32 1, i32 1, i32 1, i32 1], align 16
8 define void @foo1(i1 %arg) {
13 %phi = phi i64 [ 0, %entry ], [ %inc, %for.body ]
14 %idx = zext i32 undef to i64
15 %add.ptr = getelementptr inbounds i64, ptr null, i64 %idx
16 %inc = add nuw nsw i64 %phi, 1
17 %cmp = icmp ult i64 %inc, 999
18 br i1 %cmp, label %for.body, label %for.exit
24 define void @foo2(i1 %arg) {
29 %phi = phi i64 [ 0, %entry ], [ %inc, %for.body ]
30 %x = getelementptr i32, <4 x ptr> undef, <4 x i32> <i32 1, i32 1, i32 1, i32 1>
31 %inc = add nuw nsw i64 %phi, 1
32 %cmp = icmp ult i64 %inc, 999
33 br i1 %cmp, label %for.body, label %for.exit
39 define void @cmp_undef(i1 %arg) {
43 for.body: ; preds = %for.inc, %entry
44 %iv.0 = phi i64 [ 0, %entry ], [ %iv.1, %for.inc ]
45 %arrayidx1 = getelementptr inbounds [10 x i32], ptr @known_constant, i64 0, i64 %iv.0
46 %x1 = load i32, ptr %arrayidx1, align 4
47 %cmp = icmp eq i32 %x1, undef
48 br i1 %cmp, label %if.then, label %for.inc
50 if.then: ; preds = %for.body
53 for.inc: ; preds = %for.body, %if.then
54 %iv.1 = add nuw nsw i64 %iv.0, 1
55 %exitcond = icmp eq i64 %iv.1, 10
56 br i1 %exitcond, label %for.end, label %for.body
58 for.end: ; preds = %for.inc
62 define void @switch(i1 %arg) {
67 %iv.0 = phi i64 [ 0, %entry ], [ %iv.1, %for.inc ]
68 %arrayidx1 = getelementptr inbounds [10 x i32], ptr @known_constant, i64 0, i64 %iv.0
69 %x1 = load i32, ptr %arrayidx1, align 4
70 switch i32 %x1, label %l1 [
78 %iv.1 = add nuw nsw i64 %iv.0, 1
79 %exitcond = icmp eq i64 %iv.1, 10
80 br i1 %exitcond, label %for.end, label %for.body
86 define <4 x i32> @vec_load(i1 %arg) {
91 %phi = phi i64 [ 0, %entry ], [ %inc, %for.body ]
92 %vec_phi = phi <4 x i32> [ <i32 0, i32 0, i32 0, i32 0>, %entry ], [ %r, %for.body ]
93 %arrayidx = getelementptr inbounds [10 x i32], ptr @known_constant, i64 0, i64 %phi
94 %x = load <4 x i32>, < 4 x i32>* %arrayidx, align 4
95 %r = add <4 x i32> %x, %vec_phi
96 %inc = add nuw nsw i64 %phi, 1
97 %cmp = icmp ult i64 %inc, 999
98 br i1 %cmp, label %for.body, label %for.exit
104 define void @ptrtoint_cast(i1 %arg) optsize {
109 br i1 true, label %for.inc, label %if.then
112 %x = ptrtoint ptr null to i64
116 br i1 false, label %for.body, label %for.cond.cleanup
122 define void @ptrtoint_cast2(i1 %arg) {
124 br i1 false, label %for.body.lr.ph, label %exit
130 %iv = phi i32 [ 0, %for.body.lr.ph ], [ %inc, %for.body ]
131 %offset = getelementptr inbounds float, ptr null, i32 3
132 %inc = add nuw nsw i32 %iv, 1
133 br i1 false, label %for.body, label %exit
139 @i = external global i32, align 4
141 define void @folded_not_to_constantint(i1 %arg) {
146 %iv = phi i32 [ 0, %entry ], [ %inc, %for.inc ]
147 %m = phi ptr [ @i, %entry ], [ %m, %for.inc ]
148 br i1 %arg, label %if.else, label %if.then
154 %cmp = icmp ult ptr %m, null
155 br i1 %cmp, label %cond.false, label %for.inc
161 %inc = add nuw nsw i32 %iv, 1
162 %cmp2 = icmp ult i32 %inc, 10
163 br i1 %cmp2, label %for.body, label %for.end
169 define void @index_too_large(i1 %arg) {
174 %iv = phi i64 [ -73631599, %entry ], [ %iv.next, %for.inc ]
175 br i1 %arg, label %for.body2, label %for.inc
178 %idx = getelementptr inbounds [10 x i32], ptr @known_constant, i64 0, i64 %iv
179 %x = load i32, ptr %idx, align 1
183 %iv.next = add nsw i64 %iv, -1
184 br i1 %arg, label %for.body, label %for.end
190 define void @cmp_type_mismatch(i1 %arg) {
198 %d = phi ptr [ null, %for.header ]
199 %cmp = icmp eq ptr %d, null
200 br i1 %arg, label %for.end, label %for.header
206 define void @load_type_mismatch() {
211 %iv.0 = phi i64 [ 0, %entry ], [ %iv.1, %for.body ]
212 %arrayidx1 = getelementptr inbounds [10 x i32], ptr @known_constant, i64 0, i64 %iv.0
213 %x1 = load i64, ptr %arrayidx1, align 4
214 %x2 = add i64 10, %x1
215 %iv.1 = add nuw nsw i64 %iv.0, 1
216 %exitcond = icmp eq i64 %iv.1, 10
217 br i1 %exitcond, label %for.end, label %for.body