summaryrefslogtreecommitdiff
path: root/test/543-checker-dce-trycatch/smali/TestCase.smali
blob: 7ad9ba8e647a534cff19cc754015abe435d47b85 (plain)
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
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
# Copyright (C) 2015 The Android Open Source Project
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

.class public LTestCase;
.super Ljava/lang/Object;

.field public static sField:I

.method private static $inline$False()Z
    .registers 1
    const/4 v0, 0x0
    return v0
.end method

# Test a case when one entering TryBoundary is dead but the rest of the try
# block remains live.

## CHECK-START: int TestCase.testDeadEntry(int, int, int, int) dead_code_elimination$after_inlining (before)
## CHECK: Add

## CHECK-START: int TestCase.testDeadEntry(int, int, int, int) dead_code_elimination$after_inlining (before)
## CHECK:     TryBoundary kind:entry
## CHECK:     TryBoundary kind:entry
## CHECK-NOT: TryBoundary kind:entry

## CHECK-START: int TestCase.testDeadEntry(int, int, int, int) dead_code_elimination$after_inlining (after)
## CHECK-NOT: Add

## CHECK-START: int TestCase.testDeadEntry(int, int, int, int) dead_code_elimination$after_inlining (after)
## CHECK:     TryBoundary kind:entry
## CHECK-NOT: TryBoundary kind:entry

.method public static testDeadEntry(IIII)I
    .registers 5

    invoke-static {}, LTestCase;->$inline$False()Z
    move-result v0

    if-eqz v0, :else

    add-int/2addr p0, p1

    :try_start
    div-int/2addr p0, p2

    :else
    div-int/2addr p0, p3
    :try_end
    .catchall {:try_start .. :try_end} :catch_all

    :return
    return p0

    :catch_all
    const/4 p0, -0x1
    goto :return

.end method

# Test a case when one exiting TryBoundary is dead but the rest of the try
# block remains live.

## CHECK-START: int TestCase.testDeadExit(int, int, int, int) dead_code_elimination$after_inlining (before)
## CHECK: Add

## CHECK-START: int TestCase.testDeadExit(int, int, int, int) dead_code_elimination$after_inlining (before)
## CHECK:     TryBoundary kind:exit
## CHECK:     TryBoundary kind:exit
## CHECK-NOT: TryBoundary kind:exit

## CHECK-START: int TestCase.testDeadExit(int, int, int, int) dead_code_elimination$after_inlining (after)
## CHECK-NOT: Add

## CHECK-START: int TestCase.testDeadExit(int, int, int, int) dead_code_elimination$after_inlining (after)
## CHECK:     TryBoundary kind:exit
## CHECK-NOT: TryBoundary kind:exit

.method public static testDeadExit(IIII)I
    .registers 5

    invoke-static {}, LTestCase;->$inline$False()Z
    move-result v0

    :try_start
    div-int/2addr p0, p2

    if-nez v0, :else

    div-int/2addr p0, p3
    goto :return
    :try_end
    .catchall {:try_start .. :try_end} :catch_all

    :else
    add-int/2addr p0, p1

    :return
    return p0

    :catch_all
    const/4 p0, -0x1
    goto :return

.end method

# Test that a catch block remains live and consistent if some of try blocks
# throwing into it are removed.

## CHECK-START: int TestCase.testOneTryBlockDead(int, int, int, int) dead_code_elimination$after_inlining (before)
## CHECK:     TryBoundary kind:entry
## CHECK:     TryBoundary kind:entry
## CHECK-NOT: TryBoundary kind:entry

## CHECK-START: int TestCase.testOneTryBlockDead(int, int, int, int) dead_code_elimination$after_inlining (before)
## CHECK:     TryBoundary kind:exit
## CHECK:     TryBoundary kind:exit
## CHECK-NOT: TryBoundary kind:exit

## CHECK-START: int TestCase.testOneTryBlockDead(int, int, int, int) dead_code_elimination$after_inlining (after)
## CHECK:     TryBoundary kind:entry
## CHECK-NOT: TryBoundary kind:entry

## CHECK-START: int TestCase.testOneTryBlockDead(int, int, int, int) dead_code_elimination$after_inlining (after)
## CHECK:     TryBoundary kind:exit
## CHECK-NOT: TryBoundary kind:exit

