1 ; RUN: opt %s -passes='print<scalar-evolution>' -scalar-evolution-classify-expressions=0 2>&1 | FileCheck %s
3 target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
4 target triple = "x86_64-unknown-linux-gnu"
6 ; A collection of tests focused on exercising logic to prove no-unsigned wrap
7 ; from mustprogress semantics of loops.
9 ; CHECK: Determining loop execution counts for: @test
10 ; CHECK: Loop %for.body: backedge-taken count is ((-1 + (2 umax %N)) /u 2)
11 ; CHECK: Determining loop execution counts for: @test_preinc
12 ; CHECK: Loop %for.body: backedge-taken count is ((1 + %N) /u 2)
13 ; CHECK: Determining loop execution counts for: @test_well_defined_infinite_st
14 ; CHECK: Loop %for.body: Unpredictable backedge-taken count.
15 ; CHECK: Determining loop execution counts for: @test_well_defined_infinite_ld
16 ; CHECK: Loop %for.body: Unpredictable backedge-taken count.
17 ; CHECK: Determining loop execution counts for: @test_no_mustprogress
18 ; CHECK: Loop %for.body: Unpredictable backedge-taken count.
19 ; CHECK: Determining loop execution counts for: @test_1024
20 ; CHECK: Loop %for.body: backedge-taken count is ((-1 + (1024 umax %N)) /u 1024)
21 ; CHECK: Determining loop execution counts for: @test_uneven_divide
22 ; CHECK: Loop %for.body: Unpredictable backedge-taken count.
23 ; CHECK: Determining loop execution counts for: @test_non_invariant_rhs
24 ; CHECK: Loop %for.body: Unpredictable backedge-taken count.
25 ; CHECK: Determining loop execution counts for: @test_abnormal_exit
26 ; CHECK: Loop %for.body: Unpredictable backedge-taken count.
27 ; CHECK: Determining loop execution counts for: @test_other_exit
28 ; CHECK: Loop %for.body: <multiple exits> Unpredictable backedge-taken count.
29 ; CHECK: Determining loop execution counts for: @test_gt
30 ; CHECK: Loop %for.body: Unpredictable backedge-taken count.
32 define void @test(i32 %N) mustprogress {
37 %iv = phi i32 [ %iv.next, %for.body ], [ 0, %entry ]
38 %iv.next = add i32 %iv, 2
39 %cmp = icmp ult i32 %iv.next, %N
40 br i1 %cmp, label %for.body, label %for.cond.cleanup
46 define void @test_preinc(i32 %N) mustprogress {
51 %iv = phi i32 [ %iv.next, %for.body ], [ 0, %entry ]
52 %iv.next = add i32 %iv, 2
53 %cmp = icmp ult i32 %iv, %N
54 br i1 %cmp, label %for.body, label %for.cond.cleanup
61 @G = external global i32
63 define void @test_well_defined_infinite_st(i32 %N) mustprogress {
68 %iv = phi i32 [ %iv.next, %for.body ], [ 0, %entry ]
69 %iv.next = add i32 %iv, 2
70 store volatile i32 0, i32* @G
71 %cmp = icmp ult i32 %iv.next, %N
72 br i1 %cmp, label %for.body, label %for.cond.cleanup
78 define void @test_well_defined_infinite_ld(i32 %N) mustprogress {
83 %iv = phi i32 [ %iv.next, %for.body ], [ 0, %entry ]
84 %iv.next = add i32 %iv, 2
85 %val = load volatile i32, i32* @G
86 %cmp = icmp ult i32 %iv.next, %N
87 br i1 %cmp, label %for.body, label %for.cond.cleanup
93 define void @test_no_mustprogress(i32 %N) {
98 %iv = phi i32 [ %iv.next, %for.body ], [ 0, %entry ]
99 %iv.next = add i32 %iv, 2
100 %cmp = icmp ult i32 %iv.next, %N
101 br i1 %cmp, label %for.body, label %for.cond.cleanup
109 define void @test_1024(i32 %N) mustprogress {
114 %iv = phi i32 [ %iv.next, %for.body ], [ 0, %entry ]
115 %iv.next = add i32 %iv, 1024
116 %cmp = icmp ult i32 %iv.next, %N
117 br i1 %cmp, label %for.body, label %for.cond.cleanup
123 define void @test_uneven_divide(i32 %N) mustprogress {
128 %iv = phi i32 [ %iv.next, %for.body ], [ 0, %entry ]
129 %iv.next = add i32 %iv, 3
130 %cmp = icmp ult i32 %iv.next, %N
131 br i1 %cmp, label %for.body, label %for.cond.cleanup
137 define void @test_non_invariant_rhs() mustprogress {
142 %iv = phi i32 [ %iv.next, %for.body ], [ 0, %entry ]
143 %iv.next = add i32 %iv, 2
144 %N = load i32, i32* @G
145 %cmp = icmp ult i32 %iv.next, %N
146 br i1 %cmp, label %for.body, label %for.cond.cleanup
152 declare void @mayexit()
154 define void @test_abnormal_exit(i32 %N) mustprogress {
159 %iv = phi i32 [ %iv.next, %for.body ], [ 0, %entry ]
160 %iv.next = add i32 %iv, 2
162 %cmp = icmp ult i32 %iv.next, %N
163 br i1 %cmp, label %for.body, label %for.cond.cleanup
170 define void @test_other_exit(i32 %N) mustprogress {
175 %iv = phi i32 [ %iv.next, %for.latch ], [ 0, %entry ]
176 %iv.next = add i32 %iv, 2
177 %cmp1 = icmp ult i32 %iv.next, 20
178 br i1 %cmp1, label %for.latch, label %for.cond.cleanup
181 %cmp2 = icmp ult i32 %iv.next, %N
182 br i1 %cmp2, label %for.body, label %for.cond.cleanup
188 define void @test_gt(i32 %S, i32 %N) mustprogress {
193 %iv = phi i32 [ %iv.next, %for.body ], [ %S, %entry ]
194 %iv.next = add i32 %iv, -2
195 %cmp = icmp ugt i32 %iv.next, %N
196 br i1 %cmp, label %for.body, label %for.cond.cleanup