xref: /llvm-project/llvm/test/Transforms/PGOProfile/loop_entries_gen.ll (revision ff281f7d37ead15bdbdbfccb4b82ea93013b1a00)
1*ff281f7dSronryvchin; RUN: opt %s -passes=pgo-instr-gen -S | FileCheck %s --check-prefixes=CHECK,NOTLOOPENTRIES --implicit-check-not=@llvm.instrprof.increment
2*ff281f7dSronryvchin; RUN: opt %s -passes=pgo-instr-gen -pgo-instrument-loop-entries -S | FileCheck %s --check-prefixes=CHECK,LOOPENTRIES --implicit-check-not=@llvm.instrprof.increment
3*ff281f7dSronryvchin; RUN: opt %s -passes=pgo-instr-gen -pgo-instrument-entry -S | FileCheck %s --check-prefixes=CHECK,FUNCTIONENTRY --implicit-check-not=@llvm.instrprof.increment
4*ff281f7dSronryvchin
5*ff281f7dSronryvchin; CHECK: $__llvm_profile_raw_version = comdat any
6*ff281f7dSronryvchin; CHECK: @__llvm_profile_raw_version = hidden constant i64 {{[0-9]+}}, comdat
7*ff281f7dSronryvchin; CHECK: @__profn_test_simple_for_with_bypass = private constant [27 x i8] c"test_simple_for_with_bypass"
8*ff281f7dSronryvchin
9*ff281f7dSronryvchindefine i32 @test_simple_for_with_bypass(i32 %n) {
10*ff281f7dSronryvchinentry:
11*ff281f7dSronryvchin; CHECK: entry:
12*ff281f7dSronryvchin; NOTLOOPENTRIES: call void @llvm.instrprof.increment(ptr @__profn_test_simple_for_with_bypass, i64 {{[0-9]+}}, i32 3, i32 1)
13*ff281f7dSronryvchin; LOOPENTRIES: call void @llvm.instrprof.increment(ptr @__profn_test_simple_for_with_bypass, i64 {{[0-9]+}}, i32 3, i32 1)
14*ff281f7dSronryvchin; FUNCTIONENTRY: call void @llvm.instrprof.increment(ptr @__profn_test_simple_for_with_bypass, i64 {{[0-9]+}}, i32 3, i32 0)
15*ff281f7dSronryvchin  %mask = and i32 %n, 65535
16*ff281f7dSronryvchin  %skip = icmp eq i32 %mask, 0
17*ff281f7dSronryvchin  br i1 %skip, label %end, label %for.entry
18*ff281f7dSronryvchin
19*ff281f7dSronryvchinfor.entry:
20*ff281f7dSronryvchin; CHECK: for.entry:
21*ff281f7dSronryvchin; LOOPENTRIES: call void @llvm.instrprof.increment(ptr @__profn_test_simple_for_with_bypass, i64 {{[0-9]+}}, i32 3, i32 2)
22*ff281f7dSronryvchin  br label %for.cond
23*ff281f7dSronryvchin
24*ff281f7dSronryvchinfor.cond:
25*ff281f7dSronryvchin; CHECK: for.cond:
26*ff281f7dSronryvchin  %i = phi i32 [ 0, %for.entry ], [ %inc1, %for.inc ]
27*ff281f7dSronryvchin  %sum = phi i32 [ 1, %for.entry ], [ %inc, %for.inc ]
28*ff281f7dSronryvchin  %cmp = icmp slt i32 %i, %n
29*ff281f7dSronryvchin  br i1 %cmp, label %for.body, label %for.end, !prof !1
30*ff281f7dSronryvchin
31*ff281f7dSronryvchinfor.body:
32*ff281f7dSronryvchin; CHECK: for.body:
33*ff281f7dSronryvchin  %inc = add nsw i32 %sum, 1
34*ff281f7dSronryvchin  br label %for.inc
35*ff281f7dSronryvchin
36*ff281f7dSronryvchinfor.inc:
37*ff281f7dSronryvchin; CHECK: for.inc:
38*ff281f7dSronryvchin; NOTLOOPENTRIES: call void @llvm.instrprof.increment(ptr @__profn_test_simple_for_with_bypass, i64 {{[0-9]+}}, i32 3, i32 0)
39*ff281f7dSronryvchin; LOOPENTRIES: call void @llvm.instrprof.increment(ptr @__profn_test_simple_for_with_bypass, i64 {{[0-9]+}}, i32 3, i32 0)
40*ff281f7dSronryvchin; FUNCTIONENTRY: call void @llvm.instrprof.increment(ptr @__profn_test_simple_for_with_bypass, i64 {{[0-9]+}}, i32 3, i32 1)
41*ff281f7dSronryvchin  %inc1 = add nsw i32 %i, 1
42*ff281f7dSronryvchin  br label %for.cond
43*ff281f7dSronryvchin
44*ff281f7dSronryvchinfor.end:
45*ff281f7dSronryvchin; CHECK: for.end:
46*ff281f7dSronryvchin; NOTLOOPENTRIES: call void @llvm.instrprof.increment(ptr @__profn_test_simple_for_with_bypass, i64 {{[0-9]+}}, i32 3, i32 2)
47*ff281f7dSronryvchin; FUNCTIONENTRY: call void @llvm.instrprof.increment(ptr @__profn_test_simple_for_with_bypass, i64 {{[0-9]+}}, i32 3, i32 2)
48*ff281f7dSronryvchin  br label %end
49*ff281f7dSronryvchin
50*ff281f7dSronryvchinend:
51*ff281f7dSronryvchin; CHECK: end:
52*ff281f7dSronryvchin  %final_sum = phi i32 [ %sum, %for.end ], [ 0, %entry ]
53*ff281f7dSronryvchin  ret i32 %final_sum
54*ff281f7dSronryvchin}
55*ff281f7dSronryvchin
56*ff281f7dSronryvchin; CHECK: declare void @llvm.instrprof.increment(ptr, i64, i32, i32) #0
57*ff281f7dSronryvchin
58*ff281f7dSronryvchin!1 = !{!"branch_weights", i32 100000, i32 80}
59