1# Copyright (C) 2019 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 LB146014745;
16.super Ljava/lang/Object;
17
18## CHECK-START: java.lang.String B146014745.$noinline$testAppend1(java.lang.String, int) instruction_simplifier (before)
19## CHECK-NOT:                  StringBuilderAppend
20
21## CHECK-START: java.lang.String B146014745.$noinline$testAppend1(java.lang.String, int) instruction_simplifier (after)
22## CHECK:                      StringBuilderAppend
23
24.method public static $noinline$testAppend1(Ljava/lang/String;I)Ljava/lang/String;
25    .registers 4
26# StringBuilder sb = new StringBuilder();
27    new-instance v0, Ljava/lang/StringBuilder;
28    invoke-direct {v0}, Ljava/lang/StringBuilder;-><init>()V
29# sb.append(s).append(i);
30    invoke-virtual {v0, p0}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;
31    move-result-object v1
32    invoke-virtual {v1, p1}, Ljava/lang/StringBuilder;->append(I)Ljava/lang/StringBuilder;
33# return sb.append(s).append(i).toString();
34    invoke-virtual {v0, p0}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;
35    move-result-object v1
36    invoke-virtual {v1, p1}, Ljava/lang/StringBuilder;->append(I)Ljava/lang/StringBuilder;
37    move-result-object v1
38    invoke-virtual {v1}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;
39    move-result-object v1
40    return-object v1
41.end method
42
43## CHECK-START: java.lang.String B146014745.$noinline$testAppend2(java.lang.String, int) instruction_simplifier (after)
44## CHECK-NOT:                  StringBuilderAppend
45
46.method public static $noinline$testAppend2(Ljava/lang/String;I)Ljava/lang/String;
47    .registers 4
48# StringBuilder sb = new StringBuilder();
49    new-instance v0, Ljava/lang/StringBuilder;
50    invoke-direct {v0}, Ljava/lang/StringBuilder;-><init>()V
51# String s2 = sb.append(s).append(i).toString();
52    invoke-virtual {v0, p0}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;
53    move-result-object v1
54    invoke-virtual {v1, p1}, Ljava/lang/StringBuilder;->append(I)Ljava/lang/StringBuilder;
55    move-result-object v1
56    invoke-virtual {v1}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;
57    move-result-object v1
58# return sb.append(s2).toString();
59    invoke-virtual {v0, v1}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;
60    move-result-object v1
61    invoke-virtual {v1}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;
62    move-result-object v1
63    return-object v1
64.end method
65
66## CHECK-START: java.lang.String B146014745.$noinline$testAppend3(java.lang.String, int) instruction_simplifier (after)
67## CHECK-NOT:                  StringBuilderAppend
68
69.method public static $noinline$testAppend3(Ljava/lang/String;I)Ljava/lang/String;
70    .registers 5
71# StringBuilder sb = new StringBuilder();
72    new-instance v0, Ljava/lang/StringBuilder;
73    invoke-direct {v0}, Ljava/lang/StringBuilder;-><init>()V
74# String s2 = sb.append(s).toString();
75    invoke-virtual {v0, p0}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;
76    move-result-object v2
77    invoke-virtual {v2}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;
78    move-result-object v2
79# return sb.append(i).append(s2).append(i);
80    invoke-virtual {v0, p1}, Ljava/lang/StringBuilder;->append(I)Ljava/lang/StringBuilder;
81    move-result-object v1
82    invoke-virtual {v1, v2}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;
83    move-result-object v1
84    invoke-virtual {v1, p1}, Ljava/lang/StringBuilder;->append(I)Ljava/lang/StringBuilder;
85# return sb.toString();
86    invoke-virtual {v0}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;
87    move-result-object v1
88    return-object v1
89.end method
90
91# The following is a jasmin version.
92# Unfortunately, this would be translated without the required move-result-object,
93# instead using the register initialized by new-instance for subsequent calls.
94
95#.class public B146014745
96#.super java/lang/Object
97
98#.method public static $noinline$testAppend1(Ljava/lang/String;I)Ljava/lang/String;
99#    .limit stack 3
100#    .limit locals 2
101#; StringBuilder sb = new StringBuilder();
102#    new java/lang/StringBuilder
103#    dup
104#    invokespecial java.lang.StringBuilder.<init>()V
105#; sb.append(s).append(i);
106#    dup
107#    aload_0
108#    invokevirtual java.lang.StringBuilder.append(Ljava/lang/String;)Ljava/lang/StringBuilder;
109#    iload_1
110#    invokevirtual java.lang.StringBuilder.append(I)Ljava/lang/StringBuilder;
111#    pop
112#; return sb.append(s).append(i).toString();
113#    aload_0
114#    invokevirtual java.lang.StringBuilder.append(Ljava/lang/String;)Ljava/lang/StringBuilder;
115#    iload_1
116#    invokevirtual java.lang.StringBuilder.append(I)Ljava/lang/StringBuilder;
117#    invokevirtual java.lang.StringBuilder.toString()Ljava/lang/String;
118#    areturn
119#.end method
120
121#.method public static $noinline$testAppend2(Ljava/lang/String;I)Ljava/lang/String;
122#    .limit stack 3
123#    .limit locals 2
124#; StringBuilder sb = new StringBuilder();
125#    new java/lang/StringBuilder
126#    dup
127#    invokespecial java.lang.StringBuilder.<init>()V
128#; String s2 = sb.append(s).append(i).toString();
129#    dup
130#    aload_0
131#    invokevirtual java.lang.StringBuilder.append(Ljava/lang/String;)Ljava/lang/StringBuilder;
132#    iload_1
133#    invokevirtual java.lang.StringBuilder.append(I)Ljava/lang/StringBuilder;
134#    invokevirtual java.lang.StringBuilder.toString()Ljava/lang/String;
135#; return sb.append(s2).toString();
136#    invokevirtual java.lang.StringBuilder.append(Ljava/lang/String;)Ljava/lang/StringBuilder;
137#    invokevirtual java.lang.StringBuilder.toString()Ljava/lang/String;
138#    areturn
139#.end method
140
141#.method public static $noinline$testAppend3(Ljava/lang/String;I)Ljava/lang/String;
142#    .limit stack 3
143#    .limit locals 3
144#; StringBuilder sb = new StringBuilder();
145#    new java/lang/StringBuilder
146#    dup
147#    invokespecial java.lang.StringBuilder.<init>()V
148#; String s2 = sb.append(s).toString();
149#    dup
150#    aload_0
151#    invokevirtual java.lang.StringBuilder.append(Ljava/lang/String;)Ljava/lang/StringBuilder;
152#    invokevirtual java.lang.StringBuilder.toString()Ljava/lang/String;
153#    astore_2
154#; return sb.append(i).append(s2).append(i);
155#    iload_1
156#    invokevirtual java.lang.StringBuilder.append(I)Ljava/lang/StringBuilder;
157#    aload_2
158#    invokevirtual java.lang.StringBuilder.append(Ljava/lang/String;)Ljava/lang/StringBuilder;
159#    iload_1
160#    invokevirtual java.lang.StringBuilder.append(I)Ljava/lang/StringBuilder;
161#    invokevirtual java.lang.StringBuilder.toString()Ljava/lang/String;
162#    areturn
163#.end method
164