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.
5 ; RUN: opt < %s -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=false -do-counter-promotion=true -S | FileCheck %s --check-prefixes=CHECK,NOTENTRY
7 ; RUN: opt < %s -pgo-instr-gen -instrprof -pgo-instrument-entry=true -do-counter-promotion=true -S | FileCheck %s --check-prefixes=CHECK,ENTRY
8 ; RUN: opt < %s -passes=pgo-instr-gen,instrprof -pgo-instrument-entry=true -do-counter-promotion=true -S | FileCheck %s --check-prefixes=CHECK,ENTRY
10 ; Source used to create test:
12 ; extern void may_throw(int);
14 ; void run(int count) {
16 ; for (int i = 0; i < count; ++i) {
27 %eh.ThrowInfo = type { i32, i32, i32, i32 }
29 @"?buffer@@3PADA" = dso_local local_unnamed_addr global [200 x i8] zeroinitializer, align 16
30 define dso_local void @"?run@@YAXH@Z"(i32 %count) local_unnamed_addr personality i8* bitcast (i32 (...)* @__CxxFrameHandler3 to i8*) {
34 for.cond: ; preds = %for.inc, %entry
35 %i.0 = phi i32 [ 0, %entry ], [ %inc, %for.inc ]
36 %cmp = icmp slt i32 %i.0, %count
37 br i1 %cmp, label %for.body, label %cleanup
39 for.body: ; preds = %for.cond
41 ; NOTENTRY: %pgocount1 = load i64, i64* getelementptr inbounds ([3 x i64], [3 x i64]* @"__profc_?run@@YAXH@Z", i64 0, i64 0)
42 ; TENTRY: %pgocount1 = load i64, i64* getelementptr inbounds ([3 x i64], [3 x i64]* @"__profc_?run@@YAXH@Z", i64 0, i64 1)
43 ; CHECK: %1 = add i64 %pgocount1, 1
44 ; NOTENTRY: store i64 %1, i64* getelementptr inbounds ([3 x i64], [3 x i64]* @"__profc_?run@@YAXH@Z", i64 0, i64 0)
45 ; ENTRY: store i64 %1, i64* getelementptr inbounds ([3 x i64], [3 x i64]* @"__profc_?run@@YAXH@Z", i64 0, i64 1)
46 %idxprom = zext i32 %i.0 to i64
47 %arrayidx = getelementptr inbounds [200 x i8], [200 x i8]* @"?buffer@@3PADA", i64 0, i64 %idxprom
48 %0 = load i8, i8* %arrayidx, align 1
49 %cmp1 = icmp eq i8 %0, 0
50 br i1 %cmp1, label %cleanup, label %if.end
52 if.end: ; preds = %for.body
53 invoke void @"?may_throw@@YAXH@Z"(i32 %i.0)
54 to label %for.inc unwind label %catch.dispatch
56 for.inc: ; preds = %if.end
58 ; NOTENTRY: %pgocount2 = load i64, i64* getelementptr inbounds ([3 x i64], [3 x i64]* @"__profc_?run@@YAXH@Z", i64 0, i64 1)
59 ; ENTRY: %pgocount2 = load i64, i64* getelementptr inbounds ([3 x i64], [3 x i64]* @"__profc_?run@@YAXH@Z", i64 0, i64 2)
60 ; CHECK: %3 = add i64 %pgocount2, 1
61 ; NOTENTRY: store i64 %3, i64* getelementptr inbounds ([3 x i64], [3 x i64]* @"__profc_?run@@YAXH@Z", i64 0, i64 1)
62 ; ENTRY: store i64 %3, i64* getelementptr inbounds ([3 x i64], [3 x i64]* @"__profc_?run@@YAXH@Z", i64 0, i64 2)
63 %inc = add nuw nsw i32 %i.0, 1
66 cleanup: ; preds = %for.body, %for.cond
69 catch.dispatch: ; preds = %if.end
70 %1 = catchswitch within none [label %catch] unwind to caller
72 catch: ; preds = %catch.dispatch
73 %2 = catchpad within %1 [i8* null, i32 64, i8* null]
74 call void @_CxxThrowException(i8* null, %eh.ThrowInfo* null) #2 [ "funclet"(token %2) ]
77 declare dso_local void @"?may_throw@@YAXH@Z"(i32)
78 declare dso_local void @_CxxThrowException(i8*, %eh.ThrowInfo*)
79 declare dso_local i32 @__CxxFrameHandler3(...)