• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1; RUN: opt -consthoist -mtriple=x86_64-unknown-linux-gnu -consthoist-with-block-frequency=true -S < %s | FileCheck %s
2
3target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
4
5; Check when BFI is enabled for constant hoisting, constant 214748364701
6; will not be hoisted to the func entry.
7; CHECK-LABEL: @test1(
8; CHECK: entry:
9; CHECK-NOT: bitcast i64 214748364701 to i64
10; CHECK: if.then:
11
12; Function Attrs: norecurse nounwind uwtable
13define i64 @test1(i64* nocapture %a) {
14entry:
15  %arrayidx = getelementptr inbounds i64, i64* %a, i64 9
16  %t0 = load i64, i64* %arrayidx, align 8
17  %cmp = icmp slt i64 %t0, 564
18  br i1 %cmp, label %if.then, label %if.else5
19
20if.then:                                          ; preds = %entry
21  %arrayidx1 = getelementptr inbounds i64, i64* %a, i64 5
22  %t1 = load i64, i64* %arrayidx1, align 8
23  %cmp2 = icmp slt i64 %t1, 1009
24  br i1 %cmp2, label %if.then3, label %return
25
26if.then3:                                         ; preds = %if.then
27  %arrayidx4 = getelementptr inbounds i64, i64* %a, i64 6
28  %t2 = load i64, i64* %arrayidx4, align 8
29  %inc = add nsw i64 %t2, 1
30  store i64 %inc, i64* %arrayidx4, align 8
31  br label %return
32
33if.else5:                                         ; preds = %entry
34  %arrayidx6 = getelementptr inbounds i64, i64* %a, i64 6
35  %t3 = load i64, i64* %arrayidx6, align 8
36  %cmp7 = icmp slt i64 %t3, 3512
37  br i1 %cmp7, label %if.then8, label %return
38
39if.then8:                                         ; preds = %if.else5
40  %arrayidx9 = getelementptr inbounds i64, i64* %a, i64 7
41  %t4 = load i64, i64* %arrayidx9, align 8
42  %inc10 = add nsw i64 %t4, 1
43  store i64 %inc10, i64* %arrayidx9, align 8
44  br label %return
45
46return:                                           ; preds = %if.else5, %if.then, %if.then8, %if.then3
47  %retval.0 = phi i64 [ 214748364701, %if.then3 ], [ 214748364701, %if.then8 ], [ 250148364702, %if.then ], [ 256148364704, %if.else5 ]
48  ret i64 %retval.0
49}
50
51; Check when BFI is enabled for constant hoisting, constant 214748364701
52; in while.body will be hoisted to while.body.preheader. 214748364701 in
53; if.then16 and if.else10 will be merged and hoisted to the beginning of
54; if.else10 because if.else10 dominates if.then16.
55; CHECK-LABEL: @test2(
56; CHECK: entry:
57; CHECK-NOT: bitcast i64 214748364701 to i64
58; CHECK: while.body.preheader:
59; CHECK-NEXT: bitcast i64 214748364701 to i64
60; CHECK-NOT: bitcast i64 214748364701 to i64
61; CHECK: if.else10:
62; CHECK-NEXT: bitcast i64 214748364701 to i64
63; CHECK-NOT: bitcast i64 214748364701 to i64
64define i64 @test2(i64* nocapture %a) {
65entry:
66  %arrayidx = getelementptr inbounds i64, i64* %a, i64 9
67  %t0 = load i64, i64* %arrayidx, align 8
68  %cmp = icmp ult i64 %t0, 56
69  br i1 %cmp, label %if.then, label %if.else10, !prof !0
70
71if.then:                                          ; preds = %entry
72  %arrayidx1 = getelementptr inbounds i64, i64* %a, i64 5
73  %t1 = load i64, i64* %arrayidx1, align 8
74  %cmp2 = icmp ult i64 %t1, 10
75  br i1 %cmp2, label %while.cond.preheader, label %return, !prof !0
76
77while.cond.preheader:                             ; preds = %if.then
78  %arrayidx7 = getelementptr inbounds i64, i64* %a, i64 6
79  %t2 = load i64, i64* %arrayidx7, align 8
80  %cmp823 = icmp ugt i64 %t2, 10000
81  br i1 %cmp823, label %while.body.preheader, label %return
82
83while.body.preheader:                             ; preds = %while.cond.preheader
84  br label %while.body
85
86while.body:                                       ; preds = %while.body.preheader, %while.body
87  %t3 = phi i64 [ %add, %while.body ], [ %t2, %while.body.preheader ]
88  %add = add i64 %t3, 214748364701
89  %cmp8 = icmp ugt i64 %add, 10000
90  br i1 %cmp8, label %while.body, label %while.cond.return.loopexit_crit_edge
91
92if.else10:                                        ; preds = %entry
93  %arrayidx11 = getelementptr inbounds i64, i64* %a, i64 6
94  %t4 = load i64, i64* %arrayidx11, align 8
95  %add2 = add i64 %t4, 214748364701
96  %cmp12 = icmp ult i64 %add2, 35
97  br i1 %cmp12, label %if.then16, label %return, !prof !0
98
99if.then16:                                        ; preds = %if.else10
100  %arrayidx17 = getelementptr inbounds i64, i64* %a, i64 7
101  %t5 = load i64, i64* %arrayidx17, align 8
102  %inc = add i64 %t5, 1
103  store i64 %inc, i64* %arrayidx17, align 8
104  br label %return
105
106while.cond.return.loopexit_crit_edge:             ; preds = %while.body
107  store i64 %add, i64* %arrayidx7, align 8
108  br label %return
109
110return:                                           ; preds = %while.cond.preheader, %while.cond.return.loopexit_crit_edge, %if.else10, %if.then, %if.then16
111  %retval.0 = phi i64 [ 214748364701, %if.then16 ], [ 0, %if.then ], [ 0, %if.else10 ], [ 0, %while.cond.return.loopexit_crit_edge ], [ 0, %while.cond.preheader ]
112  ret i64 %retval.0
113}
114
115!0 = !{!"branch_weights", i32 1, i32 2000}
116
117; 214748364701 will be hoisted to entry block to reduce code size.
118; CHECK-LABEL: @test3(
119; CHECK: entry:
120; CHECK-NEXT: %const = bitcast i64 214748364701 to i64
121define i64 @test3(i64 %t0) {
122entry:
123  %cmp = icmp ult i64 %t0, 56
124  br i1 %cmp, label %if.then, label %if.else
125
126; CHECK: if.then:
127; CHECK-NOT: %const = bitcast i64 214748364701 to i64
128if.then:
129  %add1 = add i64 %t0, 214748364701
130  br label %return
131
132; CHECK: if.else:
133; CHECK-NOT: %const = bitcast i64 214748364701 to i64
134if.else:
135  %add2 = add i64 %t0, 214748364701
136  br label %return
137
138return:
139  %retval = phi i64 [ %add1, %if.then ], [ %add2, %if.else ]
140  ret i64 %retval
141}
142
143; 214748364701 will not be hoisted to entry block because it will only
144; increase its live range.
145; CHECK-LABEL: @test4(
146; CHECK: nextblock:
147; CHECK-NEXT: %add1 = add i64 %t0, 214748364701
148define i64 @test4(i64 %t0) {
149entry:
150  %cmp = icmp ult i64 %t0, 56
151  br label %nextblock
152
153nextblock:
154  %add1 = add i64 %t0, 214748364701
155  br label %return
156
157return:
158  ret i64 %add1
159}
160