1; RUN: opt < %s -passes=pgo-instr-gen -pgo-instrument-entry=false -S | FileCheck %s --check-prefixes=GEN,NOTENTRY
2; RUN: llvm-profdata merge %S/Inputs/loop2.proftext -o %t.profdata
3; RUN: opt < %s -passes=pgo-instr-use -pgo-instrument-entry=false -pgo-test-profile-file=%t.profdata -S | FileCheck %s --check-prefix=USE
4; RUN: opt < %s -passes=pgo-instr-gen -pgo-instrument-entry=true -S | FileCheck %s --check-prefixes=GEN,ENTRY
5; RUN: llvm-profdata merge %S/Inputs/loop2_entry.proftext -o %t.profdata
6; RUN: opt < %s -passes=pgo-instr-use -pgo-instrument-entry=true -pgo-test-profile-file=%t.profdata -S | FileCheck %s --check-prefix=USE
7target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
8target triple = "x86_64-unknown-linux-gnu"
9
10; GEN: $__llvm_profile_raw_version = comdat any
11; GEN: @__llvm_profile_raw_version = constant i64 {{[0-9]+}}, comdat
12; GEN: @__profn_test_nested_for = private constant [15 x i8] c"test_nested_for"
13
14define i32 @test_nested_for(i32 %r, i32 %s) {
15entry:
16; GEN: entry:
17; NOTENTRY: call void @llvm.instrprof.increment(ptr @__profn_test_nested_for, i64 {{[0-9]+}}, i32 3, i32 2)
18; ENTRY: call void @llvm.instrprof.increment(ptr @__profn_test_nested_for, i64 {{[0-9]+}}, i32 3, i32 0)
19  br label %for.cond.outer
20
21for.cond.outer:
22; GEN: for.cond.outer:
23; GEN-NOT: call void @llvm.instrprof.increment
24  %i.0 = phi i32 [ 0, %entry ], [ %inc.2, %for.inc.outer ]
25  %sum.0 = phi i32 [ 1, %entry ], [ %sum.1, %for.inc.outer ]
26  %cmp = icmp slt i32 %i.0, %r
27  br i1 %cmp, label %for.body.outer, label %for.end.outer
28; USE: br i1 %cmp, label %for.body.outer, label %for.end.outer
29; USE-SAME: !prof ![[BW_FOR_COND_OUTER:[0-9]+]]
30
31for.body.outer:
32; GEN: for.body.outer:
33; GEN-NOT: call void @llvm.instrprof.increment
34  br label %for.cond.inner
35
36for.cond.inner:
37; GEN: for.cond.inner:
38; GEN-NOT: call void @llvm.instrprof.increment
39  %j.0 = phi i32 [ 0, %for.body.outer ], [ %inc.1, %for.inc.inner ]
40  %sum.1 = phi i32 [ %sum.0, %for.body.outer ], [ %inc, %for.inc.inner ]
41  %cmp2 = icmp slt i32 %j.0, %s
42  br i1 %cmp2, label %for.body.inner, label %for.end.inner
43; USE: br i1 %cmp2, label %for.body.inner, label %for.end.inner
44; USE-SAME: !prof ![[BW_FOR_COND_INNER:[0-9]+]]
45
46for.body.inner:
47; GEN: for.body.inner:
48; GEN-NOT: call void @llvm.instrprof.increment
49  %inc = add nsw i32 %sum.1, 1
50  br label %for.inc.inner
51
52for.inc.inner:
53; GEN: for.inc.inner:
54; NOTENTRY: call void @llvm.instrprof.increment(ptr @__profn_test_nested_for, i64 {{[0-9]+}}, i32 3, i32 0)
55; ENTRY: call void @llvm.instrprof.increment(ptr @__profn_test_nested_for, i64 {{[0-9]+}}, i32 3, i32 1)
56  %inc.1 = add nsw i32 %j.0, 1
57  br label %for.cond.inner
58
59for.end.inner:
60; GEN: for.end.inner:
61  br label %for.inc.outer
62
63for.inc.outer:
64; GEN: for.inc.outer:
65; NOTENTRY: call void @llvm.instrprof.increment(ptr @__profn_test_nested_for, i64 {{[0-9]+}}, i32 3, i32 1)
66; ENTRY: call void @llvm.instrprof.increment(ptr @__profn_test_nested_for, i64 {{[0-9]+}}, i32 3, i32 2)
67  %inc.2 = add nsw i32 %i.0, 1
68  br label %for.cond.outer
69
70for.end.outer:
71; GEN: for.end.outer:
72; GEN-NOT: call void @llvm.instrprof.increment
73; GEN: ret i32
74  ret i32 %sum.0
75}
76
77; USE-DAG: ![[BW_FOR_COND_OUTER]] = !{!"branch_weights", i32 10, i32 6}
78; USE-DAG: ![[BW_FOR_COND_INNER]] = !{!"branch_weights", i32 33, i32 10}
79
80