1 # Copyright (C) 2018 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 LMain2; 16 .super Ljava/lang/Object; 17 .source "Main.java" 18 19 # direct methods 20 21 ## CHECK-START: int Main2.test4(TestClass, boolean) load_store_elimination (before) 22 ## CHECK: InstanceFieldSet 23 ## CHECK: InstanceFieldGet 24 ## CHECK: Return 25 ## CHECK: InstanceFieldSet 26 27 ## CHECK-START: int Main2.test4(TestClass, boolean) load_store_elimination (after) 28 ## CHECK: InstanceFieldSet 29 ## CHECK-NOT: NullCheck 30 ## CHECK-NOT: InstanceFieldGet 31 ## CHECK: Return 32 ## CHECK: InstanceFieldSet 33 34 # Set and merge the same value in two branches. 35 36 # Original java source: 37 # 38 # static int test4(TestClass obj, boolean b) { 39 # if (b) { 40 # obj.i = 1; 41 # } else { 42 # obj.i = 1; 43 # } 44 # return obj.i; 45 # } 46 47 .method public static test4(LTestClass;Z)I 48 .registers 3 49 .param p0, "obj" # LTestClass; 50 .param p1, "b" # Z 51 52 .prologue 53 const/4 v0, 0x1 54 55 .line 185 56 if-eqz p1, :cond_8 57 58 .line 186 59 iput v0, p0, LTestClass;->i:I 60 61 .line 190 62 :goto_5 63 iget v0, p0, LTestClass;->i:I 64 65 return v0 66 67 .line 188 68 :cond_8 69 iput v0, p0, LTestClass;->i:I 70 71 goto :goto_5 72 .end method 73 74 ## CHECK-START: int Main2.test5(TestClass, boolean) load_store_elimination (before) 75 ## CHECK: InstanceFieldSet 76 ## CHECK: InstanceFieldGet 77 ## CHECK: Return 78 ## CHECK: InstanceFieldSet 79 80 ## CHECK-START: int Main2.test5(TestClass, boolean) load_store_elimination (after) 81 ## CHECK: InstanceFieldSet 82 ## CHECK: InstanceFieldGet 83 ## CHECK: Return 84 ## CHECK: InstanceFieldSet 85 86 # Set and merge different values in two branches. 87 # Original java source: 88 # 89 # static int test5(TestClass obj, boolean b) { 90 # if (b) { 91 # obj.i = 1; 92 # } else { 93 # obj.i = 2; 94 # } 95 # return obj.i; 96 # } 97 98 .method public static test5(LTestClass;Z)I 99 .registers 3 100 .param p0, "obj" # LTestClass; 101 .param p1, "b" # Z 102 103 .prologue 104 .line 207 105 if-eqz p1, :cond_8 106 107 .line 208 108 const/4 v0, 0x1 109 110 iput v0, p0, LTestClass;->i:I 111 112 .line 212 113 :goto_5 114 iget v0, p0, LTestClass;->i:I 115 116 return v0 117 118 .line 210 119 :cond_8 120 const/4 v0, 0x2 121 122 iput v0, p0, LTestClass;->i:I 123 124 goto :goto_5 125 .end method 126 127 ## CHECK-START: int Main2.test10(TestClass) load_store_elimination (before) 128 ## CHECK: StaticFieldGet 129 ## CHECK: InstanceFieldGet 130 ## CHECK: StaticFieldSet 131 ## CHECK: InstanceFieldGet 132 133 ## CHECK-START: int Main2.test10(TestClass) load_store_elimination (after) 134 ## CHECK: StaticFieldGet 135 ## CHECK: InstanceFieldGet 136 ## CHECK: StaticFieldSet 137 ## CHECK-NOT: NullCheck 138 ## CHECK-NOT: InstanceFieldGet 139 140 # Original java source: 141 # 142 # // Static fields shouldn't alias with instance fields. 143 # static int test10(TestClass obj) { 144 # TestClass.si += obj.i; 145 # return obj.i; 146 # } 147 148 .method public static test10(LTestClass;)I 149 .registers 3 150 .param p0, "obj" # LTestClass; 151 sget v0, LTestClass;->si:I 152 iget v1, p0, LTestClass;->i:I 153 add-int/2addr v0, v1 154 sput v0, LTestClass;->si:I 155 iget p0, p0, LTestClass;->i:I 156 return p0 157 .end method 158 159 ## CHECK-START: int Main2.test23(boolean) load_store_elimination (before) 160 ## CHECK: NewInstance 161 ## CHECK: InstanceFieldSet 162 ## CHECK: InstanceFieldGet 163 ## CHECK: InstanceFieldSet 164 ## CHECK: InstanceFieldGet 165 ## CHECK: Return 166 ## CHECK: InstanceFieldGet 167 ## CHECK: InstanceFieldSet 168 169 ## CHECK-START: int Main2.test23(boolean) load_store_elimination (after) 170 ## CHECK: NewInstance 171 ## CHECK-NOT: InstanceFieldSet 172 ## CHECK-NOT: InstanceFieldGet 173 ## CHECK: InstanceFieldSet 174 ## CHECK: InstanceFieldGet 175 ## CHECK: Return 176 ## CHECK-NOT: InstanceFieldGet 177 ## CHECK: InstanceFieldSet 178 179 # Test store elimination on merging. 180 181 # Original java source: 182 # 183 # static int test23(boolean b) { 184 # TestClass obj = new TestClass(); 185 # obj.i = 3; // This store can be eliminated since the value flows into each branch. 186 # if (b) { 187 # obj.i += 1; // This store cannot be eliminated due to the merge later. 188 # } else { 189 # obj.i += 2; // This store cannot be eliminated due to the merge later. 190 # } 191 # return obj.i; 192 # } 193 194 .method public static test23(Z)I 195 .registers 3 196 .param p0, "b" # Z 197 198 .prologue 199 .line 582 200 new-instance v0, LTestClass; 201 202 invoke-direct {v0}, LTestClass;-><init>()V 203 204 .line 583 205 .local v0, "obj":LTestClass; 206 const/4 v1, 0x3 207 208 iput v1, v0, LTestClass;->i:I 209 210 .line 584 211 if-eqz p0, :cond_13 212 213 .line 585 214 iget v1, v0, LTestClass;->i:I 215 216 add-int/lit8 v1, v1, 0x1 217 218 iput v1, v0, LTestClass;->i:I 219 220 .line 589 221 :goto_10 222 iget v1, v0, LTestClass;->i:I 223 224 return v1 225 226 .line 587 227 :cond_13 228 iget v1, v0, LTestClass;->i:I 229 230 add-int/lit8 v1, v1, 0x2 231 232 iput v1, v0, LTestClass;->i:I 233 234 goto :goto_10 235 .end method 236 237 ## CHECK-START: float Main2.test24() load_store_elimination (before) 238 ## CHECK-DAG: <<True:i\d+>> IntConstant 1 239 ## CHECK-DAG: <<Float8:f\d+>> FloatConstant 8 240 ## CHECK-DAG: <<Float42:f\d+>> FloatConstant 42 241 ## CHECK-DAG: <<Obj:l\d+>> NewInstance 242 ## CHECK-DAG: InstanceFieldSet [<<Obj>>,<<True>>] 243 ## CHECK-DAG: InstanceFieldSet [<<Obj>>,<<Float8>>] 244 ## CHECK-DAG: <<GetTest:z\d+>> InstanceFieldGet [<<Obj>>] 245 ## CHECK-DAG: <<GetField:f\d+>> InstanceFieldGet [<<Obj>>] 246 ## CHECK-DAG: <<Select:f\d+>> Select [<<Float42>>,<<GetField>>,<<GetTest>>] 247 ## CHECK-DAG: Return [<<Select>>] 248 249 ## CHECK-START: float Main2.test24() load_store_elimination (after) 250 ## CHECK-DAG: <<True:i\d+>> IntConstant 1 251 ## CHECK-DAG: <<Float8:f\d+>> FloatConstant 8 252 ## CHECK-DAG: <<Float42:f\d+>> FloatConstant 42 253 ## CHECK-DAG: <<Select:f\d+>> Select [<<Float42>>,<<Float8>>,<<True>>] 254 ## CHECK-DAG: Return [<<Select>>] 255 256 # Original java source: 257 # 258 # static float test24() { 259 # float a = 42.0f; 260 # TestClass3 obj = new TestClass3(); 261 # if (obj.test1) { 262 # a = obj.floatField; 263 # } 264 # return a; 265 # } 266 267 .method public static test24()F 268 .registers 3 269 270 .prologue 271 .line 612 272 const/high16 v0, 0x42280000 # 42.0f 273 274 .line 613 275 .local v0, "a":F 276 new-instance v1, LTestClass3; 277 278 invoke-direct {v1}, LTestClass3;-><init>()V 279 280 .line 614 281 .local v1, "obj":LTestClass3; 282 iget-boolean v2, v1, LTestClass3;->test1:Z 283 284 if-eqz v2, :cond_d 285 286 .line 615 287 iget v0, v1, LTestClass3;->floatField:F 288 289 .line 617 290 :cond_d 291 return v0 292 .end method 293