255 lines · plain
1; RUN: opt %s -passes='print<scalar-evolution>' -scalar-evolution-classify-expressions=0 2>&1 | FileCheck %s2 3target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"4target triple = "x86_64-unknown-linux-gnu"5 6; A collection of tests focused on exercising logic to prove no-unsigned wrap7; from mustprogress semantics of loops.8 9; CHECK: Determining loop execution counts for: @test10; CHECK: Loop %for.body: backedge-taken count is ((-1 + (2 umax %N)) /u 2)11; CHECK: Determining loop execution counts for: @test_preinc12; CHECK: Loop %for.body: backedge-taken count is ((1 + %N) /u 2)13; CHECK: Determining loop execution counts for: @test_well_defined_infinite_st14; CHECK: Loop %for.body: Unpredictable backedge-taken count.15; CHECK: Determining loop execution counts for: @test_well_defined_infinite_ld16; CHECK: Loop %for.body: Unpredictable backedge-taken count.17; CHECK: Determining loop execution counts for: @test_no_mustprogress18; CHECK: Loop %for.body: Unpredictable backedge-taken count.19; CHECK: Determining loop execution counts for: @test_102420; CHECK: Loop %for.body: backedge-taken count is ((-1 + (1024 umax %N)) /u 1024)21; CHECK: Determining loop execution counts for: @test_uneven_divide22; CHECK: Loop %for.body: Unpredictable backedge-taken count.23; CHECK: Determining loop execution counts for: @test_non_invariant_rhs24; CHECK: Loop %for.body: Unpredictable backedge-taken count.25; CHECK: Determining loop execution counts for: @test_abnormal_exit26; CHECK: Loop %for.body: Unpredictable backedge-taken count.27; CHECK: Determining loop execution counts for: @test_other_exit28; CHECK: Loop %for.body: <multiple exits> Unpredictable backedge-taken count.29; CHECK: Determining loop execution counts for: @test_gt30; CHECK: Loop %for.body: Unpredictable backedge-taken count.31; CHECK: Determining loop execution counts for: @test_willreturn32; CHECK: Loop %for.body: backedge-taken count is ((-1 + (1024 umax %N)) /u 1024)33; CHECK: Determining loop execution counts for: @test_nowillreturn34; CHECK: Loop %for.body: Unpredictable backedge-taken count.35; TODO: investigate why willreturn is still needed on the callsite36; CHECK: Determining loop execution counts for: @test_willreturn_nocallsite37; CHECK: Loop %for.body: Unpredictable backedge-taken count.38 39define void @test(i32 %N) mustprogress {40entry:41 br label %for.body42 43for.body:44 %iv = phi i32 [ %iv.next, %for.body ], [ 0, %entry ]45 %iv.next = add i32 %iv, 246 %cmp = icmp ult i32 %iv.next, %N47 br i1 %cmp, label %for.body, label %for.cond.cleanup48 49for.cond.cleanup:50 ret void51}52 53define void @test_preinc(i32 %N) mustprogress {54entry:55 br label %for.body56 57for.body:58 %iv = phi i32 [ %iv.next, %for.body ], [ 0, %entry ]59 %iv.next = add i32 %iv, 260 %cmp = icmp ult i32 %iv, %N61 br i1 %cmp, label %for.body, label %for.cond.cleanup62 63for.cond.cleanup:64 ret void65 66}67 68@G = external global i3269 70define void @test_well_defined_infinite_st(i32 %N) mustprogress {71entry:72 br label %for.body73 74for.body:75 %iv = phi i32 [ %iv.next, %for.body ], [ 0, %entry ]76 %iv.next = add i32 %iv, 277 store volatile i32 0, ptr @G78 %cmp = icmp ult i32 %iv.next, %N79 br i1 %cmp, label %for.body, label %for.cond.cleanup80 81for.cond.cleanup:82 ret void83}84 85define void @test_well_defined_infinite_ld(i32 %N) mustprogress {86entry:87 br label %for.body88 89for.body:90 %iv = phi i32 [ %iv.next, %for.body ], [ 0, %entry ]91 %iv.next = add i32 %iv, 292 %val = load volatile i32, ptr @G93 %cmp = icmp ult i32 %iv.next, %N94 br i1 %cmp, label %for.body, label %for.cond.cleanup95 96for.cond.cleanup:97 ret void98}99 100define void @test_no_mustprogress(i32 %N) {101entry:102 br label %for.body103 104for.body:105 %iv = phi i32 [ %iv.next, %for.body ], [ 0, %entry ]106 %iv.next = add i32 %iv, 2107 %cmp = icmp ult i32 %iv.next, %N108 br i1 %cmp, label %for.body, label %for.cond.cleanup109 110for.cond.cleanup:111 ret void112 113}114 115 116define void @test_1024(i32 %N) mustprogress {117entry:118 br label %for.body119 120for.body:121 %iv = phi i32 [ %iv.next, %for.body ], [ 0, %entry ]122 %iv.next = add i32 %iv, 1024123 %cmp = icmp ult i32 %iv.next, %N124 br i1 %cmp, label %for.body, label %for.cond.cleanup125 126for.cond.cleanup:127 ret void128}129 130define void @test_uneven_divide(i32 %N) mustprogress {131entry:132 br label %for.body133 134for.body:135 %iv = phi i32 [ %iv.next, %for.body ], [ 0, %entry ]136 %iv.next = add i32 %iv, 3137 %cmp = icmp ult i32 %iv.next, %N138 br i1 %cmp, label %for.body, label %for.cond.cleanup139 140for.cond.cleanup:141 ret void142}143 144define void @test_non_invariant_rhs() mustprogress {145entry:146 br label %for.body147 148for.body:149 %iv = phi i32 [ %iv.next, %for.body ], [ 0, %entry ]150 %iv.next = add i32 %iv, 2151 %N = load i32, ptr @G152 %cmp = icmp ult i32 %iv.next, %N153 br i1 %cmp, label %for.body, label %for.cond.cleanup154 155for.cond.cleanup:156 ret void157}158 159declare void @mayexit()160 161define void @test_abnormal_exit(i32 %N) mustprogress {162entry:163 br label %for.body164 165for.body:166 %iv = phi i32 [ %iv.next, %for.body ], [ 0, %entry ]167 %iv.next = add i32 %iv, 2168 call void @mayexit()169 %cmp = icmp ult i32 %iv.next, %N170 br i1 %cmp, label %for.body, label %for.cond.cleanup171 172for.cond.cleanup:173 ret void174}175 176 177define void @test_other_exit(i32 %N) mustprogress {178entry:179 br label %for.body180 181for.body:182 %iv = phi i32 [ %iv.next, %for.latch ], [ 0, %entry ]183 %iv.next = add i32 %iv, 2184 %cmp1 = icmp ult i32 %iv.next, 20185 br i1 %cmp1, label %for.latch, label %for.cond.cleanup186 187for.latch:188 %cmp2 = icmp ult i32 %iv.next, %N189 br i1 %cmp2, label %for.body, label %for.cond.cleanup190 191for.cond.cleanup:192 ret void193}194 195define void @test_gt(i32 %S, i32 %N) mustprogress {196entry:197 br label %for.body198 199for.body:200 %iv = phi i32 [ %iv.next, %for.body ], [ %S, %entry ]201 %iv.next = add i32 %iv, -2202 %cmp = icmp ugt i32 %iv.next, %N203 br i1 %cmp, label %for.body, label %for.cond.cleanup204 205for.cond.cleanup:206 ret void207}208 209declare void @sideeffect()210 211define void @test_willreturn(i32 %S, i32 %N) willreturn {212entry:213 br label %for.body214 215for.body:216 %iv = phi i32 [ %iv.next, %for.body ], [ 0, %entry ]217 %iv.next = add i32 %iv, 1024218 call void @sideeffect() nounwind willreturn219 %cmp = icmp ult i32 %iv.next, %N220 br i1 %cmp, label %for.body, label %for.cond.cleanup221 222for.cond.cleanup:223 ret void224}225 226define void @test_nowillreturn(i32 %S, i32 %N) {227entry:228 br label %for.body229 230for.body:231 %iv = phi i32 [ %iv.next, %for.body ], [ 0, %entry ]232 %iv.next = add i32 %iv, 1024233 call void @sideeffect() nounwind willreturn234 %cmp = icmp ult i32 %iv.next, %N235 br i1 %cmp, label %for.body, label %for.cond.cleanup236 237for.cond.cleanup:238 ret void239}240 241define void @test_willreturn_nocallsite(i32 %S, i32 %N) willreturn {242entry:243 br label %for.body244 245for.body:246 %iv = phi i32 [ %iv.next, %for.body ], [ 0, %entry ]247 %iv.next = add i32 %iv, 1024248 call void @sideeffect() nounwind249 %cmp = icmp ult i32 %iv.next, %N250 br i1 %cmp, label %for.body, label %for.cond.cleanup251 252for.cond.cleanup:253 ret void254}255