1 ; RUN: opt -S -unroll-runtime -loop-unroll < %s | FileCheck %s
3 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-S128"
5 ;; Check that we don't emit expensive instructions to compute trip
6 ;; counts when unrolling loops.
8 define i32 @test(i64 %v12, i8* %array, i64* %loc) {
12 %step = load i64, i64* %loc, !range !0
15 loop: ; preds = %entry, %loop
16 %k.015 = phi i64 [ %v15, %loop ], [ %v12, %entry ]
17 %v14 = getelementptr inbounds i8, i8* %array, i64 %k.015
19 %v15 = add nuw nsw i64 %k.015, %step
20 %v16 = icmp slt i64 %v15, 8193
21 br i1 %v16, label %loop, label %loopexit
23 loopexit: ; preds = %loop
27 ;; Though SCEV for loop tripcount contains division,
28 ;; it shouldn't be considered expensive, since the division already
29 ;; exists in the code and we don't need to expand it once more.
30 ;; Thus, it shouldn't prevent us from unrolling the loop.
32 define i32 @test2(i64* %loc, i64 %conv7) {
33 ; CHECK-LABEL: @test2(
37 ; CHECK-LABEL: for.body
39 %rem0 = load i64, i64* %loc, align 8
40 %ExpensiveComputation = udiv i64 %rem0, 42 ; <<< Extra computations are added to the trip-count expression
43 %div11 = udiv i64 %ExpensiveComputation, %conv7
44 %cmp.i38 = icmp ugt i64 %div11, 1
45 %div12 = select i1 %cmp.i38, i64 %div11, i64 1
48 %rem1 = phi i64 [ %rem0, %bb1 ], [ %rem2, %for.body ]
49 %k1 = phi i64 [ %div12, %bb1 ], [ %dec, %for.body ]
50 %mul1 = mul i64 %rem1, 48271
51 %rem2 = urem i64 %mul1, 2147483647
52 %dec = add i64 %k1, -1
53 %cmp = icmp eq i64 %dec, 0
54 br i1 %cmp, label %exit, label %for.body
56 %rem3 = phi i64 [ %rem2, %for.body ]
57 store i64 %rem3, i64* %loc, align 8
61 !0 = !{i64 1, i64 100}