1 ; RUN: opt -S -hotcoldsplit -hotcoldsplit-threshold=0 < %s | FileCheck %s
5 ; extern void sideeffect(int);
6 ; extern void __attribute__((cold)) sink();
8 ; if (cond) { //< Start outlining here.
18 target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
19 target triple = "x86_64-apple-macosx10.14.0"
21 ; CHECK-LABEL: define {{.*}}@foo(
22 ; CHECK: br i1 {{.*}}, label %if.end, label %codeRepl
23 ; CHECK-LABEL: codeRepl:
24 ; CHECK-NEXT: call void @foo.cold.1
25 ; CHECK-LABEL: if.end:
26 ; CHECK: call void @sideeffect(i32 1)
27 define void @foo(i32 %cond) {
29 %tobool = icmp eq i32 %cond, 0
30 br i1 %tobool, label %if.end, label %while.cond.preheader
32 while.cond.preheader: ; preds = %entry
33 %cmp3 = icmp sgt i32 %cond, 10
34 br i1 %cmp3, label %while.body.preheader, label %while.end
36 while.body.preheader: ; preds = %while.cond.preheader
39 while.body: ; preds = %while.body.preheader, %while.body
40 %cond.addr.04 = phi i32 [ %dec, %while.body ], [ %cond, %while.body.preheader ]
41 %dec = add nsw i32 %cond.addr.04, -1
42 tail call void @sideeffect(i32 0) #3
43 %cmp = icmp sgt i32 %dec, 10
44 br i1 %cmp, label %while.body, label %while.end.loopexit
46 while.end.loopexit: ; preds = %while.body
49 while.end: ; preds = %while.end.loopexit, %while.cond.preheader
50 tail call void (...) @sink()
53 if.end: ; preds = %entry
54 tail call void @sideeffect(i32 1)
58 ; This is the same as @foo, but the while loop comes after the sink block.
59 ; CHECK-LABEL: define {{.*}}@while_loop_after_sink(
60 ; CHECK: br i1 {{.*}}, label %if.end, label %codeRepl
61 ; CHECK-LABEL: codeRepl:
62 ; CHECK-NEXT: call void @while_loop_after_sink.cold.1
63 ; CHECK-LABEL: if.end:
64 ; CHECK: call void @sideeffect(i32 1)
65 define void @while_loop_after_sink(i32 %cond) {
67 %tobool = icmp eq i32 %cond, 0
68 br i1 %tobool, label %if.end, label %sink
71 tail call void (...) @sink()
72 br label %while.cond.preheader
75 %cmp3 = icmp sgt i32 %cond, 10
76 br i1 %cmp3, label %while.body.preheader, label %while.end
78 while.body.preheader: ; preds = %while.cond.preheader
81 while.body: ; preds = %while.body.preheader, %while.body
82 %cond.addr.04 = phi i32 [ %dec, %while.body ], [ %cond, %while.body.preheader ]
83 %dec = add nsw i32 %cond.addr.04, -1
84 tail call void @sideeffect(i32 0) #3
85 %cmp = icmp sgt i32 %dec, 10
86 br i1 %cmp, label %while.body, label %while.end.loopexit
88 while.end.loopexit: ; preds = %while.body
91 while.end: ; preds = %while.end.loopexit, %while.cond.preheader
94 if.end: ; preds = %entry
95 tail call void @sideeffect(i32 1)
99 ; CHECK-LABEL: define {{.*}}@foo.cold.1
101 ; CHECK-NEXT: add nsw i32
102 ; CHECK-NEXT: call {{.*}}@sideeffect
106 ; CHECK-LABEL: define {{.*}}@while_loop_after_sink.cold.1
107 ; CHECK: call {{.*}}@sink
109 ; CHECK-NEXT: add nsw i32
110 ; CHECK-NEXT: call {{.*}}@sideeffect
114 declare void @sideeffect(i32)
116 declare void @sink(...) cold