1# Copyright (C) 2015 The Android Open Source Project
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7#      http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15.class public LRegisterAllocator;
16
17.super Ljava/lang/Object;
18
19# Test that catch phis are allocated to a stack slot, and that equivalent catch
20# phis are allocated to the same stack slot.
21
22## CHECK-START: int RegisterAllocator.testEquivalentCatchPhiSlot_Single(int, int, int) register (after)
23## CHECK-DAG:     Phi reg:0 is_catch_phi:true locations:{{\[.*\]}}-><<SlotA1:\d+>>(sp)
24## CHECK-DAG:     Phi reg:0 is_catch_phi:true locations:{{\[.*\]}}-><<SlotA2:\d+>>(sp)
25## CHECK-DAG:     Phi reg:1 is_catch_phi:true locations:{{\[.*\]}}-><<SlotB:\d+>>(sp)
26## CHECK-EVAL:    <<SlotA1>> == <<SlotA2>>
27## CHECK-EVAL:    <<SlotB>> != <<SlotA1>>
28
29.method public static testEquivalentCatchPhiSlot_Single(III)I
30  .registers 8
31
32  :try_start
33  const/high16 v0, 0x40000000 # float 2
34  move v1, p0
35  div-int/2addr p0, p1
36
37  const/high16 v0, 0x41000000 # float 8
38  move v1, p1
39  div-int/2addr p0, p2
40  goto :return
41  :try_end
42  .catchall {:try_start .. :try_end} :catch_all
43
44  :catch_all
45  # 2x CatchPhi for v0, 1x for v1
46  if-eqz v1, :use_as_float
47
48  :use_as_int
49  goto :return
50
51  :use_as_float
52  float-to-int v0, v0
53
54  :return
55  return v0
56.end method
57
58# Test that wide catch phis are allocated to two stack slots.
59
60## CHECK-START: long RegisterAllocator.testEquivalentCatchPhiSlot_Wide(int, int, int) register (after)
61## CHECK-DAG:     Phi reg:0 is_catch_phi:true locations:{{\[.*\]}}->2x<<SlotB1:\d+>>(sp)
62## CHECK-DAG:     Phi reg:0 is_catch_phi:true locations:{{\[.*\]}}->2x<<SlotB2:\d+>>(sp)
63## CHECK-DAG:     Phi reg:2 is_catch_phi:true locations:{{\[.*\]}}-><<SlotA:\d+>>(sp)
64## CHECK-EVAL:    <<SlotB1>> == <<SlotB2>>
65## CHECK-EVAL:    abs(<<SlotA>> - <<SlotB1>>) >= 8
66
67.method public static testEquivalentCatchPhiSlot_Wide(III)J
68  .registers 8
69
70  :try_start
71  const-wide/high16 v0, 0x4000000000000000L # double 2
72  move v2, p0
73  div-int/2addr p0, p1
74
75  const-wide/high16 v0, 0x4100000000000000L # double 8
76  move v2, p1
77  div-int/2addr p0, p2
78  goto :return
79  :try_end
80  .catchall {:try_start .. :try_end} :catch_all
81
82  :catch_all
83  # 2x CatchPhi for v0, 1x for v2
84  if-eqz v2, :use_as_double
85
86  :use_as_long
87  goto :return
88
89  :use_as_double
90  double-to-long v0, v0
91
92  :return
93  return-wide v0
94.end method
95