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 -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
8 ; Source used to create test:
10 ; extern void may_throw(int);
12 ; void run(int count) {
14 ; for (int i = 0; i < count; ++i) {
25 %eh.ThrowInfo = type { i32, i32, i32, i32 }
27 @"?buffer@@3PADA" = dso_local local_unnamed_addr global [200 x i8] zeroinitializer, align 16
28 define dso_local void @"?run@@YAXH@Z"(i32 %count) local_unnamed_addr personality ptr @__CxxFrameHandler3 {
32 for.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
37 for.body: ; preds = %for.cond
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
50 if.end: ; preds = %for.body
51 invoke void @"?may_throw@@YAXH@Z"(i32 %i.0)
52 to label %for.inc unwind label %catch.dispatch
54 for.inc: ; preds = %if.end
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
64 cleanup: ; preds = %for.body, %for.cond
67 catch.dispatch: ; preds = %if.end
68 %1 = catchswitch within none [label %catch] unwind to caller
70 catch: ; 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) ]
75 declare dso_local void @"?may_throw@@YAXH@Z"(i32)
76 declare dso_local void @_CxxThrowException(ptr, ptr)
77 declare dso_local i32 @__CxxFrameHandler3(...)