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 -pgo-instr-gen -instrprof -do-counter-promotion=true -S | FileCheck %s 6; RUN: opt < %s -passes=pgo-instr-gen,instrprof -do-counter-promotion=true -S | FileCheck %s 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 i8* bitcast (i32 (...)* @__CxxFrameHandler3 to i8*) { 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; CHECK: %pgocount1 = load i64, i64* getelementptr inbounds ([3 x i64], [3 x i64]* @"__profc_?run@@YAXH@Z", i64 0, i64 0) 40; CHECK: %1 = add i64 %pgocount1, 1 41; CHECK: store i64 %1, i64* getelementptr inbounds ([3 x i64], [3 x i64]* @"__profc_?run@@YAXH@Z", i64 0, i64 0) 42 %idxprom = zext i32 %i.0 to i64 43 %arrayidx = getelementptr inbounds [200 x i8], [200 x i8]* @"?buffer@@3PADA", i64 0, i64 %idxprom 44 %0 = load i8, i8* %arrayidx, align 1 45 %cmp1 = icmp eq i8 %0, 0 46 br i1 %cmp1, label %cleanup, label %if.end 47 48if.end: ; preds = %for.body 49 invoke void @"?may_throw@@YAXH@Z"(i32 %i.0) 50 to label %for.inc unwind label %catch.dispatch 51 52for.inc: ; preds = %if.end 53; CHECK: for.inc: 54; CHECK: %pgocount2 = load i64, i64* getelementptr inbounds ([3 x i64], [3 x i64]* @"__profc_?run@@YAXH@Z", i64 0, i64 1) 55; CHECK: %3 = add i64 %pgocount2, 1 56; CHECK: store i64 %3, i64* getelementptr inbounds ([3 x i64], [3 x i64]* @"__profc_?run@@YAXH@Z", i64 0, i64 1) 57 %inc = add nuw nsw i32 %i.0, 1 58 br label %for.cond 59 60cleanup: ; preds = %for.body, %for.cond 61 ret void 62 63catch.dispatch: ; preds = %if.end 64 %1 = catchswitch within none [label %catch] unwind to caller 65 66catch: ; preds = %catch.dispatch 67 %2 = catchpad within %1 [i8* null, i32 64, i8* null] 68 call void @_CxxThrowException(i8* null, %eh.ThrowInfo* null) #2 [ "funclet"(token %2) ] 69 unreachable 70} 71declare dso_local void @"?may_throw@@YAXH@Z"(i32) 72declare dso_local void @_CxxThrowException(i8*, %eh.ThrowInfo*) 73declare dso_local i32 @__CxxFrameHandler3(...) 74