blob: 57bac8560d4f3f26b9344fb2df3f3aa0a6bd7458 [file] [log] [blame]
Dehao Chen41d72a82016-11-17 01:17:02 +00001; RUN: opt < %s -S -loop-unroll -unroll-runtime -unroll-threshold=40 -unroll-dynamic-cost-savings-discount=0 | FileCheck %s
2
3@known_constant = internal unnamed_addr constant [9 x i32] [i32 0, i32 -1, i32 0, i32 -1, i32 5, i32 -1, i32 0, i32 -1, i32 0], align 16
4
5; CHECK-LABEL: @bar_prof
6; CHECK: loop.prol:
7; CHECK: loop:
8; CHECK: %mul = mul
9; CHECK: %mul.1 = mul
10; CHECK: %mul.2 = mul
11; CHECK: %mul.3 = mul
12define i32 @bar_prof(i32* noalias nocapture readonly %src, i64 %c) !prof !1 {
13entry:
14 br label %loop
15
16loop:
17 %iv = phi i64 [ 0, %entry ], [ %inc, %loop ]
18 %r = phi i32 [ 0, %entry ], [ %add, %loop ]
19 %arrayidx = getelementptr inbounds i32, i32* %src, i64 %iv
20 %src_element = load i32, i32* %arrayidx, align 4
21 %array_const_idx = getelementptr inbounds [9 x i32], [9 x i32]* @known_constant, i64 0, i64 %iv
22 %const_array_element = load i32, i32* %array_const_idx, align 4
23 %mul = mul nsw i32 %src_element, %const_array_element
24 %add = add nsw i32 %mul, %r
25 %inc = add nuw nsw i64 %iv, 1
26 %exitcond86.i = icmp eq i64 %inc, %c
27 br i1 %exitcond86.i, label %loop.end, label %loop, !prof !2
28
29loop.end:
30 %r.lcssa = phi i32 [ %r, %loop ]
31 ret i32 %r.lcssa
32}
33
34; CHECK-LABEL: @bar_prof_flat
35; CHECK-NOT: loop.prol
36define i32 @bar_prof_flat(i32* noalias nocapture readonly %src, i64 %c) !prof !1 {
37entry:
38 br label %loop
39
40loop:
41 %iv = phi i64 [ 0, %entry ], [ %inc, %loop ]
42 %r = phi i32 [ 0, %entry ], [ %add, %loop ]
43 %arrayidx = getelementptr inbounds i32, i32* %src, i64 %iv
44 %src_element = load i32, i32* %arrayidx, align 4
45 %array_const_idx = getelementptr inbounds [9 x i32], [9 x i32]* @known_constant, i64 0, i64 %iv
46 %const_array_element = load i32, i32* %array_const_idx, align 4
47 %mul = mul nsw i32 %src_element, %const_array_element
48 %add = add nsw i32 %mul, %r
49 %inc = add nuw nsw i64 %iv, 1
50 %exitcond86.i = icmp eq i64 %inc, %c
51 br i1 %exitcond86.i, label %loop, label %loop.end, !prof !2
52
53loop.end:
54 %r.lcssa = phi i32 [ %r, %loop ]
55 ret i32 %r.lcssa
56}
57
58!1 = !{!"function_entry_count", i64 1}
59!2 = !{!"branch_weights", i32 1, i32 1000}