1# Copyright (C) 2017 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 LSmaliTests; 16.super Ljava/lang/Object; 17 18# static fields 19.field public static booleanField:Z 20 21.method static constructor <clinit>()V 22 .registers 1 23 24 .prologue 25 const/4 v0, 0x1 26 27 # booleanField = true 28 sput-boolean v0, LSmaliTests;->booleanField:Z 29 30 return-void 31.end method 32 33## CHECK-START: byte SmaliTests.booleanToByte(boolean) builder (after) 34## CHECK: <<Arg:z\d+>> ParameterValue 35## CHECK-DAG: <<Zero:i\d+>> IntConstant 0 36## CHECK-DAG: <<One:i\d+>> IntConstant 1 37## CHECK-DAG: <<Cond:z\d+>> Equal [<<Arg>>,<<Zero>>] 38## CHECK-DAG: If [<<Cond>>] 39## CHECK-DAG: <<Phi:i\d+>> Phi [<<One>>,<<Zero>>] 40## CHECK-DAG: <<IToS:b\d+>> TypeConversion [<<Phi>>] 41## CHECK-DAG: Return [<<IToS>>] 42 43## CHECK-START: byte SmaliTests.booleanToByte(boolean) select_generator (after) 44## CHECK: <<Arg:z\d+>> ParameterValue 45## CHECK-DAG: <<Zero:i\d+>> IntConstant 0 46## CHECK-DAG: <<One:i\d+>> IntConstant 1 47## CHECK-DAG: <<Sel:i\d+>> Select [<<Zero>>,<<One>>,<<Arg>>] 48## CHECK-DAG: <<IToS:b\d+>> TypeConversion [<<Sel>>] 49## CHECK-DAG: Return [<<IToS>>] 50 51## CHECK-START: byte SmaliTests.booleanToByte(boolean) instruction_simplifier$after_bce (after) 52## CHECK: <<Arg:z\d+>> ParameterValue 53## CHECK-DAG: Return [<<Arg>>] 54.method static booleanToByte(Z)B 55 .registers 2 56 if-eqz p0, :cond_5 57 const/4 v0, 0x1 58 59 :goto_3 60 int-to-byte v0, v0 61 return v0 62 63 :cond_5 64 const/4 v0, 0x0 65 goto :goto_3 66.end method 67 68## CHECK-START: short SmaliTests.booleanToShort(boolean) builder (after) 69## CHECK: <<Arg:z\d+>> ParameterValue 70## CHECK-DAG: <<Zero:i\d+>> IntConstant 0 71## CHECK-DAG: <<One:i\d+>> IntConstant 1 72## CHECK-DAG: <<Cond:z\d+>> Equal [<<Arg>>,<<Zero>>] 73## CHECK-DAG: If [<<Cond>>] 74## CHECK-DAG: <<Phi:i\d+>> Phi [<<One>>,<<Zero>>] 75## CHECK-DAG: <<IToS:s\d+>> TypeConversion [<<Phi>>] 76## CHECK-DAG: Return [<<IToS>>] 77 78## CHECK-START: short SmaliTests.booleanToShort(boolean) select_generator (after) 79## CHECK: <<Arg:z\d+>> ParameterValue 80## CHECK-DAG: <<Zero:i\d+>> IntConstant 0 81## CHECK-DAG: <<One:i\d+>> IntConstant 1 82## CHECK-DAG: <<Sel:i\d+>> Select [<<Zero>>,<<One>>,<<Arg>>] 83## CHECK-DAG: <<IToS:s\d+>> TypeConversion [<<Sel>>] 84## CHECK-DAG: Return [<<IToS>>] 85 86## CHECK-START: short SmaliTests.booleanToShort(boolean) instruction_simplifier$after_bce (after) 87## CHECK: <<Arg:z\d+>> ParameterValue 88## CHECK-DAG: Return [<<Arg>>] 89.method static booleanToShort(Z)S 90 .registers 2 91 if-eqz p0, :cond_5 92 const/4 v0, 0x1 93 94 :goto_3 95 int-to-short v0, v0 96 return v0 97 98 :cond_5 99 const/4 v0, 0x0 100 goto :goto_3 101.end method 102 103## CHECK-START: char SmaliTests.booleanToChar(boolean) builder (after) 104## CHECK: <<Arg:z\d+>> ParameterValue 105## CHECK-DAG: <<Zero:i\d+>> IntConstant 0 106## CHECK-DAG: <<One:i\d+>> IntConstant 1 107## CHECK-DAG: <<Cond:z\d+>> Equal [<<Arg>>,<<Zero>>] 108## CHECK-DAG: If [<<Cond>>] 109## CHECK-DAG: <<Phi:i\d+>> Phi [<<One>>,<<Zero>>] 110## CHECK-DAG: <<IToC:c\d+>> TypeConversion [<<Phi>>] 111## CHECK-DAG: Return [<<IToC>>] 112 113## CHECK-START: char SmaliTests.booleanToChar(boolean) select_generator (after) 114## CHECK: <<Arg:z\d+>> ParameterValue 115## CHECK-DAG: <<Zero:i\d+>> IntConstant 0 116## CHECK-DAG: <<One:i\d+>> IntConstant 1 117## CHECK-DAG: <<Sel:i\d+>> Select [<<Zero>>,<<One>>,<<Arg>>] 118## CHECK-DAG: <<IToC:c\d+>> TypeConversion [<<Sel>>] 119## CHECK-DAG: Return [<<IToC>>] 120 121## CHECK-START: char SmaliTests.booleanToChar(boolean) instruction_simplifier$after_bce (after) 122## CHECK: <<Arg:z\d+>> ParameterValue 123## CHECK-DAG: Return [<<Arg>>] 124.method static booleanToChar(Z)C 125 .registers 2 126 if-eqz p0, :cond_5 127 const/4 v0, 0x1 128 129 :goto_3 130 int-to-char v0, v0 131 return v0 132 133 :cond_5 134 const/4 v0, 0x0 135 goto :goto_3 136.end method 137 138## CHECK-START: int SmaliTests.booleanToInt(boolean) builder (after) 139## CHECK: <<Arg:z\d+>> ParameterValue 140## CHECK-DAG: <<Zero:i\d+>> IntConstant 0 141## CHECK-DAG: <<One:i\d+>> IntConstant 1 142## CHECK-DAG: <<Cond:z\d+>> Equal [<<Arg>>,<<Zero>>] 143## CHECK-DAG: If [<<Cond>>] 144## CHECK-DAG: <<Phi:i\d+>> Phi [<<One>>,<<Zero>>] 145## CHECK-DAG: Return [<<Phi>>] 146 147## CHECK-START: int SmaliTests.booleanToInt(boolean) select_generator (after) 148## CHECK: <<Arg:z\d+>> ParameterValue 149## CHECK-DAG: <<Zero:i\d+>> IntConstant 0 150## CHECK-DAG: <<One:i\d+>> IntConstant 1 151## CHECK-DAG: <<Sel:i\d+>> Select [<<Zero>>,<<One>>,<<Arg>>] 152## CHECK-DAG: Return [<<Sel>>] 153 154## CHECK-START: int SmaliTests.booleanToInt(boolean) instruction_simplifier$after_bce (after) 155## CHECK: <<Arg:z\d+>> ParameterValue 156## CHECK-DAG: Return [<<Arg>>] 157.method static booleanToInt(Z)I 158 .registers 2 159 if-eqz p0, :cond_4 160 const/4 v0, 0x1 161 162 :goto_3 163 return v0 164 165 :cond_4 166 const/4 v0, 0x0 167 goto :goto_3 168.end method 169 170## CHECK-START: long SmaliTests.booleanToLong(boolean) builder (after) 171## CHECK-DAG: <<Arg:z\d+>> ParameterValue 172## CHECK-DAG: <<Zero:i\d+>> IntConstant 0 173## CHECK-DAG: <<One:i\d+>> IntConstant 1 174## CHECK-DAG: <<Cond:z\d+>> Equal [<<Arg>>,<<Zero>>] 175## CHECK-DAG: If [<<Cond>>] 176## CHECK-DAG: <<Phi:i\d+>> Phi [<<One>>,<<Zero>>] 177## CHECK-DAG: <<IToJ:j\d+>> TypeConversion [<<Phi>>] 178## CHECK-DAG: Return [<<IToJ>>] 179 180## CHECK-START: long SmaliTests.booleanToLong(boolean) select_generator (after) 181## CHECK-DAG: <<Arg:z\d+>> ParameterValue 182## CHECK-DAG: <<Zero:i\d+>> IntConstant 0 183## CHECK-DAG: <<One:i\d+>> IntConstant 1 184## CHECK-DAG: <<Sel:i\d+>> Select [<<Zero>>,<<One>>,<<Arg>>] 185## CHECK-DAG: <<IToJ:j\d+>> TypeConversion [<<Sel>>] 186## CHECK-DAG: Return [<<IToJ>>] 187 188## CHECK-START: long SmaliTests.booleanToLong(boolean) instruction_simplifier$after_bce (after) 189## CHECK-DAG: <<Arg:z\d+>> ParameterValue 190## CHECK-DAG: <<ZToJ:j\d+>> TypeConversion [<<Arg>>] 191## CHECK-DAG: Return [<<ZToJ>>] 192.method public static booleanToLong(Z)J 193 .registers 3 194 .param p0, "b" # Z 195 .prologue 196 197 # return b ? 1 : 0; 198 if-eqz p0, :b_is_zero 199 200# :b_is_one 201 const/4 v0, 0x1 202 203 :l_return 204 int-to-long v0, v0 205 return-wide v0 206 207 :b_is_zero 208 const/4 v0, 0x0 209 goto :l_return 210.end method 211 212## CHECK-START: int SmaliTests.longToIntOfBoolean() builder (after) 213## CHECK-DAG: <<Sget:z\d+>> StaticFieldGet 214## CHECK-DAG: <<ZToJ:j\d+>> InvokeStaticOrDirect [<<Sget>>{{(,[ij]\d+)?}}] 215## CHECK-DAG: <<JToI:i\d+>> TypeConversion [<<ZToJ>>] 216## CHECK-DAG: Return [<<JToI>>] 217 218## CHECK-START: int SmaliTests.longToIntOfBoolean() inliner (after) 219## CHECK-DAG: <<Zero:i\d+>> IntConstant 0 220## CHECK-DAG: <<One:i\d+>> IntConstant 1 221## CHECK-DAG: <<Sget:z\d+>> StaticFieldGet 222## CHECK-DAG: If [<<Sget>>] 223## CHECK-DAG: <<Phi:i\d+>> Phi [<<One>>,<<Zero>>] 224## CHECK-DAG: <<IToJ:j\d+>> TypeConversion [<<Phi>>] 225## CHECK-DAG: <<JToI:i\d+>> TypeConversion [<<IToJ>>] 226## CHECK-DAG: Return [<<JToI>>] 227 228## CHECK-START: int SmaliTests.longToIntOfBoolean() select_generator (after) 229## CHECK-DAG: <<Zero:i\d+>> IntConstant 0 230## CHECK-DAG: <<One:i\d+>> IntConstant 1 231## CHECK-DAG: <<Sget:z\d+>> StaticFieldGet 232## CHECK-DAG: <<Sel:i\d+>> Select [<<Zero>>,<<One>>,<<Sget>>] 233## CHECK-DAG: Return [<<Sel>>] 234 235## CHECK-START: int SmaliTests.longToIntOfBoolean() instruction_simplifier$after_bce (after) 236## CHECK-DAG: <<Sget:z\d+>> StaticFieldGet 237## CHECK-DAG: Return [<<Sget>>] 238.method public static longToIntOfBoolean()I 239 .registers 3 240 .prologue 241 242 # long l = booleanToLong(booleanField); 243 sget-boolean v2, LSmaliTests;->booleanField:Z 244 invoke-static {v2}, LSmaliTests;->booleanToLong(Z)J 245 move-result-wide v0 246 247 # return (int) l; 248 long-to-int v2, v0 249 return v2 250.end method 251