1; RUN: opt < %s -pgo-instr-gen -S | FileCheck %s --check-prefix=GEN
2; RUN: llvm-profdata merge %S/Inputs/switch.proftext -o %t.profdata
3; RUN: opt < %s -pgo-instr-use -pgo-test-profile-file=%t.profdata -S | FileCheck %s --check-prefix=USE
4target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
5target triple = "x86_64-unknown-linux-gnu"
6
7; GEN: @__profn_test_switch = private constant [11 x i8] c"test_switch"
8
9define void @test_switch(i32 %i) {
10entry:
11; GEN: entry:
12; GEN-NOT: call void @llvm.instrprof.increment
13  switch i32 %i, label %sw.default [
14    i32 1, label %sw.bb
15    i32 2, label %sw.bb1
16    i32 3, label %sw.bb2
17  ]
18; USE: ]
19; USE-SAME: !prof ![[BW_SWITCH:[0-9]+]]
20; USE: ![[BW_SWITCH]] = !{!"branch_weights", i32 3, i32 2, i32 0, i32 5}
21
22sw.bb:
23; GEN: sw.bb:
24; GEN: call void @llvm.instrprof.increment(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @__profn_test_switch, i32 0, i32 0), i64 46200943743, i32 4, i32 2)
25  br label %sw.epilog
26
27sw.bb1:
28; GEN: sw.bb1:
29; GEN: call void @llvm.instrprof.increment(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @__profn_test_switch, i32 0, i32 0), i64 46200943743, i32 4, i32 0)
30  br label %sw.epilog
31
32sw.bb2:
33; GEN: sw.bb2:
34; GEN: call void @llvm.instrprof.increment(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @__profn_test_switch, i32 0, i32 0), i64 46200943743, i32 4, i32 1)
35  br label %sw.epilog
36
37sw.default:
38; GEN: sw.default:
39; GEN: call void @llvm.instrprof.increment(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @__profn_test_switch, i32 0, i32 0), i64 46200943743, i32 4, i32 3)
40  br label %sw.epilog
41
42sw.epilog:
43; GEN: sw.epilog:
44; GEN-NOT: call void @llvm.instrprof.increment
45  ret void
46; GEN: ret void
47}
48