multiple-exits.ll
1.88 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
; RUN: opt -S -hotcoldsplit -hotcoldsplit-threshold=0 < %s | FileCheck %s
; Source:
;
; extern void sideeffect(int);
; extern void __attribute__((cold)) sink();
; void foo(int cond) {
; if (cond) { //< Start outlining here.
; sink();
; if (cond > 10)
; goto exit1;
; else
; goto exit2;
; }
; exit1:
; sideeffect(1);
; return;
; exit2:
; sideeffect(2);
; return;
; }
target datalayout = "e-m:o-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-apple-macosx10.14.0"
; CHECK-LABEL: define {{.*}}@foo(
; CHECK: br i1 {{.*}}, label %exit1, label %codeRepl
; CHECK-LABEL: codeRepl:
; CHECK: [[targetBlock:%.*]] = call i1 @foo.cold.1(
; CHECK-NEXT: br i1 [[targetBlock]], label %exit1, label %[[return:.*]]
; CHECK-LABEL: exit1:
; CHECK: call {{.*}}@sideeffect(i32 1)
; CHECK: [[return]]:
; CHECK-NEXT: ret void
define void @foo(i32 %cond) {
entry:
%tobool = icmp eq i32 %cond, 0
br i1 %tobool, label %exit1, label %if.then
if.then: ; preds = %entry
tail call void (...) @sink()
%cmp = icmp sgt i32 %cond, 10
br i1 %cmp, label %exit1, label %exit2
exit1: ; preds = %entry, %if.then
call void @sideeffect(i32 1)
br label %return
exit2: ; preds = %if.then
call void @sideeffect(i32 2)
br label %return
return: ; preds = %exit2, %exit1
ret void
}
; CHECK-LABEL: define {{.*}}@foo.cold.1(
; CHECK: br
; CHECK: [[exit1Stub:.*]]:
; CHECK-NEXT: ret i1 true
; CHECK: [[returnStub:.*]]:
; CHECK-NEXT: ret i1 false
; CHECK: call {{.*}}@sink
; CHECK-NEXT: [[cmp:%.*]] = icmp
; CHECK-NEXT: br i1 [[cmp]], label %[[exit1Stub]], label %exit2
; CHECK-LABEL: exit2:
; CHECK-NEXT: call {{.*}}@sideeffect(i32 2)
; CHECK-NEXT: br label %[[returnStub]]
declare void @sink(...) cold
declare void @sideeffect(i32)