1 ; RUN: opt < %s -pgo-instr-gen -pgo-instrument-entry -S | FileCheck %s --check-prefix=GEN
2 ; RUN: opt < %s -passes=pgo-instr-gen -pgo-instrument-entry -S | FileCheck %s --check-prefix=GEN
3 ; RUN: opt < %s -pgo-instr-gen -pgo-instrument-entry -instrprof -atomic-first-counter -S | FileCheck %s --check-prefix=GENA
4 ; RUN: opt < %s -passes=pgo-instr-gen,instrprof -pgo-instrument-entry -atomic-first-counter -S | FileCheck %s --check-prefix=GENA
6 ; RUN: llvm-profdata merge %S/Inputs/branch2.proftext -o %t.profdata
7 ; RUN: opt < %s -pgo-instr-use -pgo-test-profile-file=%t.profdata -pgo-instrument-entry -S | FileCheck %s --check-prefix=USE
8 ; RUN: opt < %s -passes=pgo-instr-use -pgo-test-profile-file=%t.profdata -pgo-instrument-entry -S | FileCheck %s --check-prefix=USE
9 target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
10 target triple = "x86_64-unknown-linux-gnu"
12 ; GEN: $__llvm_profile_raw_version = comdat any
13 ; GEN: @__llvm_profile_raw_version = constant i64 {{[0-9]+}}, comdat
14 ; GEN: @__profn_test_br_2 = private constant [9 x i8] c"test_br_2"
16 define i32 @test_br_2(i32 %i) {
19 ; GEN: call void @llvm.instrprof.increment(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @__profn_test_br_2, i32 0, i32 0), i64 {{[0-9]+}}, i32 2, i32 0)
21 ; GENA: %{{[0-9+]}} = atomicrmw add i64* getelementptr inbounds ([2 x i64], [2 x i64]* @__profc_test_br_2, i64 0, i64 0), i64 1 monotonic
22 ; USE: br i1 %cmp, label %if.then, label %if.else
23 ; USE-SAME: !prof ![[BW_ENTRY:[0-9]+]]
24 ; USE: ![[BW_ENTRY]] = !{!"branch_weights", i32 0, i32 1}
25 %cmp = icmp sgt i32 %i, 0
26 br i1 %cmp, label %if.then, label %if.else
30 ; GEN-NOT: llvm.instrprof.increment
31 %add = add nsw i32 %i, 2
36 ; GEN: call void @llvm.instrprof.increment(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @__profn_test_br_2, i32 0, i32 0), i64 {{[0-9]+}}, i32 2, i32 1)
38 ; GENA: %pgocount = load i64, i64* getelementptr inbounds ([2 x i64], [2 x i64]* @__profc_test_br_2, i64 0, i64 1), align 8
39 ; GENA: [[V:%[0-9]*]] = add i64 %pgocount, 1
40 ; GENA: store i64 [[V]], i64* getelementptr inbounds ([2 x i64], [2 x i64]* @__profc_test_br_2, i64 0, i64 1), align 8
41 %sub = sub nsw i32 %i, 2
46 ; GEN-NOT: llvm.instrprof.increment
47 %retv = phi i32 [ %add, %if.then ], [ %sub, %if.else ]