sink_to_unreachable.ll
4.44 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
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
; RUN: opt -instcombine -S < %s | FileCheck %s
; RUN: opt -passes=instcombine -S < %s | FileCheck %s
declare void @use(i32 %x)
declare i1 @cond()
define void @test_01(i32 %x, i32 %y) {
; CHECK-LABEL: @test_01(
; CHECK-NEXT: entry:
; CHECK-NEXT: [[C2:%.*]] = icmp slt i32 [[X:%.*]], [[Y:%.*]]
; CHECK-NEXT: br i1 [[C2]], label [[EXIT:%.*]], label [[UNREACHED:%.*]]
; CHECK: unreached:
; CHECK-NEXT: [[C1:%.*]] = icmp ne i32 [[X]], [[Y]]
; CHECK-NEXT: [[COMPARATOR:%.*]] = zext i1 [[C1]] to i32
; CHECK-NEXT: call void @use(i32 [[COMPARATOR]])
; CHECK-NEXT: unreachable
; CHECK: exit:
; CHECK-NEXT: ret void
;
entry:
%c1 = icmp eq i32 %x, %y
%c2 = icmp slt i32 %x, %y
%signed = select i1 %c2, i32 -1, i32 1
%comparator = select i1 %c1, i32 0, i32 %signed
br i1 %c2, label %exit, label %unreached
unreached:
call void @use(i32 %comparator)
unreachable
exit:
ret void
}
define void @test_02(i32 %x, i32 %y) {
; CHECK-LABEL: @test_02(
; CHECK-NEXT: entry:
; CHECK-NEXT: [[C2:%.*]] = icmp slt i32 [[X:%.*]], [[Y:%.*]]
; CHECK-NEXT: br i1 [[C2]], label [[EXIT:%.*]], label [[MEDIUM:%.*]]
; CHECK: medium:
; CHECK-NEXT: [[C3:%.*]] = icmp sgt i32 [[X]], [[Y]]
; CHECK-NEXT: br i1 [[C3]], label [[EXIT]], label [[UNREACHED:%.*]]
; CHECK: unreached:
; CHECK-NEXT: [[C1:%.*]] = icmp eq i32 [[X]], [[Y]]
; CHECK-NEXT: [[SIGNED:%.*]] = select i1 [[C2]], i32 -1, i32 1
; CHECK-NEXT: [[COMPARATOR:%.*]] = select i1 [[C1]], i32 0, i32 [[SIGNED]]
; CHECK-NEXT: call void @use(i32 [[COMPARATOR]])
; CHECK-NEXT: unreachable
; CHECK: exit:
; CHECK-NEXT: ret void
;
entry:
%c1 = icmp eq i32 %x, %y
%c2 = icmp slt i32 %x, %y
%signed = select i1 %c2, i32 -1, i32 1
%comparator = select i1 %c1, i32 0, i32 %signed
br i1 %c2, label %exit, label %medium
medium:
%c3 = icmp sgt i32 %x, %y
br i1 %c3, label %exit, label %unreached
unreached:
call void @use(i32 %comparator)
unreachable
exit:
ret void
}
define i32 @test_03(i32 %x, i32 %y) {
; CHECK-LABEL: @test_03(
; CHECK-NEXT: entry:
; CHECK-NEXT: [[C2:%.*]] = icmp slt i32 [[X:%.*]], [[Y:%.*]]
; CHECK-NEXT: br i1 [[C2]], label [[EXIT:%.*]], label [[MEDIUM:%.*]]
; CHECK: medium:
; CHECK-NEXT: [[C3:%.*]] = icmp sgt i32 [[X]], [[Y]]
; CHECK-NEXT: br i1 [[C3]], label [[EXIT]], label [[UNREACHED:%.*]]
; CHECK: unreached:
; CHECK-NEXT: [[C1:%.*]] = icmp eq i32 [[X]], [[Y]]
; CHECK-NEXT: [[SIGNED:%.*]] = select i1 [[C2]], i32 -1, i32 1
; CHECK-NEXT: [[COMPARATOR:%.*]] = select i1 [[C1]], i32 0, i32 [[SIGNED]]
; CHECK-NEXT: ret i32 [[COMPARATOR]]
; CHECK: exit:
; CHECK-NEXT: ret i32 0
;
entry:
%c1 = icmp eq i32 %x, %y
%c2 = icmp slt i32 %x, %y
%signed = select i1 %c2, i32 -1, i32 1
%comparator = select i1 %c1, i32 0, i32 %signed
br i1 %c2, label %exit, label %medium
medium:
%c3 = icmp sgt i32 %x, %y
br i1 %c3, label %exit, label %unreached
unreached:
ret i32 %comparator
exit:
ret i32 0
}
define i32 @test_04(i32 %x, i1 %c) {
; CHECK-LABEL: @test_04(
; CHECK-NEXT: bb0:
; CHECK-NEXT: br i1 [[C:%.*]], label [[BB1:%.*]], label [[BB2:%.*]]
; CHECK: bb1:
; CHECK-NEXT: br label [[BB3:%.*]]
; CHECK: bb2:
; CHECK-NEXT: br label [[BB3]]
; CHECK: bb3:
; CHECK-NEXT: [[P:%.*]] = phi i32 [ 0, [[BB1]] ], [ 1, [[BB2]] ]
; CHECK-NEXT: [[A:%.*]] = add i32 [[X:%.*]], 1
; CHECK-NEXT: [[R:%.*]] = add i32 [[P]], [[A]]
; CHECK-NEXT: ret i32 [[R]]
;
bb0:
%a = add i32 %x, 1
br i1 %c, label %bb1, label %bb2
bb1:
br label %bb3
bb2:
br label %bb3
bb3:
%p = phi i32 [0, %bb1], [1, %bb2]
%r = add i32 %p, %a
ret i32 %r
}
; Do not sink into a potentially hotter block.
define i32 @test_05_neg(i32 %x, i1 %cond) {
; CHECK-LABEL: @test_05_neg(
; CHECK-NEXT: bb0:
; CHECK-NEXT: [[A:%.*]] = add i32 [[X:%.*]], 1
; CHECK-NEXT: br i1 [[COND:%.*]], label [[BB1:%.*]], label [[BB2:%.*]]
; CHECK: bb1:
; CHECK-NEXT: br label [[BB3:%.*]]
; CHECK: bb2:
; CHECK-NEXT: [[CALL:%.*]] = call i1 @cond()
; CHECK-NEXT: br i1 [[CALL]], label [[BB2]], label [[BB3]]
; CHECK: bb3:
; CHECK-NEXT: [[P:%.*]] = phi i32 [ 0, [[BB1]] ], [ [[A]], [[BB2]] ]
; CHECK-NEXT: ret i32 [[P]]
;
bb0:
%a = add i32 %x, 1
br i1 %cond, label %bb1, label %bb2
bb1:
br label %bb3
bb2:
%call = call i1 @cond()
br i1 %call, label %bb2, label %bb3
bb3:
%p = phi i32 [0, %bb1], [%a, %bb2]
ret i32 %p
}