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
7 target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
8 target triple = "x86_64-unknown-linux-gnu"
10 ; GEN: $__llvm_profile_raw_version = comdat any
11 ; GEN: @__llvm_profile_raw_version = hidden constant i64 {{[0-9]+}}, comdat
12 ; GEN: @__profn_test_nested_for = private constant [15 x i8] c"test_nested_for"
14 define i32 @test_nested_for(i32 %r, i32 %s) {
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
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]+]]
32 ; GEN: for.body.outer:
33 ; NOTENTRY: call void @llvm.instrprof.increment(ptr @__profn_test_nested_for, i64 798733566382720768, i32 3, i32 1)
34 ; ENTRY: call void @llvm.instrprof.increment(ptr @__profn_test_nested_for, i64 798733566382720768, i32 3, i32 2)
35 br label %for.cond.inner
38 ; GEN: for.cond.inner:
39 ; GEN-NOT: call void @llvm.instrprof.increment
40 %j.0 = phi i32 [ 0, %for.body.outer ], [ %inc.1, %for.inc.inner ]
41 %sum.1 = phi i32 [ %sum.0, %for.body.outer ], [ %inc, %for.inc.inner ]
42 %cmp2 = icmp slt i32 %j.0, %s
43 br i1 %cmp2, label %for.body.inner, label %for.end.inner
44 ; USE: br i1 %cmp2, label %for.body.inner, label %for.end.inner
45 ; USE-SAME: !prof ![[BW_FOR_COND_INNER:[0-9]+]]
48 ; GEN: for.body.inner:
49 ; GEN-NOT: call void @llvm.instrprof.increment
50 %inc = add nsw i32 %sum.1, 1
51 br label %for.inc.inner
55 ; NOTENTRY: call void @llvm.instrprof.increment(ptr @__profn_test_nested_for, i64 {{[0-9]+}}, i32 3, i32 0)
56 ; ENTRY: call void @llvm.instrprof.increment(ptr @__profn_test_nested_for, i64 {{[0-9]+}}, i32 3, i32 1)
57 %inc.1 = add nsw i32 %j.0, 1
58 br label %for.cond.inner
62 br label %for.inc.outer
66 ; GEN-NOT: call void @llvm.instrprof.increment
67 %inc.2 = add nsw i32 %i.0, 1
68 br label %for.cond.outer
72 ; GEN-NOT: call void @llvm.instrprof.increment
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}