1; RUN: opt < %s -pgo-instr-gen -S | FileCheck %s --check-prefix=GEN 2; RUN: opt < %s -passes=pgo-instr-gen -S | FileCheck %s --check-prefix=GEN 3; RUN: llvm-profdata merge %S/Inputs/landingpad.proftext -o %t.profdata 4; RUN: opt < %s -pgo-instr-use -pgo-test-profile-file=%t.profdata -S | FileCheck %s --check-prefix=USE 5; RUN: opt < %s -passes=pgo-instr-use -pgo-test-profile-file=%t.profdata -S | FileCheck %s --check-prefix=USE 6target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128" 7target triple = "x86_64-unknown-linux-gnu" 8 9@val = global i32 0, align 4 10@_ZTIi = external constant i8* 11; GEN: $__llvm_profile_raw_version = comdat any 12; GEN: @__llvm_profile_raw_version = constant i64 {{[0-9]+}}, comdat 13; GEN: @__profn_bar = private constant [3 x i8] c"bar" 14; GEN: @__profn_foo = private constant [3 x i8] c"foo" 15 16define i32 @bar(i32 %i) { 17entry: 18; GEN: entry: 19; GEN-NOT: call void @llvm.instrprof.increment 20 %rem = srem i32 %i, 3 21 %tobool = icmp ne i32 %rem, 0 22 br i1 %tobool, label %if.then, label %if.end 23; USE: br i1 %tobool, label %if.then, label %if.end 24; USE-SAME: !prof ![[BW_BAR_ENTRY:[0-9]+]] 25 26if.then: 27; GEN: if.then: 28; GEN: call void @llvm.instrprof.increment(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @__profn_bar, i32 0, i32 0), i64 24868915205, i32 2, i32 1) 29 %exception = call i8* @__cxa_allocate_exception(i64 4) 30 %tmp = bitcast i8* %exception to i32* 31 store i32 %i, i32* %tmp, align 16 32 call void @__cxa_throw(i8* %exception, i8* bitcast (i8** @_ZTIi to i8*), i8* null) 33 unreachable 34 35if.end: 36; GEN: if.end: 37; GEN: call void @llvm.instrprof.increment(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @__profn_bar, i32 0, i32 0), i64 24868915205, i32 2, i32 0) 38 ret i32 0 39} 40 41declare i8* @__cxa_allocate_exception(i64) 42 43declare void @__cxa_throw(i8*, i8*, i8*) 44 45define i32 @foo(i32 %i) personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*) { 46entry: 47; GEN: entry: 48; GEN-NOT: call void @llvm.instrprof.increment 49 %rem = srem i32 %i, 2 50 %tobool = icmp ne i32 %rem, 0 51 br i1 %tobool, label %if.then, label %if.end 52; USE: br i1 %tobool, label %if.then, label %if.end 53; USE-SAME: !prof ![[BW_FOO_ENTRY:[0-9]+]] 54 55if.then: 56; GEN: if.then: 57; GEN-NOT: call void @llvm.instrprof.increment 58 %mul = mul nsw i32 %i, 7 59 %call = invoke i32 @bar(i32 %mul) 60 to label %invoke.cont unwind label %lpad 61 62invoke.cont: 63; GEN: invoke.cont: 64; GEN: call void @llvm.instrprof.increment(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @__profn_foo, i32 0, i32 0), i64 59130013419, i32 4, i32 1) 65 br label %if.end 66 67lpad: 68; GEN: lpad: 69; GEN-NOT: call void @llvm.instrprof.increment 70 %tmp = landingpad { i8*, i32 } 71 catch i8* bitcast (i8** @_ZTIi to i8*) 72 %tmp1 = extractvalue { i8*, i32 } %tmp, 0 73 %tmp2 = extractvalue { i8*, i32 } %tmp, 1 74 br label %catch.dispatch 75 76catch.dispatch: 77; GEN: catch.dispatch: 78; GEN-NOT: call void @llvm.instrprof.increment 79 %tmp3 = call i32 @llvm.eh.typeid.for(i8* bitcast (i8** @_ZTIi to i8*)) 80 %matches = icmp eq i32 %tmp2, %tmp3 81 br i1 %matches, label %catch, label %eh.resume 82; USE: br i1 %matches, label %catch, label %eh.resume 83; USE-SAME: !prof ![[BW_CATCH_DISPATCH:[0-9]+]] 84 85catch: 86; GEN: catch: 87; GEN: call void @llvm.instrprof.increment(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @__profn_foo, i32 0, i32 0), i64 59130013419, i32 4, i32 2) 88 %tmp4 = call i8* @__cxa_begin_catch(i8* %tmp1) 89 %tmp5 = bitcast i8* %tmp4 to i32* 90 %tmp6 = load i32, i32* %tmp5, align 4 91 %tmp7 = load i32, i32* @val, align 4 92 %sub = sub nsw i32 %tmp7, %tmp6 93 store i32 %sub, i32* @val, align 4 94 call void @__cxa_end_catch() 95 br label %try.cont 96 97try.cont: 98; GEN: try.cont: 99; GEN-NOT: call void @llvm.instrprof.increment 100 ret i32 -1 101 102if.end: 103; GEN: if.end: 104; GEN: call void @llvm.instrprof.increment(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @__profn_foo, i32 0, i32 0), i64 59130013419, i32 4, i32 0) 105 %tmp8 = load i32, i32* @val, align 4 106 %add = add nsw i32 %tmp8, %i 107 store i32 %add, i32* @val, align 4 108 br label %try.cont 109 110eh.resume: 111; GEN: eh.resume: 112; GEN: call void @llvm.instrprof.increment(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @__profn_foo, i32 0, i32 0), i64 59130013419, i32 4, i32 3) 113 %lpad.val = insertvalue { i8*, i32 } undef, i8* %tmp1, 0 114 %lpad.val3 = insertvalue { i8*, i32 } %lpad.val, i32 %tmp2, 1 115 resume { i8*, i32 } %lpad.val3 116} 117 118declare i32 @__gxx_personality_v0(...) 119 120declare i32 @llvm.eh.typeid.for(i8*) 121 122declare i8* @__cxa_begin_catch(i8*) 123 124declare void @__cxa_end_catch() 125 126; USE: ![[BW_BAR_ENTRY]] = !{!"branch_weights", i32 2, i32 1} 127; USE: ![[BW_FOO_ENTRY]] = !{!"branch_weights", i32 3, i32 2} 128; USE: ![[BW_CATCH_DISPATCH]] = !{!"branch_weights", i32 2, i32 0} 129