1 ; Check that the unlikely branch is outlined. Override internal branch thresholds with -hotcoldsplit-cold-probability-denom
3 ; RUN: opt -S -passes=hotcoldsplit < %s | FileCheck %s --check-prefixes=CHECK-OUTLINE,CHECK-NOOUTLINE-BAZ
4 ; RUN: opt -S -passes=hotcoldsplit -hotcoldsplit-cold-probability-denom=50 < %s | FileCheck --check-prefixes=CHECK-OUTLINE,CHECK-PROB %s
6 ; int cold(const char*);
7 ; int hot(const char*);
8 ; void foo(int a, int b) {
9 ; if (a == b) [[unlikely]] { // Should be outlined.
17 ; void bar(int a, int b) {
18 ; if (a == b) [[likely]] {
20 ; } else { // Should be outlined.
26 ; void baz(int a, int b) {
27 ; if (a == b) [[likely]] {
29 ; } else { // Should be outlined.
35 ; All the outlined cold functions are emitted after the hot functions.
40 ; CHECK-OUTLINE: internal void @foo.cold.1() #[[ATTR0:[0-9]+]]
41 ; CHECK-OUTLINE-NEXT: newFuncRoot
42 ; CHECK-OUTLINE: tail call noundef i32 @cold
43 ; CHECK-OUTLINE: tail call noundef i32 @cold
45 ; CHECK-OUTLINE: internal void @bar.cold.1() #[[ATTR0:[0-9]+]]
46 ; CHECK-OUTLINE-NEXT: newFuncRoot
47 ; CHECK-OUTLINE: tail call noundef i32 @cold
48 ; CHECK-OUTLINE: tail call noundef i32 @cold
50 ; CHECK-NOOUTLINE-BAZ-NOT: internal void @baz.cold.1()
52 ; CHECK-PROB: internal void @baz.cold.1() #[[ATTR0:[0-9]+]]
53 ; CHECK-PROB-NEXT: newFuncRoot
54 ; CHECK-PROB: tail call noundef i32 @cold
55 ; CHECK-PROB: tail call noundef i32 @cold
56 ; CHECK-OUTLINE: attributes #[[ATTR0]] = { cold minsize }
58 source_filename = "/app/example.cpp"
59 target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
60 target triple = "x86_64-unknown-linux-gnu"
62 @.str = private unnamed_addr constant [5 x i8] c"same\00", align 1
63 @.str.1 = private unnamed_addr constant [10 x i8] c"different\00", align 1
65 define dso_local void @foo(i32 noundef %a, i32 noundef %b) local_unnamed_addr {
67 %cmp = icmp eq i32 %a, %b
68 br i1 %cmp, label %if.then, label %if.else, !prof !1
71 %call = tail call noundef i32 @cold(ptr noundef nonnull @.str)
72 %call1 = tail call noundef i32 @cold(ptr noundef nonnull @.str)
76 %call2 = tail call noundef i32 @hot(ptr noundef nonnull @.str.1)
83 declare noundef i32 @cold(ptr noundef) local_unnamed_addr #1
85 declare noundef i32 @hot(ptr noundef) local_unnamed_addr #1
87 define dso_local void @bar(i32 noundef %a, i32 noundef %b) local_unnamed_addr {
89 %cmp = icmp eq i32 %a, %b
90 br i1 %cmp, label %if.then, label %if.else, !prof !2
93 %call = tail call noundef i32 @hot(ptr noundef nonnull @.str)
97 %call1 = tail call noundef i32 @cold(ptr noundef nonnull @.str.1)
98 %call2 = tail call noundef i32 @cold(ptr noundef nonnull @.str.1)
105 define dso_local void @baz(i32 noundef %a, i32 noundef %b) local_unnamed_addr {
107 %cmp = icmp eq i32 %a, %b
108 br i1 %cmp, label %if.then, label %if.else, !prof !3
111 %call = tail call noundef i32 @hot(ptr noundef nonnull @.str)
115 %call1 = tail call noundef i32 @cold(ptr noundef nonnull @.str.1)
116 %call2 = tail call noundef i32 @cold(ptr noundef nonnull @.str.1)
123 !1 = !{!"branch_weights", i32 1, i32 2000}
124 !2 = !{!"branch_weights", i32 2000, i32 1}
125 !3 = !{!"branch_weights", i32 50, i32 1}