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