thread-two-bbs.ll
4.14 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
; RUN: opt < %s -jump-threading -S -verify | FileCheck %s
target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128"
target triple = "x86_64-unknown-linux-gnu"
@a = global i32 0, align 4
define void @foo(i32 %cond1, i32 %cond2) {
; CHECK-LABEL: @foo
; CHECK-LABEL: entry
entry:
%tobool = icmp eq i32 %cond1, 0
br i1 %tobool, label %bb.cond2, label %bb.f1
bb.f1:
call void @f1()
br label %bb.cond2
; Verify that we branch on cond2 without checking ptr.
; CHECK: call void @f1()
; CHECK-NEXT: icmp eq i32 %cond2, 0
; CHECK-NEXT: label %bb.f4, label %bb.f2
bb.cond2:
%ptr = phi i32* [ null, %bb.f1 ], [ @a, %entry ]
%tobool1 = icmp eq i32 %cond2, 0
br i1 %tobool1, label %bb.file, label %bb.f2
; Verify that we branch on cond2 without checking ptr.
; CHECK: icmp eq i32 %cond2, 0
; CHECK-NEXT: label %bb.f3, label %bb.f2
bb.f2:
call void @f2()
br label %exit
; Verify that we eliminate this basic block.
; CHECK-NOT: bb.file:
bb.file:
%cmp = icmp eq i32* %ptr, null
br i1 %cmp, label %bb.f4, label %bb.f3
bb.f3:
call void @f3()
br label %exit
bb.f4:
call void @f4()
br label %exit
exit:
ret void
}
declare void @f1()
declare void @f2()
declare void @f3()
declare void @f4()
define void @foo2(i32 %cond1, i32 %cond2) {
; CHECK-LABEL: @foo2
; CHECK-LABEL: entry
entry:
%tobool = icmp ne i32 %cond1, 0
br i1 %tobool, label %bb.f1, label %bb.f2
bb.f1:
call void @f1()
br label %bb.cond2
; Verify that we branch on cond2 without checking tobool again.
; CHECK: call void @f1()
; CHECK-NEXT: icmp eq i32 %cond2, 0
; CHECK-NEXT: label %exit, label %bb.f3
bb.f2:
call void @f2()
br label %bb.cond2
; Verify that we branch on cond2 without checking tobool again.
; CHECK: call void @f2()
; CHECK-NEXT: icmp eq i32 %cond2, 0
; CHECK-NEXT: label %exit, label %bb.f4
bb.cond2:
%tobool1 = icmp eq i32 %cond2, 0
br i1 %tobool1, label %exit, label %bb.cond1again
; Verify that we eliminate this basic block.
; CHECK-NOT: bb.cond1again:
bb.cond1again:
br i1 %tobool, label %bb.f3, label %bb.f4
bb.f3:
call void @f3()
br label %exit
bb.f4:
call void @f4()
br label %exit
exit:
ret void
}
; Verify that we do *not* thread any edge. We used to evaluate
; constant expressions like:
;
; icmp ugt i8* null, inttoptr (i64 4 to i8*)
;
; as "true", causing jump threading to a wrong destination.
define void @foo3(i8* %arg1, i8* %arg2) {
; CHECK-LABEL: @foo
; CHECK-NOT: bb_{{[^ ]*}}.thread:
entry:
%cmp1 = icmp eq i8* %arg1, null
br i1 %cmp1, label %bb_bar1, label %bb_end
bb_bar1:
call void @bar(i32 1)
br label %bb_end
bb_end:
%cmp2 = icmp ne i8* %arg2, null
br i1 %cmp2, label %bb_cont, label %bb_bar2
bb_bar2:
call void @bar(i32 2)
br label %bb_exit
bb_cont:
%cmp3 = icmp ule i8* %arg1, inttoptr (i64 4 to i8*)
br i1 %cmp3, label %bb_exit, label %bb_bar3
bb_bar3:
call void @bar(i32 3)
br label %bb_exit
bb_exit:
ret void
}
declare void @bar(i32)
;; Test that we skip unconditional PredBB when threading jumps through two
;; successive basic blocks.
define i32 @foo4(i32* %0) {
; CHECK-LABEL: @f
; CHECK: br i1 %good, label %pred.bb, label %pred.pred.bb
entry:
%size = call i64 @get_size(i32* %0)
%good = icmp ugt i64 %size, 3
br i1 %good, label %pred.bb, label %pred.pred.bb
; CHECK: pred.pred.bb:
; CHECK: br label %pred.bb
; CHECK: pred.bb:
; CHECK: br label %bb
; CHECK: bb:
pred.pred.bb: ; preds = %entry
call void @effect()
br label %pred.bb
pred.bb: ; preds = %pred.pred.bb, %entry
%v = load i32, i32* %0
br label %bb
bb: ; preds = %pred.bb
call void @effect1(i8* blockaddress(@foo4, %bb))
br i1 %good, label %cont2, label %cont1
cont1: ; preds = %bb
br i1 %good, label %exit, label %cont2
cont2: ; preds = %bb
br label %exit
exit: ; preds = %cont1, %cont2
ret i32 %v
}
declare i64 @get_size(i32*)
declare void @effect()
declare void @effect1(i8*)