1 ; RUN: opt -consthoist -mtriple=x86_64-unknown-linux-gnu -consthoist-with-block-frequency=true -S < %s | FileCheck %s
3 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
5 ; Check when BFI is enabled for constant hoisting, constant 214748364701
6 ; will not be hoisted to the func entry.
9 ; CHECK-NOT: bitcast i64 214748364701 to i64
12 ; Function Attrs: norecurse nounwind uwtable
13 define i64 @test1(ptr nocapture %a) {
15 %arrayidx = getelementptr inbounds i64, ptr %a, i64 9
16 %t0 = load i64, ptr %arrayidx, align 8
17 %cmp = icmp slt i64 %t0, 564
18 br i1 %cmp, label %if.then, label %if.else5
20 if.then: ; preds = %entry
21 %arrayidx1 = getelementptr inbounds i64, ptr %a, i64 5
22 %t1 = load i64, ptr %arrayidx1, align 8
23 %cmp2 = icmp slt i64 %t1, 1009
24 br i1 %cmp2, label %if.then3, label %return
26 if.then3: ; preds = %if.then
27 %arrayidx4 = getelementptr inbounds i64, ptr %a, i64 6
28 %t2 = load i64, ptr %arrayidx4, align 8
29 %inc = add nsw i64 %t2, 1
30 store i64 %inc, ptr %arrayidx4, align 8
33 if.else5: ; preds = %entry
34 %arrayidx6 = getelementptr inbounds i64, ptr %a, i64 6
35 %t3 = load i64, ptr %arrayidx6, align 8
36 %cmp7 = icmp slt i64 %t3, 3512
37 br i1 %cmp7, label %if.then8, label %return
39 if.then8: ; preds = %if.else5
40 %arrayidx9 = getelementptr inbounds i64, ptr %a, i64 7
41 %t4 = load i64, ptr %arrayidx9, align 8
42 %inc10 = add nsw i64 %t4, 1
43 store i64 %inc10, ptr %arrayidx9, align 8
46 return: ; 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 ]
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(
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
62 ; CHECK-NEXT: bitcast i64 214748364701 to i64
63 ; CHECK-NOT: bitcast i64 214748364701 to i64
64 define i64 @test2(ptr nocapture %a) {
66 %arrayidx = getelementptr inbounds i64, ptr %a, i64 9
67 %t0 = load i64, ptr %arrayidx, align 8
68 %cmp = icmp ult i64 %t0, 56
69 br i1 %cmp, label %if.then, label %if.else10, !prof !0
71 if.then: ; preds = %entry
72 %arrayidx1 = getelementptr inbounds i64, ptr %a, i64 5
73 %t1 = load i64, ptr %arrayidx1, align 8
74 %cmp2 = icmp ult i64 %t1, 10
75 br i1 %cmp2, label %while.cond.preheader, label %return, !prof !0
77 while.cond.preheader: ; preds = %if.then
78 %arrayidx7 = getelementptr inbounds i64, ptr %a, i64 6
79 %t2 = load i64, ptr %arrayidx7, align 8
80 %cmp823 = icmp ugt i64 %t2, 10000
81 br i1 %cmp823, label %while.body.preheader, label %return
83 while.body.preheader: ; preds = %while.cond.preheader
86 while.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
92 if.else10: ; preds = %entry
93 %arrayidx11 = getelementptr inbounds i64, ptr %a, i64 6
94 %t4 = load i64, ptr %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
99 if.then16: ; preds = %if.else10
100 %arrayidx17 = getelementptr inbounds i64, ptr %a, i64 7
101 %t5 = load i64, ptr %arrayidx17, align 8
102 %inc = add i64 %t5, 1
103 store i64 %inc, ptr %arrayidx17, align 8
106 while.cond.return.loopexit_crit_edge: ; preds = %while.body
107 store i64 %add, ptr %arrayidx7, align 8
110 return: ; 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 ]
115 !0 = !{!"branch_weights", i32 1, i32 2000}
117 ; 214748364701 will be hoisted to entry block to reduce code size.
118 ; CHECK-LABEL: @test3(
120 ; CHECK-NEXT: %const = bitcast i64 214748364701 to i64
121 define i64 @test3(i64 %t0) {
123 %cmp = icmp ult i64 %t0, 56
124 br i1 %cmp, label %if.then, label %if.else
127 ; CHECK-NOT: %const = bitcast i64 214748364701 to i64
129 %add1 = add i64 %t0, 214748364701
133 ; CHECK-NOT: %const = bitcast i64 214748364701 to i64
135 %add2 = add i64 %t0, 214748364701
139 %retval = phi i64 [ %add1, %if.then ], [ %add2, %if.else ]
143 ; 214748364701 will not be hoisted to entry block because it will only
144 ; increase its live range.
145 ; CHECK-LABEL: @test4(
147 ; CHECK-NEXT: %add1 = add i64 %t0, 214748364701
148 define i64 @test4(i64 %t0) {
150 %cmp = icmp ult i64 %t0, 56
154 %add1 = add i64 %t0, 214748364701