.method public static testOneTryBlockDead(IIII)I
    .registers 5

    invoke-static {}, LTestCase;->$inline$False()Z
    move-result v0

    :try_start_1
    div-int/2addr p0, p2
    :try_end_1
    .catchall {:try_start_1 .. :try_end_1} :catch_all

    if-eqz v0, :return

    :try_start_2
    div-int/2addr p0, p3
    :try_end_2
    .catchall {:try_start_2 .. :try_end_2} :catch_all

    :return
    return p0

    :catch_all
    const/4 p0, -0x1
    goto :return

.end method

# Test that try block membership is recomputed. In this test case, the try entry
# stored with the merge block gets deleted and SSAChecker would fail if it was
# not replaced with the try entry from the live branch.

.method public static testRecomputeTryMembership(IIII)I
    .registers 5

    invoke-static {}, LTestCase;->$inline$False()Z
    move-result v0

    if-eqz v0, :else

    # Dead branch
    :try_start
    div-int/2addr p0, p1
    goto :merge

    # Live branch
    :else
    div-int/2addr p0, p2

    # Merge block. Make complex so it does not get merged with the live branch.
    :merge
    div-int/2addr p0, p3
    if-eqz p0, :else2
    div-int/2addr p0, p3
    :else2
    :try_end
    .catchall {:try_start .. :try_end} :catch_all

    :return
    return p0

    :catch_all
    const/4 p0, -0x1
    goto :return

.end method

# Test that DCE removes catch phi uses of instructions defined in dead try blocks.

## CHECK-START: int TestCase.testCatchPhiInputs_DefinedInTryBlock(int, int, int, int) dead_code_elimination$after_inlining (before)
## CHECK-DAG:     <<Arg0:i\d+>>      ParameterValue
## CHECK-DAG:     <<Arg1:i\d+>>      ParameterValue
## CHECK-DAG:     <<Const0xa:i\d+>>  IntConstant 10
## CHECK-DAG:     <<Const0xb:i\d+>>  IntConstant 11
## CHECK-DAG:     <<Const0xc:i\d+>>  IntConstant 12
## CHECK-DAG:     <<Const0xd:i\d+>>  IntConstant 13
## CHECK-DAG:     <<Const0xe:i\d+>>  IntConstant 14
## CHECK-DAG:     <<Const0xf:i\d+>>  IntConstant 15
## CHECK-DAG:     <<Const0x10:i\d+>> IntConstant 16
## CHECK-DAG:     <<Const0x11:i\d+>> IntConstant 17
## CHECK-DAG:     <<Add:i\d+>>       Add [<<Arg0>>,<<Arg1>>]
## CHECK-DAG:     <<Phi:i\d+>>       Phi [<<Add>>,<<Const0xf>>] reg:3 is_catch_phi:false
## CHECK-DAG:                        Phi [<<Const0xa>>,<<Const0xb>>,<<Const0xd>>] reg:1 is_catch_phi:true
## CHECK-DAG:                        Phi [<<Add>>,<<Const0xc>>,<<Const0xe>>] reg:2 is_catch_phi:true
## CHECK-DAG:                        Phi [<<Phi>>,<<Const0x10>>,<<Const0x11>>] reg:3 is_catch_phi:true

## CHECK-START: int TestCase.testCatchPhiInputs_DefinedInTryBlock(int, int, int, int) dead_code_elimination$after_inlining (after)
## CHECK-DAG:     <<Const0xb:i\d+>>  IntConstant 11
## CHECK-DAG:     <<Const0xc:i\d+>>  IntConstant 12
## CHECK-DAG:     <<Const0xd:i\d+>>  IntConstant 13
## CHECK-DAG:     <<Const0xe:i\d+>>  IntConstant 14
## CHECK-DAG:     <<Const0x10:i\d+>> IntConstant 16
## CHECK-DAG:     <<Const0x11:i\d+>> IntConstant 17
## CHECK-DAG:                        Phi [<<Const0xb>>,<<Const0xd>>] reg:1 is_catch_phi:true
## CHECK-DAG:                        Phi [<<Const0xc>>,<<Const0xe>>] reg:2 is_catch_phi:true
## CHECK-DAG:                        Phi [<<Const0x10>>,<<Const0x11>>] reg:3 is_catch_phi:true

