78 lines · plain
1; Test that instrumentation counter promotion for loops does not fail during2; compilation for loops that exit to a catchswitch block. In this case, counters3; 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,NOTENTRY6; RUN: opt < %s -passes=pgo-instr-gen,instrprof -pgo-instrument-entry=true -do-counter-promotion=true -S | FileCheck %s --check-prefixes=CHECK,ENTRY7 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 1628define dso_local void @"?run@@YAXH@Z"(i32 %count) local_unnamed_addr personality ptr @__CxxFrameHandler3 {29entry:30 br label %for.cond31 32for.cond: ; preds = %for.inc, %entry33 %i.0 = phi i32 [ 0, %entry ], [ %inc, %for.inc ]34 %cmp = icmp slt i32 %i.0, %count35 br i1 %cmp, label %for.body, label %cleanup36 37for.body: ; preds = %for.cond38; 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, 142; 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 i6445 %arrayidx = getelementptr inbounds [200 x i8], ptr @"?buffer@@3PADA", i64 0, i64 %idxprom46 %0 = load i8, ptr %arrayidx, align 147 %cmp1 = icmp eq i8 %0, 048 br i1 %cmp1, label %cleanup, label %if.end49 50if.end: ; preds = %for.body51 invoke void @"?may_throw@@YAXH@Z"(i32 %i.0)52 to label %for.inc unwind label %catch.dispatch53 54for.inc: ; preds = %if.end55; 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, 159; 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, 162 br label %for.cond63 64cleanup: ; preds = %for.body, %for.cond65 ret void66 67catch.dispatch: ; preds = %if.end68 %1 = catchswitch within none [label %catch] unwind to caller69 70catch: ; preds = %catch.dispatch71 %2 = catchpad within %1 [ptr null, i32 64, ptr null]72 call void @_CxxThrowException(ptr null, ptr null) #2 [ "funclet"(token %2) ]73 unreachable74}75declare dso_local void @"?may_throw@@YAXH@Z"(i32)76declare dso_local void @_CxxThrowException(ptr, ptr)77declare dso_local i32 @__CxxFrameHandler3(...)78