1; Test that instrumentation counter promotion for loops does not fail during 2; compilation for loops that exit to a catchswitch block. In this case, counters 3; do not get promoted out of the loop body. 4 5; RUN: opt < %s -passes=pgo-instr-gen,instrprof -pgo-instrument-entry=false -do-counter-promotion=true -S | FileCheck %s --check-prefixes=CHECK,NOTENTRY 6; RUN: opt < %s -passes=pgo-instr-gen,instrprof -pgo-instrument-entry=true -do-counter-promotion=true -S | FileCheck %s --check-prefixes=CHECK,ENTRY 7 8; Source used to create test: 9; 10; extern void may_throw(int); 11; char buffer[200]; 12; void run(int count) { 13; try { 14; for (int i = 0; i < count; ++i) { 15; if (buffer[i] == 0) 16; break; 17; may_throw(i); 18; } 19; } 20; catch (...) { 21; throw; 22; } 23;} 24 25%eh.ThrowInfo = type { i32, i32, i32, i32 } 26 27@"?buffer@@3PADA" = dso_local local_unnamed_addr global [200 x i8] zeroinitializer, align 16 28define dso_local void @"?run@@YAXH@Z"(i32 %count) local_unnamed_addr personality ptr @__CxxFrameHandler3 { 29entry: 30 br label %for.cond 31 32for.cond: ; preds = %for.inc, %entry 33 %i.0 = phi i32 [ 0, %entry ], [ %inc, %for.inc ] 34 %cmp = icmp slt i32 %i.0, %count 35 br i1 %cmp, label %for.body, label %cleanup 36 37for.body: ; preds = %for.cond 38; CHECK: for.body: 39; NOTENTRY: %pgocount1 = load i64, ptr @"__profc_?run@@YAXH@Z" 40; TENTRY: %pgocount1 = load i64, ptr getelementptr inbounds ([3 x i64], ptr @"__profc_?run@@YAXH@Z", i32 0, i32 1) 41; CHECK: %1 = add i64 %pgocount1, 1 42; NOTENTRY: store i64 %1, ptr @"__profc_?run@@YAXH@Z" 43; ENTRY: store i64 %1, ptr getelementptr inbounds ([3 x i64], ptr @"__profc_?run@@YAXH@Z", i32 0, i32 1) 44 %idxprom = zext i32 %i.0 to i64 45 %arrayidx = getelementptr inbounds [200 x i8], ptr @"?buffer@@3PADA", i64 0, i64 %idxprom 46 %0 = load i8, ptr %arrayidx, align 1 47 %cmp1 = icmp eq i8 %0, 0 48 br i1 %cmp1, label %cleanup, label %if.end 49 50if.end: ; preds = %for.body 51 invoke void @"?may_throw@@YAXH@Z"(i32 %i.0) 52 to label %for.inc unwind label %catch.dispatch 53 54for.inc: ; preds = %if.end 55; CHECK: for.inc: 56; NOTENTRY: %pgocount2 = load i64, ptr getelementptr inbounds ([3 x i64], ptr @"__profc_?run@@YAXH@Z", i32 0, i32 1) 57; ENTRY: %pgocount2 = load i64, ptr getelementptr inbounds ([3 x i64], ptr @"__profc_?run@@YAXH@Z", i32 0, i32 2) 58; CHECK: %3 = add i64 %pgocount2, 1 59; NOTENTRY: store i64 %3, ptr getelementptr inbounds ([3 x i64], ptr @"__profc_?run@@YAXH@Z", i32 0, i32 1) 60; ENTRY: store i64 %3, ptr getelementptr inbounds ([3 x i64], ptr @"__profc_?run@@YAXH@Z", i32 0, i32 2) 61 %inc = add nuw nsw i32 %i.0, 1 62 br label %for.cond 63 64cleanup: ; preds = %for.body, %for.cond 65 ret void 66 67catch.dispatch: ; preds = %if.end 68 %1 = catchswitch within none [label %catch] unwind to caller 69 70catch: ; preds = %catch.dispatch 71 %2 = catchpad within %1 [ptr null, i32 64, ptr null] 72 call void @_CxxThrowException(ptr null, ptr null) #2 [ "funclet"(token %2) ] 73 unreachable 74} 75declare dso_local void @"?may_throw@@YAXH@Z"(i32) 76declare dso_local void @_CxxThrowException(ptr, ptr) 77declare dso_local i32 @__CxxFrameHandler3(...) 78