1 ; Check that we don't crash on corner cases.
2 ; RUN: opt < %s -S -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(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
13 %phi = phi i64 [ 0, %entry ], [ %inc, %for.body ]
14 %idx = zext i32 undef to i64
15 %add.ptr = getelementptr inbounds i64, i64* 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
29 %phi = phi i64 [ 0, %entry ], [ %inc, %for.body ]
30 %x = getelementptr i32, <4 x i32*> 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() {
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], [10 x i32]* @known_constant, i64 0, i64 %iv.0
46 %x1 = load i32, i32* %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() {
67 %iv.0 = phi i64 [ 0, %entry ], [ %iv.1, %for.inc ]
68 %arrayidx1 = getelementptr inbounds [10 x i32], [10 x i32]* @known_constant, i64 0, i64 %iv.0
69 %x1 = load i32, i32* %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() {
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], [10 x i32]* @known_constant, i64 0, i64 %phi
94 %bc = bitcast i32* %arrayidx to <4 x i32>*
95 %x = load <4 x i32>, < 4 x i32>* %bc, align 4
96 %r = add <4 x i32> %x, %vec_phi
97 %inc = add nuw nsw i64 %phi, 1
98 %cmp = icmp ult i64 %inc, 999
99 br i1 %cmp, label %for.body, label %for.exit
105 define void @ptrtoint_cast() optsize {
110 br i1 true, label %for.inc, label %if.then
113 %arraydecay = getelementptr inbounds [1 x i32], [1 x i32]* null, i64 0, i64 0
114 %x = ptrtoint i32* %arraydecay to i64
118 br i1 false, label %for.body, label %for.cond.cleanup
124 define void @ptrtoint_cast2() {
126 br i1 false, label %for.body.lr.ph, label %exit
132 %iv = phi i32 [ 0, %for.body.lr.ph ], [ %inc, %for.body ]
133 %offset = getelementptr inbounds float, float* null, i32 3
134 %bc = bitcast float* %offset to i64*
135 %inc = add nuw nsw i32 %iv, 1
136 br i1 false, label %for.body, label %exit
142 @i = external global i32, align 4
144 define void @folded_not_to_constantint() {
149 %iv = phi i32 [ 0, %entry ], [ %inc, %for.inc ]
150 %m = phi i32* [ @i, %entry ], [ %m, %for.inc ]
151 br i1 undef, label %if.else, label %if.then
157 %cmp = icmp ult i32* %m, null
158 br i1 %cmp, label %cond.false, label %for.inc
164 %inc = add nuw nsw i32 %iv, 1
165 %cmp2 = icmp ult i32 %inc, 10
166 br i1 %cmp2, label %for.body, label %for.end
172 define void @index_too_large() {
177 %iv = phi i64 [ -73631599, %entry ], [ %iv.next, %for.inc ]
178 br i1 undef, label %for.body2, label %for.inc
181 %idx = getelementptr inbounds [10 x i32], [10 x i32]* @known_constant, i64 0, i64 %iv
182 %x = load i32, i32* %idx, align 1
186 %iv.next = add nsw i64 %iv, -1
187 br i1 undef, label %for.body, label %for.end
193 define void @cmp_type_mismatch() {
201 %d = phi i32* [ null, %for.header ]
202 %cmp = icmp eq i32* %d, null
203 br i1 undef, label %for.end, label %for.header
209 define void @load_type_mismatch() {
214 %iv.0 = phi i64 [ 0, %entry ], [ %iv.1, %for.body ]
215 %arrayidx1 = getelementptr inbounds [10 x i32], [10 x i32]* @known_constant, i64 0, i64 %iv.0
216 %bc = bitcast i32* %arrayidx1 to i64*
217 %x1 = load i64, i64* %bc, align 4
218 %x2 = add i64 10, %x1
219 %iv.1 = add nuw nsw i64 %iv.0, 1
220 %exitcond = icmp eq i64 %iv.1, 10
221 br i1 %exitcond, label %for.end, label %for.body