Dehao Chen | 4b41571 | 2016-10-19 03:53:41 +0000 | [diff] [blame] | 1 | ; RUN: opt < %s -codegenprepare -S | FileCheck %s |
Dehao Chen | 302b69c | 2016-10-18 20:42:47 +0000 | [diff] [blame] | 2 | |
Dehao Chen | 83033e0 | 2016-10-18 21:13:31 +0000 | [diff] [blame] | 3 | target triple = "x86_64-pc-linux-gnu" |
| 4 | |
Dehao Chen | 302b69c | 2016-10-18 20:42:47 +0000 | [diff] [blame] | 5 | ; This tests that hot/cold functions get correct section prefix assigned |
| 6 | |
Teresa Johnson | a4ce3bf | 2017-12-20 17:53:10 +0000 | [diff] [blame] | 7 | ; CHECK: hot_func1{{.*}}!section_prefix ![[HOT_ID:[0-9]+]] |
Dehao Chen | 775341a | 2017-03-23 23:14:11 +0000 | [diff] [blame] | 8 | ; The entry is hot |
Teresa Johnson | a4ce3bf | 2017-12-20 17:53:10 +0000 | [diff] [blame] | 9 | define void @hot_func1() !prof !15 { |
Dehao Chen | 302b69c | 2016-10-18 20:42:47 +0000 | [diff] [blame] | 10 | ret void |
| 11 | } |
| 12 | |
Teresa Johnson | a4ce3bf | 2017-12-20 17:53:10 +0000 | [diff] [blame] | 13 | ; CHECK: hot_func2{{.*}}!section_prefix ![[HOT_ID:[0-9]+]] |
| 14 | ; Entry is cold but inner block is hot |
| 15 | define void @hot_func2(i32 %n) !prof !16 { |
| 16 | entry: |
| 17 | %n.addr = alloca i32, align 4 |
| 18 | %i = alloca i32, align 4 |
| 19 | store i32 %n, i32* %n.addr, align 4 |
| 20 | store i32 0, i32* %i, align 4 |
| 21 | br label %for.cond |
| 22 | |
| 23 | for.cond: |
| 24 | %0 = load i32, i32* %i, align 4 |
| 25 | %1 = load i32, i32* %n.addr, align 4 |
| 26 | %cmp = icmp slt i32 %0, %1 |
| 27 | br i1 %cmp, label %for.body, label %for.end, !prof !19 |
| 28 | |
| 29 | for.body: |
| 30 | %2 = load i32, i32* %i, align 4 |
| 31 | %inc = add nsw i32 %2, 1 |
| 32 | store i32 %inc, i32* %i, align 4 |
| 33 | br label %for.cond |
| 34 | |
| 35 | for.end: |
| 36 | ret void |
| 37 | } |
| 38 | |
| 39 | ; For instrumentation based PGO, we should only look at block counts, |
Teresa Johnson | 2a6b799 | 2017-05-11 23:18:05 +0000 | [diff] [blame] | 40 | ; not call site VP metadata (which can exist on value profiled memcpy, |
| 41 | ; or possibly left behind after static analysis based devirtualization). |
| 42 | ; CHECK: cold_func1{{.*}}!section_prefix ![[COLD_ID:[0-9]+]] |
| 43 | define void @cold_func1() !prof !16 { |
Teresa Johnson | a4ce3bf | 2017-12-20 17:53:10 +0000 | [diff] [blame] | 44 | call void @hot_func1(), !prof !17 |
| 45 | call void @hot_func1(), !prof !17 |
Dehao Chen | 775341a | 2017-03-23 23:14:11 +0000 | [diff] [blame] | 46 | ret void |
| 47 | } |
| 48 | |
Teresa Johnson | a4ce3bf | 2017-12-20 17:53:10 +0000 | [diff] [blame] | 49 | ; CHECK: cold_func2{{.*}}!section_prefix ![[COLD_ID]] |
Teresa Johnson | 2a6b799 | 2017-05-11 23:18:05 +0000 | [diff] [blame] | 50 | define void @cold_func2() !prof !16 { |
Teresa Johnson | a4ce3bf | 2017-12-20 17:53:10 +0000 | [diff] [blame] | 51 | call void @hot_func1(), !prof !17 |
| 52 | call void @hot_func1(), !prof !18 |
| 53 | call void @hot_func1(), !prof !18 |
Dehao Chen | 775341a | 2017-03-23 23:14:11 +0000 | [diff] [blame] | 54 | ret void |
| 55 | } |
| 56 | |
Teresa Johnson | 2a6b799 | 2017-05-11 23:18:05 +0000 | [diff] [blame] | 57 | ; CHECK: cold_func3{{.*}}!section_prefix ![[COLD_ID]] |
| 58 | define void @cold_func3() !prof !16 { |
Teresa Johnson | a4ce3bf | 2017-12-20 17:53:10 +0000 | [diff] [blame] | 59 | call void @hot_func1(), !prof !18 |
Dehao Chen | 302b69c | 2016-10-18 20:42:47 +0000 | [diff] [blame] | 60 | ret void |
| 61 | } |
| 62 | |
Dehao Chen | 4b41571 | 2016-10-19 03:53:41 +0000 | [diff] [blame] | 63 | ; CHECK: ![[HOT_ID]] = !{!"function_section_prefix", !".hot"} |
Teresa Johnson | 720d9b4 | 2017-05-09 01:43:24 +0000 | [diff] [blame] | 64 | ; CHECK: ![[COLD_ID]] = !{!"function_section_prefix", !".unlikely"} |
Dehao Chen | 302b69c | 2016-10-18 20:42:47 +0000 | [diff] [blame] | 65 | !llvm.module.flags = !{!1} |
| 66 | !1 = !{i32 1, !"ProfileSummary", !2} |
| 67 | !2 = !{!3, !4, !5, !6, !7, !8, !9, !10} |
| 68 | !3 = !{!"ProfileFormat", !"InstrProf"} |
| 69 | !4 = !{!"TotalCount", i64 10000} |
| 70 | !5 = !{!"MaxCount", i64 1000} |
| 71 | !6 = !{!"MaxInternalCount", i64 1} |
| 72 | !7 = !{!"MaxFunctionCount", i64 1000} |
| 73 | !8 = !{!"NumCounts", i64 3} |
| 74 | !9 = !{!"NumFunctions", i64 3} |
| 75 | !10 = !{!"DetailedSummary", !11} |
| 76 | !11 = !{!12, !13, !14} |
| 77 | !12 = !{i32 10000, i64 100, i32 1} |
| 78 | !13 = !{i32 999000, i64 100, i32 1} |
| 79 | !14 = !{i32 999999, i64 1, i32 2} |
| 80 | !15 = !{!"function_entry_count", i64 1000} |
| 81 | !16 = !{!"function_entry_count", i64 1} |
Dehao Chen | 775341a | 2017-03-23 23:14:11 +0000 | [diff] [blame] | 82 | !17 = !{!"branch_weights", i32 80} |
| 83 | !18 = !{!"branch_weights", i32 1} |
Teresa Johnson | a4ce3bf | 2017-12-20 17:53:10 +0000 | [diff] [blame] | 84 | !19 = !{!"branch_weights", i32 1000, i32 1} |