• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1; RUN: opt < %s -pgo-instr-gen -pgo-instrument-entry=false -S | FileCheck %s --check-prefix=GEN
2; RUN: opt < %s -passes=pgo-instr-gen -pgo-instrument-entry=false -S | FileCheck %s --check-prefix=GEN
3; RUN: llvm-profdata merge %S/Inputs/criticaledge.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;
7; RUN: opt < %s -pgo-instr-gen -pgo-instrument-entry=true -S | FileCheck %s --check-prefix=GEN
8; RUN: opt < %s -passes=pgo-instr-gen -pgo-instrument-entry=true -S | FileCheck %s --check-prefix=GEN
9; RUN: llvm-profdata merge %S/Inputs/criticaledge_entry.proftext -o %t2.profdata
10; RUN: opt < %s -pgo-instr-use -pgo-instrument-entry=true -pgo-test-profile-file=%t2.profdata -S | FileCheck %s --check-prefix=USE
11; RUN: opt < %s -passes=pgo-instr-use -pgo-instrument-entry=true -pgo-test-profile-file=%t2.profdata -S | FileCheck %s --check-prefix=USE
12target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
13target triple = "x86_64-unknown-linux-gnu"
14
15; GEN: $__llvm_profile_raw_version = comdat any
16; GEN: @__llvm_profile_raw_version = constant i64 {{[0-9]+}}, comdat
17; GEN: @__profn_test_criticalEdge = private constant [17 x i8] c"test_criticalEdge"
18; GEN: @__profn__stdin__bar = private constant [11 x i8] c"<stdin>:bar"
19
20define i32 @test_criticalEdge(i32 %i, i32 %j) {
21entry:
22; CHECK: entry:
23; NOTENTRY-NOT: call void @llvm.instrprof.increment
24; ENTRY:   call void @llvm.instrprof.increment(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @__profn_test_criticalEdge, i32 0, i32 0), i64 {{[0-9]+}}, i32 8, i32 0)
25  switch i32 %i, label %sw.default [
26    i32 1, label %sw.bb
27    i32 2, label %sw.bb1
28    i32 3, label %sw.bb2
29    i32 4, label %sw.bb2
30; CHECK:    i32 3, label %entry.sw.bb2_crit_edge
31; CHECK:    i32 4, label %entry.sw.bb2_crit_edge1
32    i32 5, label %sw.bb2
33  ]
34; USE: ]
35; USE-SAME: !prof ![[BW_SWITCH:[0-9]+]]
36
37; CHECK: entry.sw.bb2_crit_edge1:
38; NOTENTRY:   call void @llvm.instrprof.increment(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @__profn_test_criticalEdge, i32 0, i32 0), i64 {{[0-9]+}}, i32 8, i32 1)
39; ENTRY: call void @llvm.instrprof.increment(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @__profn_test_criticalEdge, i32 0, i32 0), i64 {{[0-9]+}}, i32 8, i32 2)
40; CHECK:   br label %sw.bb2
41
42; CHECK: entry.sw.bb2_crit_edge:
43; NOTENTRY:   call void @llvm.instrprof.increment(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @__profn_test_criticalEdge, i32 0, i32 0), i64 {{[0-9]+}}, i32 8, i32 0)
44; TENTRY:   call void @llvm.instrprof.increment(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @__profn_test_criticalEdge, i32 0, i32 0), i64 {{[0-9]+}}, i32 8, i32 1)
45; CHECK:   br label %sw.bb2
46
47sw.bb:
48; GEN: sw.bb:
49; GEN: call void @llvm.instrprof.increment(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @__profn_test_criticalEdge, i32 0, i32 0), i64 {{[0-9]+}}, i32 8, i32 5)
50  %call = call i32 @bar(i32 2)
51  br label %sw.epilog
52
53sw.bb1:
54; GEN: sw.bb1:
55; GEN: call void @llvm.instrprof.increment(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @__profn_test_criticalEdge, i32 0, i32 0), i64 {{[0-9]+}}, i32 8, i32 4)
56  %call2 = call i32 @bar(i32 1024)
57  br label %sw.epilog
58
59sw.bb2:
60; GEN: sw.bb2:
61; GEN-NOT: call void @llvm.instrprof.increment
62  %cmp = icmp eq i32 %j, 2
63  br i1 %cmp, label %if.then, label %if.end
64; USE: br i1 %cmp, label %if.then, label %if.end
65; USE-SAME: !prof ![[BW_SW_BB2:[0-9]+]]
66
67if.then:
68; GEN: if.then:
69; NOTENTRY: call void @llvm.instrprof.increment(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @__profn_test_criticalEdge, i32 0, i32 0), i64 {{[0-9]+}}, i32 8, i32 2)
70; ENTRY-NOT: call void @llvm.instrprof.increment
71  %call4 = call i32 @bar(i32 4)
72  br label %return
73
74if.end:
75; GEN: if.end:
76; GEN: call void @llvm.instrprof.increment(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @__profn_test_criticalEdge, i32 0, i32 0), i64 {{[0-9]+}}, i32 8, i32 3)
77  %call5 = call i32 @bar(i32 8)
78  br label %sw.epilog
79
80sw.default:
81; GEN: sw.default:
82; GEN-NOT: call void @llvm.instrprof.increment
83  %call6 = call i32 @bar(i32 32)
84  %cmp7 = icmp sgt i32 %j, 10
85  br i1 %cmp7, label %if.then8, label %if.end9
86; USE: br i1 %cmp7, label %if.then8, label %if.end9
87; USE-SAME: !prof ![[BW_SW_DEFAULT:[0-9]+]]
88
89if.then8:
90; GEN: if.then8:
91; GEN: call void @llvm.instrprof.increment(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @__profn_test_criticalEdge, i32 0, i32 0), i64 {{[0-9]+}}, i32 8, i32 7)
92  %add = add nsw i32 %call6, 10
93  br label %if.end9
94
95if.end9:
96; GEN: if.end9:
97; GEN: call void @llvm.instrprof.increment(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @__profn_test_criticalEdge, i32 0, i32 0), i64 {{[0-9]+}}, i32 8, i32 6)
98  %res.0 = phi i32 [ %add, %if.then8 ], [ %call6, %sw.default ]
99  br label %sw.epilog
100
101sw.epilog:
102; GEN: sw.epilog:
103; GEN-NOT: call void @llvm.instrprof.increment
104  %res.1 = phi i32 [ %res.0, %if.end9 ], [ %call5, %if.end ], [ %call2, %sw.bb1 ], [ %call, %sw.bb ]
105  br label %return
106
107return:
108; GEN: return:
109; GEN-NOT: call void @llvm.instrprof.increment
110  %retval = phi i32 [ %res.1, %sw.epilog ], [ %call4, %if.then ]
111  ret i32 %retval
112}
113
114define internal i32 @bar(i32 %i) {
115entry:
116; GEN: call void @llvm.instrprof.increment(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @__profn__stdin__bar, i32 0, i32 0), i64 {{[0-9]+}}, i32 1, i32 0)
117  ret i32 %i
118}
119
120; USE: ![[BW_SWITCH]] = !{!"branch_weights", i32 2, i32 1, i32 0, i32 2, i32 1, i32 1}
121; USE: ![[BW_SW_BB2]] = !{!"branch_weights", i32 2, i32 2}
122; USE: ![[BW_SW_DEFAULT]] = !{!"branch_weights", i32 1, i32 1}
123