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: 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) 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-NOT: call void @llvm.instrprof.increment 38; GEN: ret i32 39 ret i32 0 40} 41 42declare i8* @__cxa_allocate_exception(i64) 43 44declare void @__cxa_throw(i8*, i8*, i8*) 45 46define i32 @foo(i32 %i) personality i8* bitcast (i32 (...)* @__gxx_personality_v0 to i8*) { 47entry: 48; GEN: entry: 49; GEN-NOT: call void @llvm.instrprof.increment 50 %rem = srem i32 %i, 2 51 %tobool = icmp ne i32 %rem, 0 52 br i1 %tobool, label %if.then, label %if.end 53; USE: br i1 %tobool, label %if.then, label %if.end 54; USE-SAME: !prof ![[BW_FOO_ENTRY:[0-9]+]] 55 56if.then: 57; GEN: if.then: 58; GEN-NOT: call void @llvm.instrprof.increment 59 %mul = mul nsw i32 %i, 7 60 %call = invoke i32 @bar(i32 %mul) 61 to label %invoke.cont unwind label %lpad 62 63invoke.cont: 64; GEN: invoke.cont: 65; 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) 66 br label %if.end 67 68lpad: 69; GEN: lpad: 70; GEN-NOT: call void @llvm.instrprof.increment 71 %tmp = landingpad { i8*, i32 } 72 catch i8* bitcast (i8** @_ZTIi to i8*) 73 %tmp1 = extractvalue { i8*, i32 } %tmp, 0 74 %tmp2 = extractvalue { i8*, i32 } %tmp, 1 75 br label %catch.dispatch 76 77catch.dispatch: 78; GEN: catch.dispatch: 79; GEN-NOT: call void @llvm.instrprof.increment 80 %tmp3 = call i32 @llvm.eh.typeid.for(i8* bitcast (i8** @_ZTIi to i8*)) 81 %matches = icmp eq i32 %tmp2, %tmp3 82 br i1 %matches, label %catch, label %eh.resume 83; USE: br i1 %matches, label %catch, label %eh.resume 84; USE-SAME: !prof ![[BW_CATCH_DISPATCH:[0-9]+]] 85 86catch: 87; GEN: catch: 88; 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) 89 %tmp4 = call i8* @__cxa_begin_catch(i8* %tmp1) 90 %tmp5 = bitcast i8* %tmp4 to i32* 91 %tmp6 = load i32, i32* %tmp5, align 4 92 %tmp7 = load i32, i32* @val, align 4 93 %sub = sub nsw i32 %tmp7, %tmp6 94 store i32 %sub, i32* @val, align 4 95 call void @__cxa_end_catch() 96 br label %try.cont 97 98try.cont: 99; GEN: try.cont: 100; GEN-NOT: call void @llvm.instrprof.increment 101 ret i32 -1 102 103if.end: 104; GEN: if.end: 105; 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) 106 %tmp8 = load i32, i32* @val, align 4 107 %add = add nsw i32 %tmp8, %i 108 store i32 %add, i32* @val, align 4 109 br label %try.cont 110 111eh.resume: 112; GEN: eh.resume: 113; 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) 114 %lpad.val = insertvalue { i8*, i32 } undef, i8* %tmp1, 0 115 %lpad.val3 = insertvalue { i8*, i32 } %lpad.val, i32 %tmp2, 1 116 resume { i8*, i32 } %lpad.val3 117} 118 119declare i32 @__gxx_personality_v0(...) 120 121declare i32 @llvm.eh.typeid.for(i8*) 122 123declare i8* @__cxa_begin_catch(i8*) 124 125declare void @__cxa_end_catch() 126 127; USE: ![[BW_BAR_ENTRY]] = !{!"branch_weights", i32 2, i32 1} 128; USE: ![[BW_FOO_ENTRY]] = !{!"branch_weights", i32 3, i32 2} 129; USE: ![[BW_CATCH_DISPATCH]] = !{!"branch_weights", i32 2, i32 0} 130