restore-ssa.ll
8.29 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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
; RUN: opt < %s -unify-loop-exits -enable-new-pm=0 -S | FileCheck %s
; Loop consists of A and B:
; - A is the header
; - A and B are exiting blocks
; - C and return are exit blocks.
; Pattern: Value (%mytmp42) defined in exiting block (A) and used in
; exit block (return).
; The relevant code uses DT::dominates(Value,
; BasicBlock). This is misnamed because it actually checks
; strict dominance, causing the pattern to be miscompiled
; (the use receives an undef value).
define i32 @exiting-used-in-exit(i32* %arg1, i32* %arg2) local_unnamed_addr align 2 {
; CHECK-LABEL: @exiting-used-in-exit(
; CHECK-NEXT: entry:
; CHECK-NEXT: br label [[A:%.*]]
; CHECK: A:
; CHECK-NEXT: [[MYTMP42:%.*]] = load i32, i32* [[ARG1:%.*]], align 4
; CHECK-NEXT: [[CMP1:%.*]] = icmp slt i32 [[MYTMP42]], 0
; CHECK-NEXT: br i1 [[CMP1]], label [[B:%.*]], label [[LOOP_EXIT_GUARD:%.*]]
; CHECK: B:
; CHECK-NEXT: [[MYTMP41:%.*]] = load i32, i32* [[ARG2:%.*]], align 4
; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[MYTMP41]], 0
; CHECK-NEXT: br i1 [[CMP]], label [[A]], label [[LOOP_EXIT_GUARD]]
; CHECK: C:
; CHECK-NEXT: [[INC:%.*]] = add i32 [[MYTMP41_MOVED:%.*]], 1
; CHECK-NEXT: br label [[RETURN:%.*]]
; CHECK: return:
; CHECK-NEXT: [[PHI:%.*]] = phi i32 [ [[INC]], [[C:%.*]] ], [ [[PHI_MOVED:%.*]], [[LOOP_EXIT_GUARD]] ]
; CHECK-NEXT: ret i32 [[PHI]]
; CHECK: loop.exit.guard:
; CHECK-NEXT: [[GUARD_RETURN:%.*]] = phi i1 [ true, [[A]] ], [ false, [[B]] ]
; CHECK-NEXT: [[PHI_MOVED]] = phi i32 [ [[MYTMP42]], [[A]] ], [ undef, [[B]] ]
; CHECK-NEXT: [[MYTMP41_MOVED]] = phi i32 [ undef, [[A]] ], [ [[MYTMP41]], [[B]] ]
; CHECK-NEXT: br i1 [[GUARD_RETURN]], label [[RETURN]], label [[C]]
;
entry:
br label %A
A:
%mytmp42 = load i32, i32* %arg1, align 4
%cmp1 = icmp slt i32 %mytmp42, 0
br i1 %cmp1, label %B, label %return
B:
%mytmp41 = load i32, i32* %arg2, align 4
%cmp = icmp slt i32 %mytmp41, 0
br i1 %cmp, label %A, label %C
C:
%inc = add i32 %mytmp41, 1
br label %return
return:
%phi = phi i32 [ %inc, %C ], [ %mytmp42, %A ]
ret i32 %phi
}
; Loop consists of A, B and C:
; - A is the header
; - A and C are exiting blocks
; - B is an "internal" block that dominates exiting block C
; - D and return are exit blocks.
; Pattern: Value (%mytmp41) defined in internal block (B) and used in an
; exit block (D).
define i32 @internal-used-in-exit(i32* %arg1, i32* %arg2) local_unnamed_addr align 2 {
; CHECK-LABEL: @internal-used-in-exit(
; CHECK-NEXT: entry:
; CHECK-NEXT: [[MYTMP42:%.*]] = load i32, i32* [[ARG1:%.*]], align 4
; CHECK-NEXT: br label [[A:%.*]]
; CHECK: A:
; CHECK-NEXT: [[CMP1:%.*]] = icmp slt i32 [[MYTMP42]], 0
; CHECK-NEXT: br i1 [[CMP1]], label [[B:%.*]], label [[LOOP_EXIT_GUARD:%.*]]
; CHECK: B:
; CHECK-NEXT: [[MYTMP41:%.*]] = load i32, i32* [[ARG2:%.*]], align 4
; CHECK-NEXT: br label [[C:%.*]]
; CHECK: C:
; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[MYTMP42]], 0
; CHECK-NEXT: br i1 [[CMP]], label [[A]], label [[LOOP_EXIT_GUARD]]
; CHECK: D:
; CHECK-NEXT: [[INC:%.*]] = add i32 [[MYTMP41_MOVED:%.*]], 1
; CHECK-NEXT: br label [[RETURN:%.*]]
; CHECK: return:
; CHECK-NEXT: ret i32 0
; CHECK: loop.exit.guard:
; CHECK-NEXT: [[GUARD_RETURN:%.*]] = phi i1 [ true, [[A]] ], [ false, [[C]] ]
; CHECK-NEXT: [[MYTMP41_MOVED]] = phi i32 [ undef, [[A]] ], [ [[MYTMP41]], [[C]] ]
; CHECK-NEXT: br i1 [[GUARD_RETURN]], label [[RETURN]], label [[D:%.*]]
;
entry:
%mytmp42 = load i32, i32* %arg1, align 4
br label %A
A:
%cmp1 = icmp slt i32 %mytmp42, 0
br i1 %cmp1, label %B, label %return
B:
%mytmp41 = load i32, i32* %arg2, align 4
br label %C
C:
%cmp = icmp slt i32 %mytmp42, 0
br i1 %cmp, label %A, label %D
D:
%inc = add i32 %mytmp41, 1
br label %return
return:
ret i32 0
}
; Loop consists of A, B and C:
; - A is the header
; - A and C are exiting blocks
; - B is an "internal" block that dominates exiting block C
; - D and return are exit blocks.
; Pattern: %return contains a phi node that receives values from
; %entry, %A and %D. This mixes all the special cases in a single phi.
define i32 @mixed-use-in-exit(i32* %arg1, i32* %arg2) local_unnamed_addr align 2 {
; CHECK-LABEL: @mixed-use-in-exit(
; CHECK-NEXT: entry:
; CHECK-NEXT: [[MYTMP42:%.*]] = load i32, i32* [[ARG1:%.*]], align 4
; CHECK-NEXT: [[CMP2:%.*]] = icmp slt i32 [[MYTMP42]], 0
; CHECK-NEXT: br i1 [[CMP2]], label [[A:%.*]], label [[RETURN:%.*]]
; CHECK: A:
; CHECK-NEXT: [[MYTMP43:%.*]] = add i32 [[MYTMP42]], 1
; CHECK-NEXT: [[CMP1:%.*]] = icmp slt i32 [[MYTMP42]], 0
; CHECK-NEXT: br i1 [[CMP1]], label [[B:%.*]], label [[LOOP_EXIT_GUARD:%.*]]
; CHECK: B:
; CHECK-NEXT: [[MYTMP41:%.*]] = load i32, i32* [[ARG2:%.*]], align 4
; CHECK-NEXT: br label [[C:%.*]]
; CHECK: C:
; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[MYTMP42]], 0
; CHECK-NEXT: br i1 [[CMP]], label [[A]], label [[LOOP_EXIT_GUARD]]
; CHECK: D:
; CHECK-NEXT: br label [[RETURN]]
; CHECK: return:
; CHECK-NEXT: [[PHI:%.*]] = phi i32 [ [[MYTMP41_MOVED:%.*]], [[D:%.*]] ], [ [[MYTMP42]], [[ENTRY:%.*]] ], [ [[PHI_MOVED:%.*]], [[LOOP_EXIT_GUARD]] ]
; CHECK-NEXT: ret i32 [[PHI]]
; CHECK: loop.exit.guard:
; CHECK-NEXT: [[GUARD_RETURN:%.*]] = phi i1 [ true, [[A]] ], [ false, [[C]] ]
; CHECK-NEXT: [[PHI_MOVED]] = phi i32 [ [[MYTMP43]], [[A]] ], [ undef, [[C]] ]
; CHECK-NEXT: [[MYTMP41_MOVED]] = phi i32 [ undef, [[A]] ], [ [[MYTMP41]], [[C]] ]
; CHECK-NEXT: br i1 [[GUARD_RETURN]], label [[RETURN]], label [[D]]
;
entry:
%mytmp42 = load i32, i32* %arg1, align 4
%cmp2 = icmp slt i32 %mytmp42, 0
br i1 %cmp2, label %A, label %return
A:
%mytmp43 = add i32 %mytmp42, 1
%cmp1 = icmp slt i32 %mytmp42, 0
br i1 %cmp1, label %B, label %return
B:
%mytmp41 = load i32, i32* %arg2, align 4
br label %C
C:
%cmp = icmp slt i32 %mytmp42, 0
br i1 %cmp, label %A, label %D
D:
br label %return
return:
%phi = phi i32 [ %mytmp41, %D ], [ %mytmp43, %A ], [%mytmp42, %entry]
ret i32 %phi
}
; Loop consists of A, B and C:
; - A is the header
; - A and C are exiting blocks
; - B is an "internal" block that dominates exiting block C
; - D and E are exit blocks.
; Pattern: Value (%mytmp41) defined in internal block (B) and used in a
; downstream block not related to the loop (return). The use
; is a phi where the incoming block for %mytmp41 is not related
; to the loop (D).
; This pattern does not involve either the exiting blocks or
; the exit blocks, which catches any such assumptions built
; into the SSA reconstruction phase.
define i32 @phi-via-external-block(i32* %arg1, i32* %arg2) local_unnamed_addr align 2 {
; CHECK-LABEL: @phi-via-external-block(
; CHECK-NEXT: entry:
; CHECK-NEXT: [[MYTMP42:%.*]] = load i32, i32* [[ARG1:%.*]], align 4
; CHECK-NEXT: br label [[A:%.*]]
; CHECK: A:
; CHECK-NEXT: [[CMP1:%.*]] = icmp slt i32 [[MYTMP42]], 0
; CHECK-NEXT: br i1 [[CMP1]], label [[B:%.*]], label [[LOOP_EXIT_GUARD:%.*]]
; CHECK: B:
; CHECK-NEXT: [[MYTMP41:%.*]] = load i32, i32* [[ARG2:%.*]], align 4
; CHECK-NEXT: br label [[C:%.*]]
; CHECK: C:
; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[MYTMP42]], 0
; CHECK-NEXT: br i1 [[CMP]], label [[A]], label [[LOOP_EXIT_GUARD]]
; CHECK: D:
; CHECK-NEXT: br label [[RETURN:%.*]]
; CHECK: E:
; CHECK-NEXT: br label [[RETURN]]
; CHECK: return:
; CHECK-NEXT: [[PHI:%.*]] = phi i32 [ [[MYTMP41_MOVED:%.*]], [[D:%.*]] ], [ [[MYTMP42]], [[E:%.*]] ]
; CHECK-NEXT: ret i32 [[PHI]]
; CHECK: loop.exit.guard:
; CHECK-NEXT: [[GUARD_E:%.*]] = phi i1 [ true, [[A]] ], [ false, [[C]] ]
; CHECK-NEXT: [[MYTMP41_MOVED]] = phi i32 [ undef, [[A]] ], [ [[MYTMP41]], [[C]] ]
; CHECK-NEXT: br i1 [[GUARD_E]], label [[E]], label [[D]]
;
entry:
%mytmp42 = load i32, i32* %arg1, align 4
br label %A
A:
%cmp1 = icmp slt i32 %mytmp42, 0
br i1 %cmp1, label %B, label %E
B:
%mytmp41 = load i32, i32* %arg2, align 4
br label %C
C:
%cmp = icmp slt i32 %mytmp42, 0
br i1 %cmp, label %A, label %D
D:
br label %return
E:
br label %return
return:
%phi = phi i32 [ %mytmp41, %D ], [ %mytmp42, %E ]
ret i32 %phi
}