.method public static testCatchPhiInputs_DefinedInTryBlock(IIII)I
    .registers 8

    invoke-static {}, LTestCase;->$inline$False()Z
    move-result v0

    if-eqz v0, :else

    shr-int/2addr p2, p3

    :try_start
    const v1, 0xa                  # dead catch phi input, defined in entry block (HInstruction)
    add-int v2, p0, p1             # dead catch phi input, defined in the dead block (HInstruction)
    move v3, v2
    if-eqz v3, :define_phi
    const v3, 0xf
    :define_phi
    # v3 = Phi [Add, 0xf]          # dead catch phi input, defined in the dead block (HPhi)
    div-int/2addr p0, v2

    :else
    const v1, 0xb                  # live catch phi input
    const v2, 0xc                  # live catch phi input
    const v3, 0x10                 # live catch phi input
    div-int/2addr p0, p3

    const v1, 0xd                  # live catch phi input
    const v2, 0xe                  # live catch phi input
    const v3, 0x11                 # live catch phi input
    div-int/2addr p0, p1
    :try_end
    .catchall {:try_start .. :try_end} :catch_all

    :return
    return p0

    :catch_all
    sub-int p0, v1, v2      # use catch phi values
    sub-int p0, p0, v3      # use catch phi values
    goto :return

.end method

# Test that DCE does not remove catch phi uses of instructions defined outside
# dead try blocks.

## CHECK-START: int TestCase.testCatchPhiInputs_DefinedOutsideTryBlock(int, int, int, int) dead_code_elimination$after_inlining (before)
## CHECK-DAG:     <<Const0xa:i\d+>> IntConstant 10
## CHECK-DAG:     <<Const0xb:i\d+>> IntConstant 11
## CHECK-DAG:     <<Const0xc:i\d+>> IntConstant 12
## CHECK-DAG:     <<Const0xd:i\d+>> IntConstant 13
## CHECK-DAG:     <<Const0xe:i\d+>> IntConstant 14
## CHECK-DAG:     <<Const0xf:i\d+>> IntConstant 15
## CHECK-DAG:                       Phi [<<Const0xa>>,<<Const0xb>>,<<Const0xd>>] reg:1 is_catch_phi:true
## CHECK-DAG:                       Phi [<<Const0xf>>,<<Const0xc>>,<<Const0xe>>] reg:2 is_catch_phi:true

## CHECK-START: int TestCase.testCatchPhiInputs_DefinedOutsideTryBlock(int, int, int, int) dead_code_elimination$after_inlining (after)
## CHECK-DAG:     <<Const0xa:i\d+>> IntConstant 10
## CHECK-DAG:     <<Const0xb:i\d+>> IntConstant 11
## CHECK-DAG:     <<Const0xc:i\d+>> IntConstant 12
## CHECK-DAG:     <<Const0xd:i\d+>> IntConstant 13
## CHECK-DAG:     <<Const0xe:i\d+>> IntConstant 14
## CHECK-DAG:     <<Const0xf:i\d+>> IntConstant 15
## CHECK-DAG:                       Phi [<<Const0xa>>,<<Const0xb>>,<<Const0xd>>] reg:1 is_catch_phi:true
## CHECK-DAG:                       Phi [<<Const0xf>>,<<Const0xc>>,<<Const0xe>>] reg:2 is_catch_phi:true

.method public static testCatchPhiInputs_DefinedOutsideTryBlock(IIII)I
    .registers 7

    invoke-static {}, LTestCase;->$inline$False()Z
    move-result v0

    if-eqz v0, :else

    shr-int/2addr p2, p3

    :try_start
    const v1, 0xa           # dead catch phi input, defined in entry block
    const v2, 0xf           # dead catch phi input, defined in entry block
    div-int/2addr p0, v2

    :else
    const v1, 0xb           # live catch phi input
    const v2, 0xc           # live catch phi input
    div-int/2addr p0, p3

    const v1, 0xd           # live catch phi input
    const v2, 0xe           # live catch phi input
    div-int/2addr p0, p1
    :try_end
    .catchall {:try_start .. :try_end} :catch_all

    :return
    return p0

    :catch_all
    sub-int p0, v1, v2      # use catch phi values
    goto :return

.end method