David Brazdil | ee690a3 | 2014-12-01 17:04:16 +0000 | [diff] [blame] | 1 | /* |
Roland Levillain | 6a92a03 | 2015-07-23 12:15:01 +0100 | [diff] [blame] | 2 | * Copyright (C) 2014 The Android Open Source Project |
| 3 | * |
| 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | * you may not use this file except in compliance with the License. |
| 6 | * You may obtain a copy of the License at |
| 7 | * |
| 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | * |
| 10 | * Unless required by applicable law or agreed to in writing, software |
| 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | * See the License for the specific language governing permissions and |
| 14 | * limitations under the License. |
| 15 | */ |
David Brazdil | ee690a3 | 2014-12-01 17:04:16 +0000 | [diff] [blame] | 16 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame^] | 17 | import java.lang.reflect.Method; |
| 18 | |
David Brazdil | 4846d13 | 2015-01-15 19:07:08 +0000 | [diff] [blame] | 19 | public class Main { |
David Brazdil | ee690a3 | 2014-12-01 17:04:16 +0000 | [diff] [blame] | 20 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame^] | 21 | // Workaround for b/18051191. |
| 22 | class InnerClass {} |
| 23 | |
Roland Levillain | 3b55ebb | 2015-05-08 13:13:19 +0100 | [diff] [blame] | 24 | public static void assertFalse(boolean condition) { |
| 25 | if (condition) { |
| 26 | throw new Error(); |
| 27 | } |
| 28 | } |
| 29 | |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 30 | public static void assertIntEquals(int expected, int result) { |
| 31 | if (expected != result) { |
| 32 | throw new Error("Expected: " + expected + ", found: " + result); |
| 33 | } |
| 34 | } |
| 35 | |
| 36 | public static void assertLongEquals(long expected, long result) { |
| 37 | if (expected != result) { |
| 38 | throw new Error("Expected: " + expected + ", found: " + result); |
| 39 | } |
| 40 | } |
| 41 | |
Mark Mendell | e82549b | 2015-05-06 10:55:34 -0400 | [diff] [blame] | 42 | public static void assertFloatEquals(float expected, float result) { |
| 43 | if (expected != result) { |
| 44 | throw new Error("Expected: " + expected + ", found: " + result); |
| 45 | } |
| 46 | } |
| 47 | |
| 48 | public static void assertDoubleEquals(double expected, double result) { |
| 49 | if (expected != result) { |
| 50 | throw new Error("Expected: " + expected + ", found: " + result); |
| 51 | } |
| 52 | } |
| 53 | |
Roland Levillain | b65eb50 | 2015-07-23 12:11:42 +0100 | [diff] [blame] | 54 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame^] | 55 | // Wrappers around methods located in file TestCmp.smali. |
| 56 | |
| 57 | public int smaliCmpLongConstants() throws Exception { |
| 58 | Method m = testCmp.getMethod("$opt$CmpLongConstants"); |
| 59 | return (Integer)m.invoke(null); |
| 60 | } |
| 61 | public int smaliCmpGtFloatConstants() throws Exception { |
| 62 | Method m = testCmp.getMethod("$opt$CmpGtFloatConstants"); |
| 63 | return (Integer)m.invoke(null); |
| 64 | } |
| 65 | public int smaliCmpLtFloatConstants() throws Exception { |
| 66 | Method m = testCmp.getMethod("$opt$CmpLtFloatConstants"); |
| 67 | return (Integer)m.invoke(null); |
| 68 | } |
| 69 | public int smaliCmpGtDoubleConstants() throws Exception { |
| 70 | Method m = testCmp.getMethod("$opt$CmpGtDoubleConstants"); |
| 71 | return (Integer)m.invoke(null); |
| 72 | } |
| 73 | public int smaliCmpLtDoubleConstants() throws Exception { |
| 74 | Method m = testCmp.getMethod("$opt$CmpLtDoubleConstants"); |
| 75 | return (Integer)m.invoke(null); |
| 76 | } |
| 77 | |
| 78 | public int smaliCmpLongSameConstant() throws Exception { |
| 79 | Method m = testCmp.getMethod("$opt$CmpLongSameConstant"); |
| 80 | return (Integer)m.invoke(null); |
| 81 | } |
| 82 | public int smaliCmpGtFloatSameConstant() throws Exception { |
| 83 | Method m = testCmp.getMethod("$opt$CmpGtFloatSameConstant"); |
| 84 | return (Integer)m.invoke(null); |
| 85 | } |
| 86 | public int smaliCmpLtFloatSameConstant() throws Exception { |
| 87 | Method m = testCmp.getMethod("$opt$CmpLtFloatSameConstant"); |
| 88 | return (Integer)m.invoke(null); |
| 89 | } |
| 90 | public int smaliCmpGtDoubleSameConstant() throws Exception { |
| 91 | Method m = testCmp.getMethod("$opt$CmpGtDoubleSameConstant"); |
| 92 | return (Integer)m.invoke(null); |
| 93 | } |
| 94 | public int smaliCmpLtDoubleSameConstant() throws Exception { |
| 95 | Method m = testCmp.getMethod("$opt$CmpLtDoubleSameConstant"); |
| 96 | return (Integer)m.invoke(null); |
| 97 | } |
| 98 | |
| 99 | public int smaliCmpGtFloatConstantWithNaN() throws Exception { |
| 100 | Method m = testCmp.getMethod("$opt$CmpGtFloatConstantWithNaN"); |
| 101 | return (Integer)m.invoke(null); |
| 102 | } |
| 103 | public int smaliCmpLtFloatConstantWithNaN() throws Exception { |
| 104 | Method m = testCmp.getMethod("$opt$CmpLtFloatConstantWithNaN"); |
| 105 | return (Integer)m.invoke(null); |
| 106 | } |
| 107 | public int smaliCmpGtDoubleConstantWithNaN() throws Exception { |
| 108 | Method m = testCmp.getMethod("$opt$CmpGtDoubleConstantWithNaN"); |
| 109 | return (Integer)m.invoke(null); |
| 110 | } |
| 111 | public int smaliCmpLtDoubleConstantWithNaN() throws Exception { |
| 112 | Method m = testCmp.getMethod("$opt$CmpLtDoubleConstantWithNaN"); |
| 113 | return (Integer)m.invoke(null); |
| 114 | } |
| 115 | |
| 116 | |
David Brazdil | ee690a3 | 2014-12-01 17:04:16 +0000 | [diff] [blame] | 117 | /** |
Roland Levillain | b65eb50 | 2015-07-23 12:11:42 +0100 | [diff] [blame] | 118 | * Exercise constant folding on negation. |
David Brazdil | ee690a3 | 2014-12-01 17:04:16 +0000 | [diff] [blame] | 119 | */ |
| 120 | |
David Brazdil | a06d66a | 2015-05-28 11:14:54 +0100 | [diff] [blame] | 121 | /// CHECK-START: int Main.IntNegation() constant_folding (before) |
| 122 | /// CHECK-DAG: <<Const42:i\d+>> IntConstant 42 |
| 123 | /// CHECK-DAG: <<Neg:i\d+>> Neg [<<Const42>>] |
| 124 | /// CHECK-DAG: Return [<<Neg>>] |
David Brazdil | ee690a3 | 2014-12-01 17:04:16 +0000 | [diff] [blame] | 125 | |
David Brazdil | a06d66a | 2015-05-28 11:14:54 +0100 | [diff] [blame] | 126 | /// CHECK-START: int Main.IntNegation() constant_folding (after) |
| 127 | /// CHECK-DAG: <<ConstN42:i\d+>> IntConstant -42 |
| 128 | /// CHECK-DAG: Return [<<ConstN42>>] |
David Brazdil | ee690a3 | 2014-12-01 17:04:16 +0000 | [diff] [blame] | 129 | |
Roland Levillain | b65eb50 | 2015-07-23 12:11:42 +0100 | [diff] [blame] | 130 | /// CHECK-START: int Main.IntNegation() constant_folding (after) |
| 131 | /// CHECK-NOT: Neg |
| 132 | |
David Brazdil | ee690a3 | 2014-12-01 17:04:16 +0000 | [diff] [blame] | 133 | public static int IntNegation() { |
| 134 | int x, y; |
| 135 | x = 42; |
| 136 | y = -x; |
| 137 | return y; |
| 138 | } |
| 139 | |
Roland Levillain | c90bc7c | 2014-12-11 12:14:33 +0000 | [diff] [blame] | 140 | /// CHECK-START: long Main.LongNegation() constant_folding (before) |
| 141 | /// CHECK-DAG: <<Const42:j\d+>> LongConstant 42 |
| 142 | /// CHECK-DAG: <<Neg:j\d+>> Neg [<<Const42>>] |
| 143 | /// CHECK-DAG: Return [<<Neg>>] |
| 144 | |
| 145 | /// CHECK-START: long Main.LongNegation() constant_folding (after) |
| 146 | /// CHECK-DAG: <<ConstN42:j\d+>> LongConstant -42 |
| 147 | /// CHECK-DAG: Return [<<ConstN42>>] |
| 148 | |
| 149 | /// CHECK-START: long Main.LongNegation() constant_folding (after) |
| 150 | /// CHECK-NOT: Neg |
| 151 | |
| 152 | public static long LongNegation() { |
| 153 | long x, y; |
| 154 | x = 42L; |
| 155 | y = -x; |
| 156 | return y; |
| 157 | } |
| 158 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame^] | 159 | /// CHECK-START: float Main.FloatNegation() constant_folding (before) |
| 160 | /// CHECK-DAG: <<Const42:f\d+>> FloatConstant 42 |
| 161 | /// CHECK-DAG: <<Neg:f\d+>> Neg [<<Const42>>] |
| 162 | /// CHECK-DAG: Return [<<Neg>>] |
| 163 | |
| 164 | /// CHECK-START: float Main.FloatNegation() constant_folding (after) |
| 165 | /// CHECK-DAG: <<ConstN42:f\d+>> FloatConstant -42 |
| 166 | /// CHECK-DAG: Return [<<ConstN42>>] |
| 167 | |
| 168 | /// CHECK-START: float Main.FloatNegation() constant_folding (after) |
| 169 | /// CHECK-NOT: Neg |
| 170 | |
| 171 | public static float FloatNegation() { |
| 172 | float x, y; |
| 173 | x = 42F; |
| 174 | y = -x; |
| 175 | return y; |
| 176 | } |
| 177 | |
| 178 | /// CHECK-START: double Main.DoubleNegation() constant_folding (before) |
| 179 | /// CHECK-DAG: <<Const42:d\d+>> DoubleConstant 42 |
| 180 | /// CHECK-DAG: <<Neg:d\d+>> Neg [<<Const42>>] |
| 181 | /// CHECK-DAG: Return [<<Neg>>] |
| 182 | |
| 183 | /// CHECK-START: double Main.DoubleNegation() constant_folding (after) |
| 184 | /// CHECK-DAG: <<ConstN42:d\d+>> DoubleConstant -42 |
| 185 | /// CHECK-DAG: Return [<<ConstN42>>] |
| 186 | |
| 187 | /// CHECK-START: double Main.DoubleNegation() constant_folding (after) |
| 188 | /// CHECK-NOT: Neg |
| 189 | |
| 190 | public static double DoubleNegation() { |
| 191 | double x, y; |
| 192 | x = 42D; |
| 193 | y = -x; |
| 194 | return y; |
| 195 | } |
| 196 | |
Roland Levillain | b65eb50 | 2015-07-23 12:11:42 +0100 | [diff] [blame] | 197 | |
David Brazdil | ee690a3 | 2014-12-01 17:04:16 +0000 | [diff] [blame] | 198 | /** |
Roland Levillain | b65eb50 | 2015-07-23 12:11:42 +0100 | [diff] [blame] | 199 | * Exercise constant folding on addition. |
David Brazdil | ee690a3 | 2014-12-01 17:04:16 +0000 | [diff] [blame] | 200 | */ |
| 201 | |
David Brazdil | a06d66a | 2015-05-28 11:14:54 +0100 | [diff] [blame] | 202 | /// CHECK-START: int Main.IntAddition1() constant_folding (before) |
| 203 | /// CHECK-DAG: <<Const1:i\d+>> IntConstant 1 |
| 204 | /// CHECK-DAG: <<Const2:i\d+>> IntConstant 2 |
| 205 | /// CHECK-DAG: <<Add:i\d+>> Add [<<Const1>>,<<Const2>>] |
| 206 | /// CHECK-DAG: Return [<<Add>>] |
David Brazdil | ee690a3 | 2014-12-01 17:04:16 +0000 | [diff] [blame] | 207 | |
David Brazdil | a06d66a | 2015-05-28 11:14:54 +0100 | [diff] [blame] | 208 | /// CHECK-START: int Main.IntAddition1() constant_folding (after) |
| 209 | /// CHECK-DAG: <<Const3:i\d+>> IntConstant 3 |
| 210 | /// CHECK-DAG: Return [<<Const3>>] |
David Brazdil | ee690a3 | 2014-12-01 17:04:16 +0000 | [diff] [blame] | 211 | |
Roland Levillain | b65eb50 | 2015-07-23 12:11:42 +0100 | [diff] [blame] | 212 | /// CHECK-START: int Main.IntAddition1() constant_folding (after) |
| 213 | /// CHECK-NOT: Add |
| 214 | |
David Brazdil | ee690a3 | 2014-12-01 17:04:16 +0000 | [diff] [blame] | 215 | public static int IntAddition1() { |
| 216 | int a, b, c; |
| 217 | a = 1; |
| 218 | b = 2; |
| 219 | c = a + b; |
| 220 | return c; |
| 221 | } |
| 222 | |
David Brazdil | a06d66a | 2015-05-28 11:14:54 +0100 | [diff] [blame] | 223 | /// CHECK-START: int Main.IntAddition2() constant_folding (before) |
| 224 | /// CHECK-DAG: <<Const1:i\d+>> IntConstant 1 |
| 225 | /// CHECK-DAG: <<Const2:i\d+>> IntConstant 2 |
| 226 | /// CHECK-DAG: <<Const5:i\d+>> IntConstant 5 |
| 227 | /// CHECK-DAG: <<Const6:i\d+>> IntConstant 6 |
David Brazdil | 57e863c | 2016-01-11 10:27:13 +0000 | [diff] [blame] | 228 | /// CHECK-DAG: <<Const11:i\d+>> IntConstant 11 |
David Brazdil | a06d66a | 2015-05-28 11:14:54 +0100 | [diff] [blame] | 229 | /// CHECK-DAG: <<Add1:i\d+>> Add [<<Const1>>,<<Const2>>] |
David Brazdil | 57e863c | 2016-01-11 10:27:13 +0000 | [diff] [blame] | 230 | /// CHECK-DAG: Add [<<Const5>>,<<Const6>>] |
| 231 | /// CHECK-DAG: <<Add3:i\d+>> Add [<<Add1>>,<<Const11>>] |
David Brazdil | a06d66a | 2015-05-28 11:14:54 +0100 | [diff] [blame] | 232 | /// CHECK-DAG: Return [<<Add3>>] |
David Brazdil | ee690a3 | 2014-12-01 17:04:16 +0000 | [diff] [blame] | 233 | |
David Brazdil | a06d66a | 2015-05-28 11:14:54 +0100 | [diff] [blame] | 234 | /// CHECK-START: int Main.IntAddition2() constant_folding (after) |
| 235 | /// CHECK-DAG: <<Const14:i\d+>> IntConstant 14 |
| 236 | /// CHECK-DAG: Return [<<Const14>>] |
David Brazdil | ee690a3 | 2014-12-01 17:04:16 +0000 | [diff] [blame] | 237 | |
Roland Levillain | b65eb50 | 2015-07-23 12:11:42 +0100 | [diff] [blame] | 238 | /// CHECK-START: int Main.IntAddition2() constant_folding (after) |
| 239 | /// CHECK-NOT: Add |
| 240 | |
David Brazdil | ee690a3 | 2014-12-01 17:04:16 +0000 | [diff] [blame] | 241 | public static int IntAddition2() { |
| 242 | int a, b, c; |
| 243 | a = 1; |
| 244 | b = 2; |
| 245 | a += b; |
| 246 | b = 5; |
| 247 | c = 6; |
| 248 | b += c; |
| 249 | c = a + b; |
| 250 | return c; |
| 251 | } |
| 252 | |
Roland Levillain | b65eb50 | 2015-07-23 12:11:42 +0100 | [diff] [blame] | 253 | /// CHECK-START: long Main.LongAddition() constant_folding (before) |
| 254 | /// CHECK-DAG: <<Const1:j\d+>> LongConstant 1 |
| 255 | /// CHECK-DAG: <<Const2:j\d+>> LongConstant 2 |
| 256 | /// CHECK-DAG: <<Add:j\d+>> Add [<<Const1>>,<<Const2>>] |
| 257 | /// CHECK-DAG: Return [<<Add>>] |
| 258 | |
| 259 | /// CHECK-START: long Main.LongAddition() constant_folding (after) |
| 260 | /// CHECK-DAG: <<Const3:j\d+>> LongConstant 3 |
| 261 | /// CHECK-DAG: Return [<<Const3>>] |
| 262 | |
| 263 | /// CHECK-START: long Main.LongAddition() constant_folding (after) |
| 264 | /// CHECK-NOT: Add |
| 265 | |
| 266 | public static long LongAddition() { |
| 267 | long a, b, c; |
| 268 | a = 1L; |
| 269 | b = 2L; |
| 270 | c = a + b; |
| 271 | return c; |
| 272 | } |
| 273 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame^] | 274 | /// CHECK-START: float Main.FloatAddition() constant_folding (before) |
| 275 | /// CHECK-DAG: <<Const1:f\d+>> FloatConstant 1 |
| 276 | /// CHECK-DAG: <<Const2:f\d+>> FloatConstant 2 |
| 277 | /// CHECK-DAG: <<Add:f\d+>> Add [<<Const1>>,<<Const2>>] |
| 278 | /// CHECK-DAG: Return [<<Add>>] |
| 279 | |
| 280 | /// CHECK-START: float Main.FloatAddition() constant_folding (after) |
| 281 | /// CHECK-DAG: <<Const3:f\d+>> FloatConstant 3 |
| 282 | /// CHECK-DAG: Return [<<Const3>>] |
| 283 | |
| 284 | /// CHECK-START: float Main.FloatAddition() constant_folding (after) |
| 285 | /// CHECK-NOT: Add |
| 286 | |
| 287 | public static float FloatAddition() { |
| 288 | float a, b, c; |
| 289 | a = 1F; |
| 290 | b = 2F; |
| 291 | c = a + b; |
| 292 | return c; |
| 293 | } |
| 294 | |
| 295 | /// CHECK-START: double Main.DoubleAddition() constant_folding (before) |
| 296 | /// CHECK-DAG: <<Const1:d\d+>> DoubleConstant 1 |
| 297 | /// CHECK-DAG: <<Const2:d\d+>> DoubleConstant 2 |
| 298 | /// CHECK-DAG: <<Add:d\d+>> Add [<<Const1>>,<<Const2>>] |
| 299 | /// CHECK-DAG: Return [<<Add>>] |
| 300 | |
| 301 | /// CHECK-START: double Main.DoubleAddition() constant_folding (after) |
| 302 | /// CHECK-DAG: <<Const3:d\d+>> DoubleConstant 3 |
| 303 | /// CHECK-DAG: Return [<<Const3>>] |
| 304 | |
| 305 | /// CHECK-START: double Main.DoubleAddition() constant_folding (after) |
| 306 | /// CHECK-NOT: Add |
| 307 | |
| 308 | public static double DoubleAddition() { |
| 309 | double a, b, c; |
| 310 | a = 1D; |
| 311 | b = 2D; |
| 312 | c = a + b; |
| 313 | return c; |
| 314 | } |
| 315 | |
Roland Levillain | b65eb50 | 2015-07-23 12:11:42 +0100 | [diff] [blame] | 316 | |
David Brazdil | ee690a3 | 2014-12-01 17:04:16 +0000 | [diff] [blame] | 317 | /** |
Roland Levillain | b65eb50 | 2015-07-23 12:11:42 +0100 | [diff] [blame] | 318 | * Exercise constant folding on subtraction. |
David Brazdil | ee690a3 | 2014-12-01 17:04:16 +0000 | [diff] [blame] | 319 | */ |
| 320 | |
David Brazdil | a06d66a | 2015-05-28 11:14:54 +0100 | [diff] [blame] | 321 | /// CHECK-START: int Main.IntSubtraction() constant_folding (before) |
| 322 | /// CHECK-DAG: <<Const6:i\d+>> IntConstant 6 |
| 323 | /// CHECK-DAG: <<Const2:i\d+>> IntConstant 2 |
| 324 | /// CHECK-DAG: <<Sub:i\d+>> Sub [<<Const6>>,<<Const2>>] |
| 325 | /// CHECK-DAG: Return [<<Sub>>] |
David Brazdil | ee690a3 | 2014-12-01 17:04:16 +0000 | [diff] [blame] | 326 | |
David Brazdil | a06d66a | 2015-05-28 11:14:54 +0100 | [diff] [blame] | 327 | /// CHECK-START: int Main.IntSubtraction() constant_folding (after) |
| 328 | /// CHECK-DAG: <<Const4:i\d+>> IntConstant 4 |
| 329 | /// CHECK-DAG: Return [<<Const4>>] |
David Brazdil | ee690a3 | 2014-12-01 17:04:16 +0000 | [diff] [blame] | 330 | |
Roland Levillain | b65eb50 | 2015-07-23 12:11:42 +0100 | [diff] [blame] | 331 | /// CHECK-START: int Main.IntSubtraction() constant_folding (after) |
| 332 | /// CHECK-NOT: Sub |
| 333 | |
David Brazdil | ee690a3 | 2014-12-01 17:04:16 +0000 | [diff] [blame] | 334 | public static int IntSubtraction() { |
| 335 | int a, b, c; |
David Brazdil | 4846d13 | 2015-01-15 19:07:08 +0000 | [diff] [blame] | 336 | a = 6; |
David Brazdil | ee690a3 | 2014-12-01 17:04:16 +0000 | [diff] [blame] | 337 | b = 2; |
| 338 | c = a - b; |
| 339 | return c; |
| 340 | } |
| 341 | |
David Brazdil | a06d66a | 2015-05-28 11:14:54 +0100 | [diff] [blame] | 342 | /// CHECK-START: long Main.LongSubtraction() constant_folding (before) |
| 343 | /// CHECK-DAG: <<Const6:j\d+>> LongConstant 6 |
| 344 | /// CHECK-DAG: <<Const2:j\d+>> LongConstant 2 |
| 345 | /// CHECK-DAG: <<Sub:j\d+>> Sub [<<Const6>>,<<Const2>>] |
| 346 | /// CHECK-DAG: Return [<<Sub>>] |
David Brazdil | ee690a3 | 2014-12-01 17:04:16 +0000 | [diff] [blame] | 347 | |
David Brazdil | a06d66a | 2015-05-28 11:14:54 +0100 | [diff] [blame] | 348 | /// CHECK-START: long Main.LongSubtraction() constant_folding (after) |
| 349 | /// CHECK-DAG: <<Const4:j\d+>> LongConstant 4 |
| 350 | /// CHECK-DAG: Return [<<Const4>>] |
David Brazdil | ee690a3 | 2014-12-01 17:04:16 +0000 | [diff] [blame] | 351 | |
Roland Levillain | b65eb50 | 2015-07-23 12:11:42 +0100 | [diff] [blame] | 352 | /// CHECK-START: long Main.LongSubtraction() constant_folding (after) |
| 353 | /// CHECK-NOT: Sub |
| 354 | |
David Brazdil | ee690a3 | 2014-12-01 17:04:16 +0000 | [diff] [blame] | 355 | public static long LongSubtraction() { |
| 356 | long a, b, c; |
David Brazdil | 4846d13 | 2015-01-15 19:07:08 +0000 | [diff] [blame] | 357 | a = 6L; |
David Brazdil | ee690a3 | 2014-12-01 17:04:16 +0000 | [diff] [blame] | 358 | b = 2L; |
| 359 | c = a - b; |
| 360 | return c; |
| 361 | } |
| 362 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame^] | 363 | /// CHECK-START: float Main.FloatSubtraction() constant_folding (before) |
| 364 | /// CHECK-DAG: <<Const6:f\d+>> FloatConstant 6 |
| 365 | /// CHECK-DAG: <<Const2:f\d+>> FloatConstant 2 |
| 366 | /// CHECK-DAG: <<Sub:f\d+>> Sub [<<Const6>>,<<Const2>>] |
| 367 | /// CHECK-DAG: Return [<<Sub>>] |
| 368 | |
| 369 | /// CHECK-START: float Main.FloatSubtraction() constant_folding (after) |
| 370 | /// CHECK-DAG: <<Const4:f\d+>> FloatConstant 4 |
| 371 | /// CHECK-DAG: Return [<<Const4>>] |
| 372 | |
| 373 | /// CHECK-START: float Main.FloatSubtraction() constant_folding (after) |
| 374 | /// CHECK-NOT: Sub |
| 375 | |
| 376 | public static float FloatSubtraction() { |
| 377 | float a, b, c; |
| 378 | a = 6F; |
| 379 | b = 2F; |
| 380 | c = a - b; |
| 381 | return c; |
| 382 | } |
| 383 | |
| 384 | /// CHECK-START: double Main.DoubleSubtraction() constant_folding (before) |
| 385 | /// CHECK-DAG: <<Const6:d\d+>> DoubleConstant 6 |
| 386 | /// CHECK-DAG: <<Const2:d\d+>> DoubleConstant 2 |
| 387 | /// CHECK-DAG: <<Sub:d\d+>> Sub [<<Const6>>,<<Const2>>] |
| 388 | /// CHECK-DAG: Return [<<Sub>>] |
| 389 | |
| 390 | /// CHECK-START: double Main.DoubleSubtraction() constant_folding (after) |
| 391 | /// CHECK-DAG: <<Const4:d\d+>> DoubleConstant 4 |
| 392 | /// CHECK-DAG: Return [<<Const4>>] |
| 393 | |
| 394 | /// CHECK-START: double Main.DoubleSubtraction() constant_folding (after) |
| 395 | /// CHECK-NOT: Sub |
| 396 | |
| 397 | public static double DoubleSubtraction() { |
| 398 | double a, b, c; |
| 399 | a = 6D; |
| 400 | b = 2D; |
| 401 | c = a - b; |
| 402 | return c; |
| 403 | } |
| 404 | |
Roland Levillain | b65eb50 | 2015-07-23 12:11:42 +0100 | [diff] [blame] | 405 | |
David Brazdil | ee690a3 | 2014-12-01 17:04:16 +0000 | [diff] [blame] | 406 | /** |
Roland Levillain | f7746ad | 2015-07-22 14:12:01 +0100 | [diff] [blame] | 407 | * Exercise constant folding on multiplication. |
| 408 | */ |
| 409 | |
| 410 | /// CHECK-START: int Main.IntMultiplication() constant_folding (before) |
| 411 | /// CHECK-DAG: <<Const7:i\d+>> IntConstant 7 |
| 412 | /// CHECK-DAG: <<Const3:i\d+>> IntConstant 3 |
| 413 | /// CHECK-DAG: <<Mul:i\d+>> Mul [<<Const7>>,<<Const3>>] |
| 414 | /// CHECK-DAG: Return [<<Mul>>] |
| 415 | |
| 416 | /// CHECK-START: int Main.IntMultiplication() constant_folding (after) |
| 417 | /// CHECK-DAG: <<Const21:i\d+>> IntConstant 21 |
| 418 | /// CHECK-DAG: Return [<<Const21>>] |
| 419 | |
| 420 | /// CHECK-START: int Main.IntMultiplication() constant_folding (after) |
| 421 | /// CHECK-NOT: Mul |
| 422 | |
| 423 | public static int IntMultiplication() { |
| 424 | int a, b, c; |
| 425 | a = 7; |
| 426 | b = 3; |
| 427 | c = a * b; |
| 428 | return c; |
| 429 | } |
| 430 | |
| 431 | /// CHECK-START: long Main.LongMultiplication() constant_folding (before) |
| 432 | /// CHECK-DAG: <<Const7:j\d+>> LongConstant 7 |
| 433 | /// CHECK-DAG: <<Const3:j\d+>> LongConstant 3 |
| 434 | /// CHECK-DAG: <<Mul:j\d+>> Mul [<<Const7>>,<<Const3>>] |
| 435 | /// CHECK-DAG: Return [<<Mul>>] |
| 436 | |
| 437 | /// CHECK-START: long Main.LongMultiplication() constant_folding (after) |
| 438 | /// CHECK-DAG: <<Const21:j\d+>> LongConstant 21 |
| 439 | /// CHECK-DAG: Return [<<Const21>>] |
| 440 | |
| 441 | /// CHECK-START: long Main.LongMultiplication() constant_folding (after) |
| 442 | /// CHECK-NOT: Mul |
| 443 | |
| 444 | public static long LongMultiplication() { |
| 445 | long a, b, c; |
| 446 | a = 7L; |
| 447 | b = 3L; |
| 448 | c = a * b; |
| 449 | return c; |
| 450 | } |
| 451 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame^] | 452 | /// CHECK-START: float Main.FloatMultiplication() constant_folding (before) |
| 453 | /// CHECK-DAG: <<Const7:f\d+>> FloatConstant 7 |
| 454 | /// CHECK-DAG: <<Const3:f\d+>> FloatConstant 3 |
| 455 | /// CHECK-DAG: <<Mul:f\d+>> Mul [<<Const7>>,<<Const3>>] |
| 456 | /// CHECK-DAG: Return [<<Mul>>] |
| 457 | |
| 458 | /// CHECK-START: float Main.FloatMultiplication() constant_folding (after) |
| 459 | /// CHECK-DAG: <<Const21:f\d+>> FloatConstant 21 |
| 460 | /// CHECK-DAG: Return [<<Const21>>] |
| 461 | |
| 462 | /// CHECK-START: float Main.FloatMultiplication() constant_folding (after) |
| 463 | /// CHECK-NOT: Mul |
| 464 | |
| 465 | public static float FloatMultiplication() { |
| 466 | float a, b, c; |
| 467 | a = 7F; |
| 468 | b = 3F; |
| 469 | c = a * b; |
| 470 | return c; |
| 471 | } |
| 472 | |
| 473 | /// CHECK-START: double Main.DoubleMultiplication() constant_folding (before) |
| 474 | /// CHECK-DAG: <<Const7:d\d+>> DoubleConstant 7 |
| 475 | /// CHECK-DAG: <<Const3:d\d+>> DoubleConstant 3 |
| 476 | /// CHECK-DAG: <<Mul:d\d+>> Mul [<<Const7>>,<<Const3>>] |
| 477 | /// CHECK-DAG: Return [<<Mul>>] |
| 478 | |
| 479 | /// CHECK-START: double Main.DoubleMultiplication() constant_folding (after) |
| 480 | /// CHECK-DAG: <<Const21:d\d+>> DoubleConstant 21 |
| 481 | /// CHECK-DAG: Return [<<Const21>>] |
| 482 | |
| 483 | /// CHECK-START: double Main.DoubleMultiplication() constant_folding (after) |
| 484 | /// CHECK-NOT: Mul |
| 485 | |
| 486 | public static double DoubleMultiplication() { |
| 487 | double a, b, c; |
| 488 | a = 7D; |
| 489 | b = 3D; |
| 490 | c = a * b; |
| 491 | return c; |
| 492 | } |
| 493 | |
Roland Levillain | f7746ad | 2015-07-22 14:12:01 +0100 | [diff] [blame] | 494 | |
| 495 | /** |
| 496 | * Exercise constant folding on division. |
| 497 | */ |
| 498 | |
| 499 | /// CHECK-START: int Main.IntDivision() constant_folding (before) |
| 500 | /// CHECK-DAG: <<Const8:i\d+>> IntConstant 8 |
| 501 | /// CHECK-DAG: <<Const3:i\d+>> IntConstant 3 |
| 502 | /// CHECK-DAG: <<Div0Chk:i\d+>> DivZeroCheck [<<Const3>>] |
| 503 | /// CHECK-DAG: <<Div:i\d+>> Div [<<Const8>>,<<Div0Chk>>] |
| 504 | /// CHECK-DAG: Return [<<Div>>] |
| 505 | |
| 506 | /// CHECK-START: int Main.IntDivision() constant_folding (after) |
| 507 | /// CHECK-DAG: <<Const2:i\d+>> IntConstant 2 |
| 508 | /// CHECK-DAG: Return [<<Const2>>] |
| 509 | |
| 510 | /// CHECK-START: int Main.IntDivision() constant_folding (after) |
| 511 | /// CHECK-NOT: DivZeroCheck |
| 512 | /// CHECK-NOT: Div |
| 513 | |
| 514 | public static int IntDivision() { |
| 515 | int a, b, c; |
| 516 | a = 8; |
| 517 | b = 3; |
| 518 | c = a / b; |
| 519 | return c; |
| 520 | } |
| 521 | |
| 522 | /// CHECK-START: long Main.LongDivision() constant_folding (before) |
| 523 | /// CHECK-DAG: <<Const8:j\d+>> LongConstant 8 |
| 524 | /// CHECK-DAG: <<Const3:j\d+>> LongConstant 3 |
| 525 | /// CHECK-DAG: <<Div0Chk:j\d+>> DivZeroCheck [<<Const3>>] |
| 526 | /// CHECK-DAG: <<Div:j\d+>> Div [<<Const8>>,<<Div0Chk>>] |
| 527 | /// CHECK-DAG: Return [<<Div>>] |
| 528 | |
| 529 | /// CHECK-START: long Main.LongDivision() constant_folding (after) |
| 530 | /// CHECK-DAG: <<Const2:j\d+>> LongConstant 2 |
| 531 | /// CHECK-DAG: Return [<<Const2>>] |
| 532 | |
| 533 | /// CHECK-START: long Main.LongDivision() constant_folding (after) |
| 534 | /// CHECK-NOT: DivZeroCheck |
| 535 | /// CHECK-NOT: Div |
| 536 | |
| 537 | public static long LongDivision() { |
| 538 | long a, b, c; |
| 539 | a = 8L; |
| 540 | b = 3L; |
| 541 | c = a / b; |
| 542 | return c; |
| 543 | } |
| 544 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame^] | 545 | /// CHECK-START: float Main.FloatDivision() constant_folding (before) |
| 546 | /// CHECK-DAG: <<Const8:f\d+>> FloatConstant 8 |
| 547 | /// CHECK-DAG: <<Const2P5:f\d+>> FloatConstant 2.5 |
| 548 | /// CHECK-DAG: <<Div:f\d+>> Div [<<Const8>>,<<Const2P5>>] |
| 549 | /// CHECK-DAG: Return [<<Div>>] |
| 550 | |
| 551 | /// CHECK-START: float Main.FloatDivision() constant_folding (after) |
| 552 | /// CHECK-DAG: <<Const3P2:f\d+>> FloatConstant 3.2 |
| 553 | /// CHECK-DAG: Return [<<Const3P2>>] |
| 554 | |
| 555 | /// CHECK-START: float Main.FloatDivision() constant_folding (after) |
| 556 | /// CHECK-NOT: Div |
| 557 | |
| 558 | public static float FloatDivision() { |
| 559 | float a, b, c; |
| 560 | a = 8F; |
| 561 | b = 2.5F; |
| 562 | c = a / b; |
| 563 | return c; |
| 564 | } |
| 565 | |
| 566 | /// CHECK-START: double Main.DoubleDivision() constant_folding (before) |
| 567 | /// CHECK-DAG: <<Const8:d\d+>> DoubleConstant 8 |
| 568 | /// CHECK-DAG: <<Const2P5:d\d+>> DoubleConstant 2.5 |
| 569 | /// CHECK-DAG: <<Div:d\d+>> Div [<<Const8>>,<<Const2P5>>] |
| 570 | /// CHECK-DAG: Return [<<Div>>] |
| 571 | |
| 572 | /// CHECK-START: double Main.DoubleDivision() constant_folding (after) |
| 573 | /// CHECK-DAG: <<Const3P2:d\d+>> DoubleConstant 3.2 |
| 574 | /// CHECK-DAG: Return [<<Const3P2>>] |
| 575 | |
| 576 | /// CHECK-START: double Main.DoubleDivision() constant_folding (after) |
| 577 | /// CHECK-NOT: Div |
| 578 | |
| 579 | public static double DoubleDivision() { |
| 580 | double a, b, c; |
| 581 | a = 8D; |
| 582 | b = 2.5D; |
| 583 | c = a / b; |
| 584 | return c; |
| 585 | } |
| 586 | |
Roland Levillain | f7746ad | 2015-07-22 14:12:01 +0100 | [diff] [blame] | 587 | |
| 588 | /** |
| 589 | * Exercise constant folding on remainder. |
| 590 | */ |
| 591 | |
| 592 | /// CHECK-START: int Main.IntRemainder() constant_folding (before) |
| 593 | /// CHECK-DAG: <<Const8:i\d+>> IntConstant 8 |
| 594 | /// CHECK-DAG: <<Const3:i\d+>> IntConstant 3 |
| 595 | /// CHECK-DAG: <<Div0Chk:i\d+>> DivZeroCheck [<<Const3>>] |
| 596 | /// CHECK-DAG: <<Rem:i\d+>> Rem [<<Const8>>,<<Div0Chk>>] |
| 597 | /// CHECK-DAG: Return [<<Rem>>] |
| 598 | |
| 599 | /// CHECK-START: int Main.IntRemainder() constant_folding (after) |
| 600 | /// CHECK-DAG: <<Const2:i\d+>> IntConstant 2 |
| 601 | /// CHECK-DAG: Return [<<Const2>>] |
| 602 | |
| 603 | /// CHECK-START: int Main.IntRemainder() constant_folding (after) |
| 604 | /// CHECK-NOT: DivZeroCheck |
| 605 | /// CHECK-NOT: Rem |
| 606 | |
| 607 | public static int IntRemainder() { |
| 608 | int a, b, c; |
| 609 | a = 8; |
| 610 | b = 3; |
| 611 | c = a % b; |
| 612 | return c; |
| 613 | } |
| 614 | |
| 615 | /// CHECK-START: long Main.LongRemainder() constant_folding (before) |
| 616 | /// CHECK-DAG: <<Const8:j\d+>> LongConstant 8 |
| 617 | /// CHECK-DAG: <<Const3:j\d+>> LongConstant 3 |
| 618 | /// CHECK-DAG: <<Div0Chk:j\d+>> DivZeroCheck [<<Const3>>] |
| 619 | /// CHECK-DAG: <<Rem:j\d+>> Rem [<<Const8>>,<<Div0Chk>>] |
| 620 | /// CHECK-DAG: Return [<<Rem>>] |
| 621 | |
| 622 | /// CHECK-START: long Main.LongRemainder() constant_folding (after) |
| 623 | /// CHECK-DAG: <<Const2:j\d+>> LongConstant 2 |
| 624 | /// CHECK-DAG: Return [<<Const2>>] |
| 625 | |
| 626 | /// CHECK-START: long Main.LongRemainder() constant_folding (after) |
| 627 | /// CHECK-NOT: DivZeroCheck |
| 628 | /// CHECK-NOT: Rem |
| 629 | |
| 630 | public static long LongRemainder() { |
| 631 | long a, b, c; |
| 632 | a = 8L; |
| 633 | b = 3L; |
| 634 | c = a % b; |
| 635 | return c; |
| 636 | } |
| 637 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame^] | 638 | /// CHECK-START: float Main.FloatRemainder() constant_folding (before) |
| 639 | /// CHECK-DAG: <<Const8:f\d+>> FloatConstant 8 |
| 640 | /// CHECK-DAG: <<Const2P5:f\d+>> FloatConstant 2.5 |
| 641 | /// CHECK-DAG: <<Rem:f\d+>> Rem [<<Const8>>,<<Const2P5>>] |
| 642 | /// CHECK-DAG: Return [<<Rem>>] |
| 643 | |
| 644 | /// CHECK-START: float Main.FloatRemainder() constant_folding (after) |
| 645 | /// CHECK-DAG: <<Const0P5:f\d+>> FloatConstant 0.5 |
| 646 | /// CHECK-DAG: Return [<<Const0P5>>] |
| 647 | |
| 648 | /// CHECK-START: float Main.FloatRemainder() constant_folding (after) |
| 649 | /// CHECK-NOT: Rem |
| 650 | |
| 651 | public static float FloatRemainder() { |
| 652 | float a, b, c; |
| 653 | a = 8F; |
| 654 | b = 2.5F; |
| 655 | c = a % b; |
| 656 | return c; |
| 657 | } |
| 658 | |
| 659 | /// CHECK-START: double Main.DoubleRemainder() constant_folding (before) |
| 660 | /// CHECK-DAG: <<Const8:d\d+>> DoubleConstant 8 |
| 661 | /// CHECK-DAG: <<Const2P5:d\d+>> DoubleConstant 2.5 |
| 662 | /// CHECK-DAG: <<Rem:d\d+>> Rem [<<Const8>>,<<Const2P5>>] |
| 663 | /// CHECK-DAG: Return [<<Rem>>] |
| 664 | |
| 665 | /// CHECK-START: double Main.DoubleRemainder() constant_folding (after) |
| 666 | /// CHECK-DAG: <<Const0P5:d\d+>> DoubleConstant 0.5 |
| 667 | /// CHECK-DAG: Return [<<Const0P5>>] |
| 668 | |
| 669 | /// CHECK-START: double Main.DoubleRemainder() constant_folding (after) |
| 670 | /// CHECK-NOT: Rem |
| 671 | |
| 672 | public static double DoubleRemainder() { |
| 673 | double a, b, c; |
| 674 | a = 8D; |
| 675 | b = 2.5D; |
| 676 | c = a % b; |
| 677 | return c; |
| 678 | } |
| 679 | |
Roland Levillain | f7746ad | 2015-07-22 14:12:01 +0100 | [diff] [blame] | 680 | |
| 681 | /** |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 682 | * Exercise constant folding on left shift. |
| 683 | */ |
| 684 | |
| 685 | /// CHECK-START: int Main.ShlIntLong() constant_folding (before) |
| 686 | /// CHECK-DAG: <<Const1:i\d+>> IntConstant 1 |
| 687 | /// CHECK-DAG: <<Const2L:j\d+>> LongConstant 2 |
| 688 | /// CHECK-DAG: <<TypeConv:i\d+>> TypeConversion [<<Const2L>>] |
| 689 | /// CHECK-DAG: <<Shl:i\d+>> Shl [<<Const1>>,<<TypeConv>>] |
| 690 | /// CHECK-DAG: Return [<<Shl>>] |
| 691 | |
| 692 | /// CHECK-START: int Main.ShlIntLong() constant_folding (after) |
| 693 | /// CHECK-DAG: <<Const4:i\d+>> IntConstant 4 |
| 694 | /// CHECK-DAG: Return [<<Const4>>] |
| 695 | |
| 696 | /// CHECK-START: int Main.ShlIntLong() constant_folding (after) |
| 697 | /// CHECK-NOT: Shl |
| 698 | |
| 699 | public static int ShlIntLong() { |
| 700 | int lhs = 1; |
| 701 | long rhs = 2; |
| 702 | return lhs << rhs; |
| 703 | } |
| 704 | |
| 705 | /// CHECK-START: long Main.ShlLongInt() constant_folding (before) |
| 706 | /// CHECK-DAG: <<Const3L:j\d+>> LongConstant 3 |
| 707 | /// CHECK-DAG: <<Const2:i\d+>> IntConstant 2 |
| 708 | /// CHECK-DAG: <<Shl:j\d+>> Shl [<<Const3L>>,<<Const2>>] |
| 709 | /// CHECK-DAG: Return [<<Shl>>] |
| 710 | |
| 711 | /// CHECK-START: long Main.ShlLongInt() constant_folding (after) |
| 712 | /// CHECK-DAG: <<Const12L:j\d+>> LongConstant 12 |
| 713 | /// CHECK-DAG: Return [<<Const12L>>] |
| 714 | |
| 715 | /// CHECK-START: long Main.ShlLongInt() constant_folding (after) |
| 716 | /// CHECK-NOT: Shl |
| 717 | |
| 718 | public static long ShlLongInt() { |
| 719 | long lhs = 3; |
| 720 | int rhs = 2; |
| 721 | return lhs << rhs; |
| 722 | } |
| 723 | |
| 724 | |
| 725 | /** |
| 726 | * Exercise constant folding on right shift. |
| 727 | */ |
| 728 | |
| 729 | /// CHECK-START: int Main.ShrIntLong() constant_folding (before) |
| 730 | /// CHECK-DAG: <<Const7:i\d+>> IntConstant 7 |
| 731 | /// CHECK-DAG: <<Const2L:j\d+>> LongConstant 2 |
| 732 | /// CHECK-DAG: <<TypeConv:i\d+>> TypeConversion [<<Const2L>>] |
| 733 | /// CHECK-DAG: <<Shr:i\d+>> Shr [<<Const7>>,<<TypeConv>>] |
| 734 | /// CHECK-DAG: Return [<<Shr>>] |
| 735 | |
| 736 | /// CHECK-START: int Main.ShrIntLong() constant_folding (after) |
| 737 | /// CHECK-DAG: <<Const1:i\d+>> IntConstant 1 |
| 738 | /// CHECK-DAG: Return [<<Const1>>] |
| 739 | |
| 740 | /// CHECK-START: int Main.ShrIntLong() constant_folding (after) |
| 741 | /// CHECK-NOT: Shr |
| 742 | |
| 743 | public static int ShrIntLong() { |
| 744 | int lhs = 7; |
| 745 | long rhs = 2; |
| 746 | return lhs >> rhs; |
| 747 | } |
| 748 | |
| 749 | /// CHECK-START: long Main.ShrLongInt() constant_folding (before) |
| 750 | /// CHECK-DAG: <<Const9L:j\d+>> LongConstant 9 |
| 751 | /// CHECK-DAG: <<Const2:i\d+>> IntConstant 2 |
| 752 | /// CHECK-DAG: <<Shr:j\d+>> Shr [<<Const9L>>,<<Const2>>] |
| 753 | /// CHECK-DAG: Return [<<Shr>>] |
| 754 | |
| 755 | /// CHECK-START: long Main.ShrLongInt() constant_folding (after) |
| 756 | /// CHECK-DAG: <<Const2L:j\d+>> LongConstant 2 |
| 757 | /// CHECK-DAG: Return [<<Const2L>>] |
| 758 | |
| 759 | /// CHECK-START: long Main.ShrLongInt() constant_folding (after) |
| 760 | /// CHECK-NOT: Shr |
| 761 | |
| 762 | public static long ShrLongInt() { |
| 763 | long lhs = 9; |
| 764 | int rhs = 2; |
| 765 | return lhs >> rhs; |
| 766 | } |
| 767 | |
| 768 | |
| 769 | /** |
| 770 | * Exercise constant folding on unsigned right shift. |
| 771 | */ |
| 772 | |
| 773 | /// CHECK-START: int Main.UShrIntLong() constant_folding (before) |
| 774 | /// CHECK-DAG: <<ConstM7:i\d+>> IntConstant -7 |
| 775 | /// CHECK-DAG: <<Const2L:j\d+>> LongConstant 2 |
| 776 | /// CHECK-DAG: <<TypeConv:i\d+>> TypeConversion [<<Const2L>>] |
| 777 | /// CHECK-DAG: <<UShr:i\d+>> UShr [<<ConstM7>>,<<TypeConv>>] |
| 778 | /// CHECK-DAG: Return [<<UShr>>] |
| 779 | |
| 780 | /// CHECK-START: int Main.UShrIntLong() constant_folding (after) |
| 781 | /// CHECK-DAG: <<ConstRes:i\d+>> IntConstant 1073741822 |
| 782 | /// CHECK-DAG: Return [<<ConstRes>>] |
| 783 | |
| 784 | /// CHECK-START: int Main.UShrIntLong() constant_folding (after) |
| 785 | /// CHECK-NOT: UShr |
| 786 | |
| 787 | public static int UShrIntLong() { |
| 788 | int lhs = -7; |
| 789 | long rhs = 2; |
| 790 | return lhs >>> rhs; |
| 791 | } |
| 792 | |
| 793 | /// CHECK-START: long Main.UShrLongInt() constant_folding (before) |
| 794 | /// CHECK-DAG: <<ConstM9L:j\d+>> LongConstant -9 |
| 795 | /// CHECK-DAG: <<Const2:i\d+>> IntConstant 2 |
| 796 | /// CHECK-DAG: <<UShr:j\d+>> UShr [<<ConstM9L>>,<<Const2>>] |
| 797 | /// CHECK-DAG: Return [<<UShr>>] |
| 798 | |
| 799 | /// CHECK-START: long Main.UShrLongInt() constant_folding (after) |
| 800 | /// CHECK-DAG: <<ConstRes:j\d+>> LongConstant 4611686018427387901 |
| 801 | /// CHECK-DAG: Return [<<ConstRes>>] |
| 802 | |
| 803 | /// CHECK-START: long Main.UShrLongInt() constant_folding (after) |
| 804 | /// CHECK-NOT: UShr |
| 805 | |
| 806 | public static long UShrLongInt() { |
| 807 | long lhs = -9; |
| 808 | int rhs = 2; |
| 809 | return lhs >>> rhs; |
| 810 | } |
| 811 | |
| 812 | |
| 813 | /** |
| 814 | * Exercise constant folding on logical and. |
| 815 | */ |
| 816 | |
| 817 | /// CHECK-START: long Main.AndIntLong() constant_folding (before) |
| 818 | /// CHECK-DAG: <<Const10:i\d+>> IntConstant 10 |
| 819 | /// CHECK-DAG: <<Const3L:j\d+>> LongConstant 3 |
| 820 | /// CHECK-DAG: <<TypeConv:j\d+>> TypeConversion [<<Const10>>] |
| 821 | /// CHECK-DAG: <<And:j\d+>> And [<<TypeConv>>,<<Const3L>>] |
| 822 | /// CHECK-DAG: Return [<<And>>] |
| 823 | |
| 824 | /// CHECK-START: long Main.AndIntLong() constant_folding (after) |
| 825 | /// CHECK-DAG: <<Const2:j\d+>> LongConstant 2 |
| 826 | /// CHECK-DAG: Return [<<Const2>>] |
| 827 | |
| 828 | /// CHECK-START: long Main.AndIntLong() constant_folding (after) |
| 829 | /// CHECK-NOT: And |
| 830 | |
| 831 | public static long AndIntLong() { |
| 832 | int lhs = 10; |
| 833 | long rhs = 3; |
| 834 | return lhs & rhs; |
| 835 | } |
| 836 | |
| 837 | /// CHECK-START: long Main.AndLongInt() constant_folding (before) |
| 838 | /// CHECK-DAG: <<Const10L:j\d+>> LongConstant 10 |
| 839 | /// CHECK-DAG: <<Const3:i\d+>> IntConstant 3 |
| 840 | /// CHECK-DAG: <<TypeConv:j\d+>> TypeConversion [<<Const3>>] |
David Brazdil | 57e863c | 2016-01-11 10:27:13 +0000 | [diff] [blame] | 841 | /// CHECK-DAG: <<And:j\d+>> And [<<TypeConv>>,<<Const10L>>] |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 842 | /// CHECK-DAG: Return [<<And>>] |
| 843 | |
| 844 | /// CHECK-START: long Main.AndLongInt() constant_folding (after) |
| 845 | /// CHECK-DAG: <<Const2:j\d+>> LongConstant 2 |
| 846 | /// CHECK-DAG: Return [<<Const2>>] |
| 847 | |
| 848 | /// CHECK-START: long Main.AndLongInt() constant_folding (after) |
| 849 | /// CHECK-NOT: And |
| 850 | |
| 851 | public static long AndLongInt() { |
| 852 | long lhs = 10; |
| 853 | int rhs = 3; |
| 854 | return lhs & rhs; |
| 855 | } |
| 856 | |
| 857 | |
| 858 | /** |
| 859 | * Exercise constant folding on logical or. |
| 860 | */ |
| 861 | |
| 862 | /// CHECK-START: long Main.OrIntLong() constant_folding (before) |
| 863 | /// CHECK-DAG: <<Const10:i\d+>> IntConstant 10 |
| 864 | /// CHECK-DAG: <<Const3L:j\d+>> LongConstant 3 |
| 865 | /// CHECK-DAG: <<TypeConv:j\d+>> TypeConversion [<<Const10>>] |
| 866 | /// CHECK-DAG: <<Or:j\d+>> Or [<<TypeConv>>,<<Const3L>>] |
| 867 | /// CHECK-DAG: Return [<<Or>>] |
| 868 | |
| 869 | /// CHECK-START: long Main.OrIntLong() constant_folding (after) |
| 870 | /// CHECK-DAG: <<Const11:j\d+>> LongConstant 11 |
| 871 | /// CHECK-DAG: Return [<<Const11>>] |
| 872 | |
| 873 | /// CHECK-START: long Main.OrIntLong() constant_folding (after) |
| 874 | /// CHECK-NOT: Or |
| 875 | |
| 876 | public static long OrIntLong() { |
| 877 | int lhs = 10; |
| 878 | long rhs = 3; |
| 879 | return lhs | rhs; |
| 880 | } |
| 881 | |
| 882 | /// CHECK-START: long Main.OrLongInt() constant_folding (before) |
| 883 | /// CHECK-DAG: <<Const10L:j\d+>> LongConstant 10 |
| 884 | /// CHECK-DAG: <<Const3:i\d+>> IntConstant 3 |
| 885 | /// CHECK-DAG: <<TypeConv:j\d+>> TypeConversion [<<Const3>>] |
David Brazdil | 57e863c | 2016-01-11 10:27:13 +0000 | [diff] [blame] | 886 | /// CHECK-DAG: <<Or:j\d+>> Or [<<TypeConv>>,<<Const10L>>] |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 887 | /// CHECK-DAG: Return [<<Or>>] |
| 888 | |
| 889 | /// CHECK-START: long Main.OrLongInt() constant_folding (after) |
| 890 | /// CHECK-DAG: <<Const11:j\d+>> LongConstant 11 |
| 891 | /// CHECK-DAG: Return [<<Const11>>] |
| 892 | |
| 893 | /// CHECK-START: long Main.OrLongInt() constant_folding (after) |
| 894 | /// CHECK-NOT: Or |
| 895 | |
| 896 | public static long OrLongInt() { |
| 897 | long lhs = 10; |
| 898 | int rhs = 3; |
| 899 | return lhs | rhs; |
| 900 | } |
| 901 | |
| 902 | |
| 903 | /** |
| 904 | * Exercise constant folding on logical exclusive or. |
| 905 | */ |
| 906 | |
| 907 | /// CHECK-START: long Main.XorIntLong() constant_folding (before) |
| 908 | /// CHECK-DAG: <<Const10:i\d+>> IntConstant 10 |
| 909 | /// CHECK-DAG: <<Const3L:j\d+>> LongConstant 3 |
| 910 | /// CHECK-DAG: <<TypeConv:j\d+>> TypeConversion [<<Const10>>] |
| 911 | /// CHECK-DAG: <<Xor:j\d+>> Xor [<<TypeConv>>,<<Const3L>>] |
| 912 | /// CHECK-DAG: Return [<<Xor>>] |
| 913 | |
| 914 | /// CHECK-START: long Main.XorIntLong() constant_folding (after) |
| 915 | /// CHECK-DAG: <<Const9:j\d+>> LongConstant 9 |
| 916 | /// CHECK-DAG: Return [<<Const9>>] |
| 917 | |
| 918 | /// CHECK-START: long Main.XorIntLong() constant_folding (after) |
| 919 | /// CHECK-NOT: Xor |
| 920 | |
| 921 | public static long XorIntLong() { |
| 922 | int lhs = 10; |
| 923 | long rhs = 3; |
| 924 | return lhs ^ rhs; |
| 925 | } |
| 926 | |
| 927 | /// CHECK-START: long Main.XorLongInt() constant_folding (before) |
| 928 | /// CHECK-DAG: <<Const10L:j\d+>> LongConstant 10 |
| 929 | /// CHECK-DAG: <<Const3:i\d+>> IntConstant 3 |
| 930 | /// CHECK-DAG: <<TypeConv:j\d+>> TypeConversion [<<Const3>>] |
David Brazdil | 57e863c | 2016-01-11 10:27:13 +0000 | [diff] [blame] | 931 | /// CHECK-DAG: <<Xor:j\d+>> Xor [<<TypeConv>>,<<Const10L>>] |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 932 | /// CHECK-DAG: Return [<<Xor>>] |
| 933 | |
| 934 | /// CHECK-START: long Main.XorLongInt() constant_folding (after) |
| 935 | /// CHECK-DAG: <<Const9:j\d+>> LongConstant 9 |
| 936 | /// CHECK-DAG: Return [<<Const9>>] |
| 937 | |
| 938 | /// CHECK-START: long Main.XorLongInt() constant_folding (after) |
| 939 | /// CHECK-NOT: Xor |
| 940 | |
| 941 | public static long XorLongInt() { |
| 942 | long lhs = 10; |
| 943 | int rhs = 3; |
| 944 | return lhs ^ rhs; |
| 945 | } |
| 946 | |
| 947 | |
| 948 | /** |
Roland Levillain | b65eb50 | 2015-07-23 12:11:42 +0100 | [diff] [blame] | 949 | * Exercise constant folding on constant (static) condition. |
David Brazdil | ee690a3 | 2014-12-01 17:04:16 +0000 | [diff] [blame] | 950 | */ |
| 951 | |
David Brazdil | a06d66a | 2015-05-28 11:14:54 +0100 | [diff] [blame] | 952 | /// CHECK-START: int Main.StaticCondition() constant_folding (before) |
| 953 | /// CHECK-DAG: <<Const7:i\d+>> IntConstant 7 |
| 954 | /// CHECK-DAG: <<Const2:i\d+>> IntConstant 2 |
| 955 | /// CHECK-DAG: <<Cond:z\d+>> GreaterThanOrEqual [<<Const7>>,<<Const2>>] |
| 956 | /// CHECK-DAG: If [<<Cond>>] |
David Brazdil | ee690a3 | 2014-12-01 17:04:16 +0000 | [diff] [blame] | 957 | |
David Brazdil | a06d66a | 2015-05-28 11:14:54 +0100 | [diff] [blame] | 958 | /// CHECK-START: int Main.StaticCondition() constant_folding (after) |
| 959 | /// CHECK-DAG: <<Const1:i\d+>> IntConstant 1 |
| 960 | /// CHECK-DAG: If [<<Const1>>] |
David Brazdil | ee690a3 | 2014-12-01 17:04:16 +0000 | [diff] [blame] | 961 | |
Roland Levillain | b65eb50 | 2015-07-23 12:11:42 +0100 | [diff] [blame] | 962 | /// CHECK-START: int Main.StaticCondition() constant_folding (after) |
| 963 | /// CHECK-NOT: GreaterThanOrEqual |
| 964 | |
David Brazdil | ee690a3 | 2014-12-01 17:04:16 +0000 | [diff] [blame] | 965 | public static int StaticCondition() { |
| 966 | int a, b, c; |
David Brazdil | 4846d13 | 2015-01-15 19:07:08 +0000 | [diff] [blame] | 967 | a = 7; |
David Brazdil | ee690a3 | 2014-12-01 17:04:16 +0000 | [diff] [blame] | 968 | b = 2; |
| 969 | if (a < b) |
| 970 | c = a + b; |
| 971 | else |
| 972 | c = a - b; |
| 973 | return c; |
| 974 | } |
| 975 | |
Roland Levillain | b65eb50 | 2015-07-23 12:11:42 +0100 | [diff] [blame] | 976 | |
David Brazdil | ee690a3 | 2014-12-01 17:04:16 +0000 | [diff] [blame] | 977 | /** |
Vladimir Marko | 9e23df5 | 2015-11-10 17:14:35 +0000 | [diff] [blame] | 978 | * Exercise constant folding on constant (static) condition for null references. |
| 979 | */ |
| 980 | |
| 981 | /// CHECK-START: int Main.StaticConditionNulls() constant_folding_after_inlining (before) |
| 982 | /// CHECK-DAG: <<Null:l\d+>> NullConstant |
| 983 | /// CHECK-DAG: <<Cond:z\d+>> NotEqual [<<Null>>,<<Null>>] |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 984 | /// CHECK-DAG: Select [{{i\d+}},{{i\d+}},<<Cond>>] |
Vladimir Marko | 9e23df5 | 2015-11-10 17:14:35 +0000 | [diff] [blame] | 985 | |
| 986 | /// CHECK-START: int Main.StaticConditionNulls() constant_folding_after_inlining (after) |
| 987 | /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0 |
David Brazdil | 74eb1b2 | 2015-12-14 11:44:01 +0000 | [diff] [blame] | 988 | /// CHECK-DAG: Select [{{i\d+}},{{i\d+}},<<Const0>>] |
Vladimir Marko | 9e23df5 | 2015-11-10 17:14:35 +0000 | [diff] [blame] | 989 | |
| 990 | /// CHECK-START: int Main.StaticConditionNulls() constant_folding_after_inlining (after) |
| 991 | /// CHECK-NOT: NotEqual |
| 992 | |
| 993 | private static Object getNull() { |
| 994 | return null; |
| 995 | } |
| 996 | |
| 997 | public static int StaticConditionNulls() { |
| 998 | Object a = getNull(); |
| 999 | Object b = getNull(); |
| 1000 | return (a == b) ? 5 : 2; |
| 1001 | } |
| 1002 | |
| 1003 | |
| 1004 | /** |
Roland Levillain | b65eb50 | 2015-07-23 12:11:42 +0100 | [diff] [blame] | 1005 | * Exercise constant folding on a program with condition |
| 1006 | * (i.e. jumps) leading to the creation of many blocks. |
David Brazdil | ee690a3 | 2014-12-01 17:04:16 +0000 | [diff] [blame] | 1007 | * |
| 1008 | * The intent of this test is to ensure that all constant expressions |
| 1009 | * are actually evaluated at compile-time, thanks to the reverse |
| 1010 | * (forward) post-order traversal of the the dominator tree. |
| 1011 | */ |
| 1012 | |
David Brazdil | a06d66a | 2015-05-28 11:14:54 +0100 | [diff] [blame] | 1013 | /// CHECK-START: int Main.JumpsAndConditionals(boolean) constant_folding (before) |
| 1014 | /// CHECK-DAG: <<Const2:i\d+>> IntConstant 2 |
| 1015 | /// CHECK-DAG: <<Const5:i\d+>> IntConstant 5 |
| 1016 | /// CHECK-DAG: <<Add:i\d+>> Add [<<Const5>>,<<Const2>>] |
| 1017 | /// CHECK-DAG: <<Sub:i\d+>> Sub [<<Const5>>,<<Const2>>] |
| 1018 | /// CHECK-DAG: <<Phi:i\d+>> Phi [<<Add>>,<<Sub>>] |
| 1019 | /// CHECK-DAG: Return [<<Phi>>] |
David Brazdil | ee690a3 | 2014-12-01 17:04:16 +0000 | [diff] [blame] | 1020 | |
David Brazdil | a06d66a | 2015-05-28 11:14:54 +0100 | [diff] [blame] | 1021 | /// CHECK-START: int Main.JumpsAndConditionals(boolean) constant_folding (after) |
| 1022 | /// CHECK-DAG: <<Const3:i\d+>> IntConstant 3 |
| 1023 | /// CHECK-DAG: <<Const7:i\d+>> IntConstant 7 |
| 1024 | /// CHECK-DAG: <<Phi:i\d+>> Phi [<<Const7>>,<<Const3>>] |
| 1025 | /// CHECK-DAG: Return [<<Phi>>] |
David Brazdil | ee690a3 | 2014-12-01 17:04:16 +0000 | [diff] [blame] | 1026 | |
Roland Levillain | b65eb50 | 2015-07-23 12:11:42 +0100 | [diff] [blame] | 1027 | /// CHECK-START: int Main.JumpsAndConditionals(boolean) constant_folding (after) |
| 1028 | /// CHECK-NOT: Add |
| 1029 | /// CHECK-NOT: Sub |
| 1030 | |
David Brazdil | ee690a3 | 2014-12-01 17:04:16 +0000 | [diff] [blame] | 1031 | public static int JumpsAndConditionals(boolean cond) { |
| 1032 | int a, b, c; |
| 1033 | a = 5; |
| 1034 | b = 2; |
| 1035 | if (cond) |
| 1036 | c = a + b; |
| 1037 | else |
| 1038 | c = a - b; |
| 1039 | return c; |
| 1040 | } |
David Brazdil | 4846d13 | 2015-01-15 19:07:08 +0000 | [diff] [blame] | 1041 | |
Roland Levillain | b65eb50 | 2015-07-23 12:11:42 +0100 | [diff] [blame] | 1042 | |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 1043 | /** |
| 1044 | * Test optimizations of arithmetic identities yielding a constant result. |
| 1045 | */ |
| 1046 | |
David Brazdil | a06d66a | 2015-05-28 11:14:54 +0100 | [diff] [blame] | 1047 | /// CHECK-START: int Main.And0(int) constant_folding (before) |
| 1048 | /// CHECK-DAG: <<Arg:i\d+>> ParameterValue |
| 1049 | /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0 |
| 1050 | /// CHECK-DAG: <<And:i\d+>> And [<<Arg>>,<<Const0>>] |
| 1051 | /// CHECK-DAG: Return [<<And>>] |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 1052 | |
David Brazdil | a06d66a | 2015-05-28 11:14:54 +0100 | [diff] [blame] | 1053 | /// CHECK-START: int Main.And0(int) constant_folding (after) |
| 1054 | /// CHECK-DAG: <<Arg:i\d+>> ParameterValue |
| 1055 | /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0 |
David Brazdil | a06d66a | 2015-05-28 11:14:54 +0100 | [diff] [blame] | 1056 | /// CHECK-DAG: Return [<<Const0>>] |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 1057 | |
Roland Levillain | b65eb50 | 2015-07-23 12:11:42 +0100 | [diff] [blame] | 1058 | /// CHECK-START: int Main.And0(int) constant_folding (after) |
| 1059 | /// CHECK-NOT: And |
| 1060 | |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 1061 | public static int And0(int arg) { |
| 1062 | return arg & 0; |
| 1063 | } |
| 1064 | |
David Brazdil | a06d66a | 2015-05-28 11:14:54 +0100 | [diff] [blame] | 1065 | /// CHECK-START: long Main.Mul0(long) constant_folding (before) |
| 1066 | /// CHECK-DAG: <<Arg:j\d+>> ParameterValue |
| 1067 | /// CHECK-DAG: <<Const0:j\d+>> LongConstant 0 |
David Brazdil | 57e863c | 2016-01-11 10:27:13 +0000 | [diff] [blame] | 1068 | /// CHECK-DAG: <<Mul:j\d+>> Mul [<<Const0>>,<<Arg>>] |
David Brazdil | a06d66a | 2015-05-28 11:14:54 +0100 | [diff] [blame] | 1069 | /// CHECK-DAG: Return [<<Mul>>] |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 1070 | |
David Brazdil | a06d66a | 2015-05-28 11:14:54 +0100 | [diff] [blame] | 1071 | /// CHECK-START: long Main.Mul0(long) constant_folding (after) |
| 1072 | /// CHECK-DAG: <<Arg:j\d+>> ParameterValue |
| 1073 | /// CHECK-DAG: <<Const0:j\d+>> LongConstant 0 |
David Brazdil | a06d66a | 2015-05-28 11:14:54 +0100 | [diff] [blame] | 1074 | /// CHECK-DAG: Return [<<Const0>>] |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 1075 | |
Roland Levillain | b65eb50 | 2015-07-23 12:11:42 +0100 | [diff] [blame] | 1076 | /// CHECK-START: long Main.Mul0(long) constant_folding (after) |
| 1077 | /// CHECK-NOT: Mul |
| 1078 | |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 1079 | public static long Mul0(long arg) { |
| 1080 | return arg * 0; |
| 1081 | } |
| 1082 | |
David Brazdil | a06d66a | 2015-05-28 11:14:54 +0100 | [diff] [blame] | 1083 | /// CHECK-START: int Main.OrAllOnes(int) constant_folding (before) |
| 1084 | /// CHECK-DAG: <<Arg:i\d+>> ParameterValue |
| 1085 | /// CHECK-DAG: <<ConstF:i\d+>> IntConstant -1 |
| 1086 | /// CHECK-DAG: <<Or:i\d+>> Or [<<Arg>>,<<ConstF>>] |
| 1087 | /// CHECK-DAG: Return [<<Or>>] |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 1088 | |
David Brazdil | a06d66a | 2015-05-28 11:14:54 +0100 | [diff] [blame] | 1089 | /// CHECK-START: int Main.OrAllOnes(int) constant_folding (after) |
| 1090 | /// CHECK-DAG: <<ConstF:i\d+>> IntConstant -1 |
David Brazdil | a06d66a | 2015-05-28 11:14:54 +0100 | [diff] [blame] | 1091 | /// CHECK-DAG: Return [<<ConstF>>] |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 1092 | |
Roland Levillain | b65eb50 | 2015-07-23 12:11:42 +0100 | [diff] [blame] | 1093 | /// CHECK-START: int Main.OrAllOnes(int) constant_folding (after) |
| 1094 | /// CHECK-NOT: Or |
| 1095 | |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 1096 | public static int OrAllOnes(int arg) { |
| 1097 | return arg | -1; |
| 1098 | } |
| 1099 | |
David Brazdil | a06d66a | 2015-05-28 11:14:54 +0100 | [diff] [blame] | 1100 | /// CHECK-START: long Main.Rem0(long) constant_folding (before) |
| 1101 | /// CHECK-DAG: <<Arg:j\d+>> ParameterValue |
| 1102 | /// CHECK-DAG: <<Const0:j\d+>> LongConstant 0 |
| 1103 | /// CHECK-DAG: <<DivZeroCheck:j\d+>> DivZeroCheck [<<Arg>>] |
| 1104 | /// CHECK-DAG: <<Rem:j\d+>> Rem [<<Const0>>,<<DivZeroCheck>>] |
| 1105 | /// CHECK-DAG: Return [<<Rem>>] |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 1106 | |
David Brazdil | a06d66a | 2015-05-28 11:14:54 +0100 | [diff] [blame] | 1107 | /// CHECK-START: long Main.Rem0(long) constant_folding (after) |
| 1108 | /// CHECK-DAG: <<Const0:j\d+>> LongConstant 0 |
David Brazdil | a06d66a | 2015-05-28 11:14:54 +0100 | [diff] [blame] | 1109 | /// CHECK-DAG: Return [<<Const0>>] |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 1110 | |
Roland Levillain | b65eb50 | 2015-07-23 12:11:42 +0100 | [diff] [blame] | 1111 | /// CHECK-START: long Main.Rem0(long) constant_folding (after) |
| 1112 | /// CHECK-NOT: Rem |
| 1113 | |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 1114 | public static long Rem0(long arg) { |
| 1115 | return 0 % arg; |
| 1116 | } |
| 1117 | |
David Brazdil | a06d66a | 2015-05-28 11:14:54 +0100 | [diff] [blame] | 1118 | /// CHECK-START: int Main.Rem1(int) constant_folding (before) |
| 1119 | /// CHECK-DAG: <<Arg:i\d+>> ParameterValue |
| 1120 | /// CHECK-DAG: <<Const1:i\d+>> IntConstant 1 |
| 1121 | /// CHECK-DAG: <<Rem:i\d+>> Rem [<<Arg>>,<<Const1>>] |
| 1122 | /// CHECK-DAG: Return [<<Rem>>] |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 1123 | |
David Brazdil | a06d66a | 2015-05-28 11:14:54 +0100 | [diff] [blame] | 1124 | /// CHECK-START: int Main.Rem1(int) constant_folding (after) |
| 1125 | /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0 |
David Brazdil | a06d66a | 2015-05-28 11:14:54 +0100 | [diff] [blame] | 1126 | /// CHECK-DAG: Return [<<Const0>>] |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 1127 | |
Roland Levillain | b65eb50 | 2015-07-23 12:11:42 +0100 | [diff] [blame] | 1128 | /// CHECK-START: int Main.Rem1(int) constant_folding (after) |
| 1129 | /// CHECK-NOT: Rem |
| 1130 | |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 1131 | public static int Rem1(int arg) { |
| 1132 | return arg % 1; |
| 1133 | } |
| 1134 | |
David Brazdil | a06d66a | 2015-05-28 11:14:54 +0100 | [diff] [blame] | 1135 | /// CHECK-START: long Main.RemN1(long) constant_folding (before) |
| 1136 | /// CHECK-DAG: <<Arg:j\d+>> ParameterValue |
| 1137 | /// CHECK-DAG: <<ConstN1:j\d+>> LongConstant -1 |
| 1138 | /// CHECK-DAG: <<DivZeroCheck:j\d+>> DivZeroCheck [<<ConstN1>>] |
| 1139 | /// CHECK-DAG: <<Rem:j\d+>> Rem [<<Arg>>,<<DivZeroCheck>>] |
| 1140 | /// CHECK-DAG: Return [<<Rem>>] |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 1141 | |
David Brazdil | a06d66a | 2015-05-28 11:14:54 +0100 | [diff] [blame] | 1142 | /// CHECK-START: long Main.RemN1(long) constant_folding (after) |
| 1143 | /// CHECK-DAG: <<Const0:j\d+>> LongConstant 0 |
David Brazdil | a06d66a | 2015-05-28 11:14:54 +0100 | [diff] [blame] | 1144 | /// CHECK-DAG: Return [<<Const0>>] |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 1145 | |
Roland Levillain | b65eb50 | 2015-07-23 12:11:42 +0100 | [diff] [blame] | 1146 | /// CHECK-START: long Main.RemN1(long) constant_folding (after) |
| 1147 | /// CHECK-NOT: Rem |
| 1148 | |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 1149 | public static long RemN1(long arg) { |
| 1150 | return arg % -1; |
| 1151 | } |
| 1152 | |
David Brazdil | a06d66a | 2015-05-28 11:14:54 +0100 | [diff] [blame] | 1153 | /// CHECK-START: int Main.Shl0(int) constant_folding (before) |
| 1154 | /// CHECK-DAG: <<Arg:i\d+>> ParameterValue |
| 1155 | /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0 |
| 1156 | /// CHECK-DAG: <<Shl:i\d+>> Shl [<<Const0>>,<<Arg>>] |
| 1157 | /// CHECK-DAG: Return [<<Shl>>] |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 1158 | |
David Brazdil | a06d66a | 2015-05-28 11:14:54 +0100 | [diff] [blame] | 1159 | /// CHECK-START: int Main.Shl0(int) constant_folding (after) |
| 1160 | /// CHECK-DAG: <<Arg:i\d+>> ParameterValue |
| 1161 | /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0 |
David Brazdil | a06d66a | 2015-05-28 11:14:54 +0100 | [diff] [blame] | 1162 | /// CHECK-DAG: Return [<<Const0>>] |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 1163 | |
Roland Levillain | b65eb50 | 2015-07-23 12:11:42 +0100 | [diff] [blame] | 1164 | /// CHECK-START: int Main.Shl0(int) constant_folding (after) |
| 1165 | /// CHECK-NOT: Shl |
| 1166 | |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 1167 | public static int Shl0(int arg) { |
| 1168 | return 0 << arg; |
| 1169 | } |
| 1170 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 1171 | /// CHECK-START: long Main.ShlLong0WithInt(int) constant_folding (before) |
| 1172 | /// CHECK-DAG: <<Arg:i\d+>> ParameterValue |
| 1173 | /// CHECK-DAG: <<Const0L:j\d+>> LongConstant 0 |
| 1174 | /// CHECK-DAG: <<Shl:j\d+>> Shl [<<Const0L>>,<<Arg>>] |
| 1175 | /// CHECK-DAG: Return [<<Shl>>] |
| 1176 | |
| 1177 | /// CHECK-START: long Main.ShlLong0WithInt(int) constant_folding (after) |
| 1178 | /// CHECK-DAG: <<Arg:i\d+>> ParameterValue |
| 1179 | /// CHECK-DAG: <<Const0L:j\d+>> LongConstant 0 |
| 1180 | /// CHECK-DAG: Return [<<Const0L>>] |
| 1181 | |
| 1182 | /// CHECK-START: long Main.ShlLong0WithInt(int) constant_folding (after) |
| 1183 | /// CHECK-NOT: Shl |
| 1184 | |
| 1185 | public static long ShlLong0WithInt(int arg) { |
| 1186 | long long_zero = 0; |
| 1187 | return long_zero << arg; |
| 1188 | } |
| 1189 | |
David Brazdil | a06d66a | 2015-05-28 11:14:54 +0100 | [diff] [blame] | 1190 | /// CHECK-START: long Main.Shr0(int) constant_folding (before) |
| 1191 | /// CHECK-DAG: <<Arg:i\d+>> ParameterValue |
| 1192 | /// CHECK-DAG: <<Const0:j\d+>> LongConstant 0 |
| 1193 | /// CHECK-DAG: <<Shr:j\d+>> Shr [<<Const0>>,<<Arg>>] |
| 1194 | /// CHECK-DAG: Return [<<Shr>>] |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 1195 | |
David Brazdil | a06d66a | 2015-05-28 11:14:54 +0100 | [diff] [blame] | 1196 | /// CHECK-START: long Main.Shr0(int) constant_folding (after) |
| 1197 | /// CHECK-DAG: <<Arg:i\d+>> ParameterValue |
| 1198 | /// CHECK-DAG: <<Const0:j\d+>> LongConstant 0 |
David Brazdil | a06d66a | 2015-05-28 11:14:54 +0100 | [diff] [blame] | 1199 | /// CHECK-DAG: Return [<<Const0>>] |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 1200 | |
Roland Levillain | b65eb50 | 2015-07-23 12:11:42 +0100 | [diff] [blame] | 1201 | /// CHECK-START: long Main.Shr0(int) constant_folding (after) |
| 1202 | /// CHECK-NOT: Shr |
| 1203 | |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 1204 | public static long Shr0(int arg) { |
| 1205 | return (long)0 >> arg; |
| 1206 | } |
| 1207 | |
David Brazdil | a06d66a | 2015-05-28 11:14:54 +0100 | [diff] [blame] | 1208 | /// CHECK-START: long Main.SubSameLong(long) constant_folding (before) |
| 1209 | /// CHECK-DAG: <<Arg:j\d+>> ParameterValue |
| 1210 | /// CHECK-DAG: <<Sub:j\d+>> Sub [<<Arg>>,<<Arg>>] |
| 1211 | /// CHECK-DAG: Return [<<Sub>>] |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 1212 | |
David Brazdil | a06d66a | 2015-05-28 11:14:54 +0100 | [diff] [blame] | 1213 | /// CHECK-START: long Main.SubSameLong(long) constant_folding (after) |
| 1214 | /// CHECK-DAG: <<Arg:j\d+>> ParameterValue |
| 1215 | /// CHECK-DAG: <<Const0:j\d+>> LongConstant 0 |
David Brazdil | a06d66a | 2015-05-28 11:14:54 +0100 | [diff] [blame] | 1216 | /// CHECK-DAG: Return [<<Const0>>] |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 1217 | |
Roland Levillain | b65eb50 | 2015-07-23 12:11:42 +0100 | [diff] [blame] | 1218 | /// CHECK-START: long Main.SubSameLong(long) constant_folding (after) |
| 1219 | /// CHECK-NOT: Sub |
| 1220 | |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 1221 | public static long SubSameLong(long arg) { |
| 1222 | return arg - arg; |
| 1223 | } |
| 1224 | |
David Brazdil | a06d66a | 2015-05-28 11:14:54 +0100 | [diff] [blame] | 1225 | /// CHECK-START: int Main.UShr0(int) constant_folding (before) |
| 1226 | /// CHECK-DAG: <<Arg:i\d+>> ParameterValue |
| 1227 | /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0 |
| 1228 | /// CHECK-DAG: <<UShr:i\d+>> UShr [<<Const0>>,<<Arg>>] |
| 1229 | /// CHECK-DAG: Return [<<UShr>>] |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 1230 | |
David Brazdil | a06d66a | 2015-05-28 11:14:54 +0100 | [diff] [blame] | 1231 | /// CHECK-START: int Main.UShr0(int) constant_folding (after) |
| 1232 | /// CHECK-DAG: <<Arg:i\d+>> ParameterValue |
| 1233 | /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0 |
David Brazdil | a06d66a | 2015-05-28 11:14:54 +0100 | [diff] [blame] | 1234 | /// CHECK-DAG: Return [<<Const0>>] |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 1235 | |
Roland Levillain | b65eb50 | 2015-07-23 12:11:42 +0100 | [diff] [blame] | 1236 | /// CHECK-START: int Main.UShr0(int) constant_folding (after) |
| 1237 | /// CHECK-NOT: UShr |
| 1238 | |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 1239 | public static int UShr0(int arg) { |
| 1240 | return 0 >>> arg; |
| 1241 | } |
| 1242 | |
David Brazdil | a06d66a | 2015-05-28 11:14:54 +0100 | [diff] [blame] | 1243 | /// CHECK-START: int Main.XorSameInt(int) constant_folding (before) |
| 1244 | /// CHECK-DAG: <<Arg:i\d+>> ParameterValue |
| 1245 | /// CHECK-DAG: <<Xor:i\d+>> Xor [<<Arg>>,<<Arg>>] |
| 1246 | /// CHECK-DAG: Return [<<Xor>>] |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 1247 | |
David Brazdil | a06d66a | 2015-05-28 11:14:54 +0100 | [diff] [blame] | 1248 | /// CHECK-START: int Main.XorSameInt(int) constant_folding (after) |
| 1249 | /// CHECK-DAG: <<Arg:i\d+>> ParameterValue |
| 1250 | /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0 |
David Brazdil | a06d66a | 2015-05-28 11:14:54 +0100 | [diff] [blame] | 1251 | /// CHECK-DAG: Return [<<Const0>>] |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 1252 | |
Roland Levillain | b65eb50 | 2015-07-23 12:11:42 +0100 | [diff] [blame] | 1253 | /// CHECK-START: int Main.XorSameInt(int) constant_folding (after) |
| 1254 | /// CHECK-NOT: Xor |
| 1255 | |
Alexandre Rames | b2fd7bc | 2015-03-11 16:48:16 +0000 | [diff] [blame] | 1256 | public static int XorSameInt(int arg) { |
| 1257 | return arg ^ arg; |
| 1258 | } |
| 1259 | |
David Brazdil | a06d66a | 2015-05-28 11:14:54 +0100 | [diff] [blame] | 1260 | /// CHECK-START: boolean Main.CmpFloatGreaterThanNaN(float) constant_folding (before) |
| 1261 | /// CHECK-DAG: <<Arg:f\d+>> ParameterValue |
| 1262 | /// CHECK-DAG: <<ConstNan:f\d+>> FloatConstant nan |
| 1263 | /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0 |
| 1264 | /// CHECK-DAG: IntConstant 1 |
| 1265 | /// CHECK-DAG: <<Cmp:i\d+>> Compare [<<Arg>>,<<ConstNan>>] |
| 1266 | /// CHECK-DAG: <<Le:z\d+>> LessThanOrEqual [<<Cmp>>,<<Const0>>] |
| 1267 | /// CHECK-DAG: If [<<Le>>] |
Roland Levillain | 3b55ebb | 2015-05-08 13:13:19 +0100 | [diff] [blame] | 1268 | |
David Brazdil | a06d66a | 2015-05-28 11:14:54 +0100 | [diff] [blame] | 1269 | /// CHECK-START: boolean Main.CmpFloatGreaterThanNaN(float) constant_folding (after) |
| 1270 | /// CHECK-DAG: ParameterValue |
| 1271 | /// CHECK-DAG: FloatConstant nan |
| 1272 | /// CHECK-DAG: IntConstant 0 |
| 1273 | /// CHECK-DAG: <<Const1:i\d+>> IntConstant 1 |
| 1274 | /// CHECK-DAG: If [<<Const1>>] |
Roland Levillain | 3b55ebb | 2015-05-08 13:13:19 +0100 | [diff] [blame] | 1275 | |
David Brazdil | a06d66a | 2015-05-28 11:14:54 +0100 | [diff] [blame] | 1276 | /// CHECK-START: boolean Main.CmpFloatGreaterThanNaN(float) constant_folding (after) |
| 1277 | /// CHECK-NOT: Compare |
| 1278 | /// CHECK-NOT: LessThanOrEqual |
Roland Levillain | 3b55ebb | 2015-05-08 13:13:19 +0100 | [diff] [blame] | 1279 | |
| 1280 | public static boolean CmpFloatGreaterThanNaN(float arg) { |
| 1281 | return arg > Float.NaN; |
| 1282 | } |
| 1283 | |
David Brazdil | a06d66a | 2015-05-28 11:14:54 +0100 | [diff] [blame] | 1284 | /// CHECK-START: boolean Main.CmpDoubleLessThanNaN(double) constant_folding (before) |
| 1285 | /// CHECK-DAG: <<Arg:d\d+>> ParameterValue |
| 1286 | /// CHECK-DAG: <<ConstNan:d\d+>> DoubleConstant nan |
| 1287 | /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0 |
| 1288 | /// CHECK-DAG: IntConstant 1 |
| 1289 | /// CHECK-DAG: <<Cmp:i\d+>> Compare [<<Arg>>,<<ConstNan>>] |
| 1290 | /// CHECK-DAG: <<Ge:z\d+>> GreaterThanOrEqual [<<Cmp>>,<<Const0>>] |
| 1291 | /// CHECK-DAG: If [<<Ge>>] |
Roland Levillain | 3b55ebb | 2015-05-08 13:13:19 +0100 | [diff] [blame] | 1292 | |
David Brazdil | a06d66a | 2015-05-28 11:14:54 +0100 | [diff] [blame] | 1293 | /// CHECK-START: boolean Main.CmpDoubleLessThanNaN(double) constant_folding (after) |
| 1294 | /// CHECK-DAG: ParameterValue |
| 1295 | /// CHECK-DAG: DoubleConstant nan |
| 1296 | /// CHECK-DAG: IntConstant 0 |
| 1297 | /// CHECK-DAG: <<Const1:i\d+>> IntConstant 1 |
| 1298 | /// CHECK-DAG: If [<<Const1>>] |
Roland Levillain | 3b55ebb | 2015-05-08 13:13:19 +0100 | [diff] [blame] | 1299 | |
David Brazdil | a06d66a | 2015-05-28 11:14:54 +0100 | [diff] [blame] | 1300 | /// CHECK-START: boolean Main.CmpDoubleLessThanNaN(double) constant_folding (after) |
| 1301 | /// CHECK-NOT: Compare |
| 1302 | /// CHECK-NOT: GreaterThanOrEqual |
Roland Levillain | 3b55ebb | 2015-05-08 13:13:19 +0100 | [diff] [blame] | 1303 | |
| 1304 | public static boolean CmpDoubleLessThanNaN(double arg) { |
| 1305 | return arg < Double.NaN; |
| 1306 | } |
| 1307 | |
Roland Levillain | b65eb50 | 2015-07-23 12:11:42 +0100 | [diff] [blame] | 1308 | |
| 1309 | /** |
| 1310 | * Exercise constant folding on type conversions. |
| 1311 | */ |
| 1312 | |
David Brazdil | a06d66a | 2015-05-28 11:14:54 +0100 | [diff] [blame] | 1313 | /// CHECK-START: int Main.ReturnInt33() constant_folding (before) |
| 1314 | /// CHECK-DAG: <<Const33:j\d+>> LongConstant 33 |
| 1315 | /// CHECK-DAG: <<Convert:i\d+>> TypeConversion [<<Const33>>] |
| 1316 | /// CHECK-DAG: Return [<<Convert>>] |
Mark Mendell | e82549b | 2015-05-06 10:55:34 -0400 | [diff] [blame] | 1317 | |
David Brazdil | a06d66a | 2015-05-28 11:14:54 +0100 | [diff] [blame] | 1318 | /// CHECK-START: int Main.ReturnInt33() constant_folding (after) |
| 1319 | /// CHECK-DAG: <<Const33:i\d+>> IntConstant 33 |
| 1320 | /// CHECK-DAG: Return [<<Const33>>] |
Mark Mendell | e82549b | 2015-05-06 10:55:34 -0400 | [diff] [blame] | 1321 | |
Roland Levillain | b65eb50 | 2015-07-23 12:11:42 +0100 | [diff] [blame] | 1322 | /// CHECK-START: int Main.ReturnInt33() constant_folding (after) |
| 1323 | /// CHECK-NOT: TypeConversion |
| 1324 | |
Mark Mendell | e82549b | 2015-05-06 10:55:34 -0400 | [diff] [blame] | 1325 | public static int ReturnInt33() { |
| 1326 | long imm = 33L; |
| 1327 | return (int) imm; |
| 1328 | } |
| 1329 | |
David Brazdil | a06d66a | 2015-05-28 11:14:54 +0100 | [diff] [blame] | 1330 | /// CHECK-START: int Main.ReturnIntMax() constant_folding (before) |
| 1331 | /// CHECK-DAG: <<ConstMax:f\d+>> FloatConstant 1e+34 |
| 1332 | /// CHECK-DAG: <<Convert:i\d+>> TypeConversion [<<ConstMax>>] |
| 1333 | /// CHECK-DAG: Return [<<Convert>>] |
Mark Mendell | e82549b | 2015-05-06 10:55:34 -0400 | [diff] [blame] | 1334 | |
David Brazdil | a06d66a | 2015-05-28 11:14:54 +0100 | [diff] [blame] | 1335 | /// CHECK-START: int Main.ReturnIntMax() constant_folding (after) |
| 1336 | /// CHECK-DAG: <<ConstMax:i\d+>> IntConstant 2147483647 |
| 1337 | /// CHECK-DAG: Return [<<ConstMax>>] |
Mark Mendell | e82549b | 2015-05-06 10:55:34 -0400 | [diff] [blame] | 1338 | |
Roland Levillain | b65eb50 | 2015-07-23 12:11:42 +0100 | [diff] [blame] | 1339 | /// CHECK-START: int Main.ReturnIntMax() constant_folding (after) |
| 1340 | /// CHECK-NOT: TypeConversion |
| 1341 | |
Mark Mendell | e82549b | 2015-05-06 10:55:34 -0400 | [diff] [blame] | 1342 | public static int ReturnIntMax() { |
| 1343 | float imm = 1.0e34f; |
| 1344 | return (int) imm; |
| 1345 | } |
| 1346 | |
David Brazdil | a06d66a | 2015-05-28 11:14:54 +0100 | [diff] [blame] | 1347 | /// CHECK-START: int Main.ReturnInt0() constant_folding (before) |
| 1348 | /// CHECK-DAG: <<ConstNaN:d\d+>> DoubleConstant nan |
| 1349 | /// CHECK-DAG: <<Convert:i\d+>> TypeConversion [<<ConstNaN>>] |
| 1350 | /// CHECK-DAG: Return [<<Convert>>] |
Mark Mendell | e82549b | 2015-05-06 10:55:34 -0400 | [diff] [blame] | 1351 | |
David Brazdil | a06d66a | 2015-05-28 11:14:54 +0100 | [diff] [blame] | 1352 | /// CHECK-START: int Main.ReturnInt0() constant_folding (after) |
| 1353 | /// CHECK-DAG: <<Const0:i\d+>> IntConstant 0 |
| 1354 | /// CHECK-DAG: Return [<<Const0>>] |
Mark Mendell | e82549b | 2015-05-06 10:55:34 -0400 | [diff] [blame] | 1355 | |
Roland Levillain | b65eb50 | 2015-07-23 12:11:42 +0100 | [diff] [blame] | 1356 | /// CHECK-START: int Main.ReturnInt0() constant_folding (after) |
| 1357 | /// CHECK-NOT: TypeConversion |
| 1358 | |
Mark Mendell | e82549b | 2015-05-06 10:55:34 -0400 | [diff] [blame] | 1359 | public static int ReturnInt0() { |
| 1360 | double imm = Double.NaN; |
| 1361 | return (int) imm; |
| 1362 | } |
| 1363 | |
David Brazdil | a06d66a | 2015-05-28 11:14:54 +0100 | [diff] [blame] | 1364 | /// CHECK-START: long Main.ReturnLong33() constant_folding (before) |
| 1365 | /// CHECK-DAG: <<Const33:i\d+>> IntConstant 33 |
| 1366 | /// CHECK-DAG: <<Convert:j\d+>> TypeConversion [<<Const33>>] |
| 1367 | /// CHECK-DAG: Return [<<Convert>>] |
Mark Mendell | e82549b | 2015-05-06 10:55:34 -0400 | [diff] [blame] | 1368 | |
David Brazdil | a06d66a | 2015-05-28 11:14:54 +0100 | [diff] [blame] | 1369 | /// CHECK-START: long Main.ReturnLong33() constant_folding (after) |
| 1370 | /// CHECK-DAG: <<Const33:j\d+>> LongConstant 33 |
| 1371 | /// CHECK-DAG: Return [<<Const33>>] |
Mark Mendell | e82549b | 2015-05-06 10:55:34 -0400 | [diff] [blame] | 1372 | |
Roland Levillain | b65eb50 | 2015-07-23 12:11:42 +0100 | [diff] [blame] | 1373 | /// CHECK-START: long Main.ReturnLong33() constant_folding (after) |
| 1374 | /// CHECK-NOT: TypeConversion |
| 1375 | |
Mark Mendell | e82549b | 2015-05-06 10:55:34 -0400 | [diff] [blame] | 1376 | public static long ReturnLong33() { |
| 1377 | int imm = 33; |
| 1378 | return (long) imm; |
| 1379 | } |
| 1380 | |
David Brazdil | a06d66a | 2015-05-28 11:14:54 +0100 | [diff] [blame] | 1381 | /// CHECK-START: long Main.ReturnLong34() constant_folding (before) |
| 1382 | /// CHECK-DAG: <<Const34:f\d+>> FloatConstant 34 |
| 1383 | /// CHECK-DAG: <<Convert:j\d+>> TypeConversion [<<Const34>>] |
| 1384 | /// CHECK-DAG: Return [<<Convert>>] |
Mark Mendell | e82549b | 2015-05-06 10:55:34 -0400 | [diff] [blame] | 1385 | |
David Brazdil | a06d66a | 2015-05-28 11:14:54 +0100 | [diff] [blame] | 1386 | /// CHECK-START: long Main.ReturnLong34() constant_folding (after) |
| 1387 | /// CHECK-DAG: <<Const34:j\d+>> LongConstant 34 |
| 1388 | /// CHECK-DAG: Return [<<Const34>>] |
Mark Mendell | e82549b | 2015-05-06 10:55:34 -0400 | [diff] [blame] | 1389 | |
Roland Levillain | b65eb50 | 2015-07-23 12:11:42 +0100 | [diff] [blame] | 1390 | /// CHECK-START: long Main.ReturnLong34() constant_folding (after) |
| 1391 | /// CHECK-NOT: TypeConversion |
| 1392 | |
Mark Mendell | e82549b | 2015-05-06 10:55:34 -0400 | [diff] [blame] | 1393 | public static long ReturnLong34() { |
| 1394 | float imm = 34.0f; |
| 1395 | return (long) imm; |
| 1396 | } |
| 1397 | |
David Brazdil | a06d66a | 2015-05-28 11:14:54 +0100 | [diff] [blame] | 1398 | /// CHECK-START: long Main.ReturnLong0() constant_folding (before) |
| 1399 | /// CHECK-DAG: <<ConstNaN:d\d+>> DoubleConstant nan |
| 1400 | /// CHECK-DAG: <<Convert:j\d+>> TypeConversion [<<ConstNaN>>] |
| 1401 | /// CHECK-DAG: Return [<<Convert>>] |
Mark Mendell | e82549b | 2015-05-06 10:55:34 -0400 | [diff] [blame] | 1402 | |
David Brazdil | a06d66a | 2015-05-28 11:14:54 +0100 | [diff] [blame] | 1403 | /// CHECK-START: long Main.ReturnLong0() constant_folding (after) |
| 1404 | /// CHECK-DAG: <<Const0:j\d+>> LongConstant 0 |
| 1405 | /// CHECK-DAG: Return [<<Const0>>] |
Mark Mendell | e82549b | 2015-05-06 10:55:34 -0400 | [diff] [blame] | 1406 | |
Roland Levillain | b65eb50 | 2015-07-23 12:11:42 +0100 | [diff] [blame] | 1407 | /// CHECK-START: long Main.ReturnLong0() constant_folding (after) |
| 1408 | /// CHECK-NOT: TypeConversion |
| 1409 | |
Mark Mendell | e82549b | 2015-05-06 10:55:34 -0400 | [diff] [blame] | 1410 | public static long ReturnLong0() { |
| 1411 | double imm = -Double.NaN; |
| 1412 | return (long) imm; |
| 1413 | } |
| 1414 | |
David Brazdil | a06d66a | 2015-05-28 11:14:54 +0100 | [diff] [blame] | 1415 | /// CHECK-START: float Main.ReturnFloat33() constant_folding (before) |
| 1416 | /// CHECK-DAG: <<Const33:i\d+>> IntConstant 33 |
| 1417 | /// CHECK-DAG: <<Convert:f\d+>> TypeConversion [<<Const33>>] |
| 1418 | /// CHECK-DAG: Return [<<Convert>>] |
Mark Mendell | e82549b | 2015-05-06 10:55:34 -0400 | [diff] [blame] | 1419 | |
David Brazdil | a06d66a | 2015-05-28 11:14:54 +0100 | [diff] [blame] | 1420 | /// CHECK-START: float Main.ReturnFloat33() constant_folding (after) |
| 1421 | /// CHECK-DAG: <<Const33:f\d+>> FloatConstant 33 |
| 1422 | /// CHECK-DAG: Return [<<Const33>>] |
Mark Mendell | e82549b | 2015-05-06 10:55:34 -0400 | [diff] [blame] | 1423 | |
Roland Levillain | b65eb50 | 2015-07-23 12:11:42 +0100 | [diff] [blame] | 1424 | /// CHECK-START: float Main.ReturnFloat33() constant_folding (after) |
| 1425 | /// CHECK-NOT: TypeConversion |
| 1426 | |
Mark Mendell | e82549b | 2015-05-06 10:55:34 -0400 | [diff] [blame] | 1427 | public static float ReturnFloat33() { |
| 1428 | int imm = 33; |
| 1429 | return (float) imm; |
| 1430 | } |
| 1431 | |
David Brazdil | a06d66a | 2015-05-28 11:14:54 +0100 | [diff] [blame] | 1432 | /// CHECK-START: float Main.ReturnFloat34() constant_folding (before) |
| 1433 | /// CHECK-DAG: <<Const34:j\d+>> LongConstant 34 |
| 1434 | /// CHECK-DAG: <<Convert:f\d+>> TypeConversion [<<Const34>>] |
| 1435 | /// CHECK-DAG: Return [<<Convert>>] |
Mark Mendell | e82549b | 2015-05-06 10:55:34 -0400 | [diff] [blame] | 1436 | |
David Brazdil | a06d66a | 2015-05-28 11:14:54 +0100 | [diff] [blame] | 1437 | /// CHECK-START: float Main.ReturnFloat34() constant_folding (after) |
| 1438 | /// CHECK-DAG: <<Const34:f\d+>> FloatConstant 34 |
| 1439 | /// CHECK-DAG: Return [<<Const34>>] |
Mark Mendell | e82549b | 2015-05-06 10:55:34 -0400 | [diff] [blame] | 1440 | |
Roland Levillain | b65eb50 | 2015-07-23 12:11:42 +0100 | [diff] [blame] | 1441 | /// CHECK-START: float Main.ReturnFloat34() constant_folding (after) |
| 1442 | /// CHECK-NOT: TypeConversion |
| 1443 | |
Mark Mendell | e82549b | 2015-05-06 10:55:34 -0400 | [diff] [blame] | 1444 | public static float ReturnFloat34() { |
| 1445 | long imm = 34L; |
| 1446 | return (float) imm; |
| 1447 | } |
| 1448 | |
David Brazdil | a06d66a | 2015-05-28 11:14:54 +0100 | [diff] [blame] | 1449 | /// CHECK-START: float Main.ReturnFloat99P25() constant_folding (before) |
| 1450 | /// CHECK-DAG: <<Const:d\d+>> DoubleConstant 99.25 |
| 1451 | /// CHECK-DAG: <<Convert:f\d+>> TypeConversion [<<Const>>] |
| 1452 | /// CHECK-DAG: Return [<<Convert>>] |
Mark Mendell | e82549b | 2015-05-06 10:55:34 -0400 | [diff] [blame] | 1453 | |
David Brazdil | a06d66a | 2015-05-28 11:14:54 +0100 | [diff] [blame] | 1454 | /// CHECK-START: float Main.ReturnFloat99P25() constant_folding (after) |
| 1455 | /// CHECK-DAG: <<Const:f\d+>> FloatConstant 99.25 |
| 1456 | /// CHECK-DAG: Return [<<Const>>] |
Mark Mendell | e82549b | 2015-05-06 10:55:34 -0400 | [diff] [blame] | 1457 | |
Roland Levillain | b65eb50 | 2015-07-23 12:11:42 +0100 | [diff] [blame] | 1458 | /// CHECK-START: float Main.ReturnFloat99P25() constant_folding (after) |
| 1459 | /// CHECK-NOT: TypeConversion |
| 1460 | |
Mark Mendell | e82549b | 2015-05-06 10:55:34 -0400 | [diff] [blame] | 1461 | public static float ReturnFloat99P25() { |
| 1462 | double imm = 99.25; |
| 1463 | return (float) imm; |
| 1464 | } |
| 1465 | |
David Brazdil | a06d66a | 2015-05-28 11:14:54 +0100 | [diff] [blame] | 1466 | /// CHECK-START: double Main.ReturnDouble33() constant_folding (before) |
| 1467 | /// CHECK-DAG: <<Const33:i\d+>> IntConstant 33 |
| 1468 | /// CHECK-DAG: <<Convert:d\d+>> TypeConversion [<<Const33>>] |
| 1469 | /// CHECK-DAG: Return [<<Convert>>] |
Mark Mendell | e82549b | 2015-05-06 10:55:34 -0400 | [diff] [blame] | 1470 | |
David Brazdil | a06d66a | 2015-05-28 11:14:54 +0100 | [diff] [blame] | 1471 | /// CHECK-START: double Main.ReturnDouble33() constant_folding (after) |
| 1472 | /// CHECK-DAG: <<Const33:d\d+>> DoubleConstant 33 |
| 1473 | /// CHECK-DAG: Return [<<Const33>>] |
Mark Mendell | e82549b | 2015-05-06 10:55:34 -0400 | [diff] [blame] | 1474 | |
| 1475 | public static double ReturnDouble33() { |
| 1476 | int imm = 33; |
| 1477 | return (double) imm; |
| 1478 | } |
| 1479 | |
David Brazdil | a06d66a | 2015-05-28 11:14:54 +0100 | [diff] [blame] | 1480 | /// CHECK-START: double Main.ReturnDouble34() constant_folding (before) |
| 1481 | /// CHECK-DAG: <<Const34:j\d+>> LongConstant 34 |
| 1482 | /// CHECK-DAG: <<Convert:d\d+>> TypeConversion [<<Const34>>] |
| 1483 | /// CHECK-DAG: Return [<<Convert>>] |
Mark Mendell | e82549b | 2015-05-06 10:55:34 -0400 | [diff] [blame] | 1484 | |
David Brazdil | a06d66a | 2015-05-28 11:14:54 +0100 | [diff] [blame] | 1485 | /// CHECK-START: double Main.ReturnDouble34() constant_folding (after) |
| 1486 | /// CHECK-DAG: <<Const34:d\d+>> DoubleConstant 34 |
| 1487 | /// CHECK-DAG: Return [<<Const34>>] |
Mark Mendell | e82549b | 2015-05-06 10:55:34 -0400 | [diff] [blame] | 1488 | |
Roland Levillain | b65eb50 | 2015-07-23 12:11:42 +0100 | [diff] [blame] | 1489 | /// CHECK-START: double Main.ReturnDouble34() constant_folding (after) |
| 1490 | /// CHECK-NOT: TypeConversion |
| 1491 | |
Mark Mendell | e82549b | 2015-05-06 10:55:34 -0400 | [diff] [blame] | 1492 | public static double ReturnDouble34() { |
| 1493 | long imm = 34L; |
| 1494 | return (double) imm; |
| 1495 | } |
| 1496 | |
David Brazdil | a06d66a | 2015-05-28 11:14:54 +0100 | [diff] [blame] | 1497 | /// CHECK-START: double Main.ReturnDouble99P25() constant_folding (before) |
| 1498 | /// CHECK-DAG: <<Const:f\d+>> FloatConstant 99.25 |
| 1499 | /// CHECK-DAG: <<Convert:d\d+>> TypeConversion [<<Const>>] |
| 1500 | /// CHECK-DAG: Return [<<Convert>>] |
Mark Mendell | e82549b | 2015-05-06 10:55:34 -0400 | [diff] [blame] | 1501 | |
David Brazdil | a06d66a | 2015-05-28 11:14:54 +0100 | [diff] [blame] | 1502 | /// CHECK-START: double Main.ReturnDouble99P25() constant_folding (after) |
| 1503 | /// CHECK-DAG: <<Const:d\d+>> DoubleConstant 99.25 |
| 1504 | /// CHECK-DAG: Return [<<Const>>] |
Mark Mendell | e82549b | 2015-05-06 10:55:34 -0400 | [diff] [blame] | 1505 | |
Roland Levillain | b65eb50 | 2015-07-23 12:11:42 +0100 | [diff] [blame] | 1506 | /// CHECK-START: double Main.ReturnDouble99P25() constant_folding (after) |
| 1507 | /// CHECK-NOT: TypeConversion |
| 1508 | |
Mark Mendell | e82549b | 2015-05-06 10:55:34 -0400 | [diff] [blame] | 1509 | public static double ReturnDouble99P25() { |
| 1510 | float imm = 99.25f; |
| 1511 | return (double) imm; |
| 1512 | } |
| 1513 | |
Roland Levillain | b65eb50 | 2015-07-23 12:11:42 +0100 | [diff] [blame] | 1514 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame^] | 1515 | public static void main(String[] args) throws Exception { |
Roland Levillain | b65eb50 | 2015-07-23 12:11:42 +0100 | [diff] [blame] | 1516 | assertIntEquals(-42, IntNegation()); |
Roland Levillain | c90bc7c | 2014-12-11 12:14:33 +0000 | [diff] [blame] | 1517 | assertLongEquals(-42L, LongNegation()); |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame^] | 1518 | assertFloatEquals(-42F, FloatNegation()); |
| 1519 | assertDoubleEquals(-42D, DoubleNegation()); |
Roland Levillain | b65eb50 | 2015-07-23 12:11:42 +0100 | [diff] [blame] | 1520 | |
| 1521 | assertIntEquals(3, IntAddition1()); |
| 1522 | assertIntEquals(14, IntAddition2()); |
| 1523 | assertLongEquals(3L, LongAddition()); |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame^] | 1524 | assertFloatEquals(3F, FloatAddition()); |
| 1525 | assertDoubleEquals(3D, DoubleAddition()); |
Roland Levillain | b65eb50 | 2015-07-23 12:11:42 +0100 | [diff] [blame] | 1526 | |
| 1527 | assertIntEquals(4, IntSubtraction()); |
| 1528 | assertLongEquals(4L, LongSubtraction()); |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame^] | 1529 | assertFloatEquals(4F, FloatSubtraction()); |
| 1530 | assertDoubleEquals(4D, DoubleSubtraction()); |
Roland Levillain | b65eb50 | 2015-07-23 12:11:42 +0100 | [diff] [blame] | 1531 | |
Roland Levillain | f7746ad | 2015-07-22 14:12:01 +0100 | [diff] [blame] | 1532 | assertIntEquals(21, IntMultiplication()); |
| 1533 | assertLongEquals(21L, LongMultiplication()); |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame^] | 1534 | assertFloatEquals(21F, FloatMultiplication()); |
| 1535 | assertDoubleEquals(21D, DoubleMultiplication()); |
Roland Levillain | f7746ad | 2015-07-22 14:12:01 +0100 | [diff] [blame] | 1536 | |
| 1537 | assertIntEquals(2, IntDivision()); |
| 1538 | assertLongEquals(2L, LongDivision()); |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame^] | 1539 | assertFloatEquals(3.2F, FloatDivision()); |
| 1540 | assertDoubleEquals(3.2D, DoubleDivision()); |
Roland Levillain | f7746ad | 2015-07-22 14:12:01 +0100 | [diff] [blame] | 1541 | |
| 1542 | assertIntEquals(2, IntRemainder()); |
| 1543 | assertLongEquals(2L, LongRemainder()); |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame^] | 1544 | assertFloatEquals(0.5F, FloatRemainder()); |
| 1545 | assertDoubleEquals(0.5D, DoubleRemainder()); |
Roland Levillain | f7746ad | 2015-07-22 14:12:01 +0100 | [diff] [blame] | 1546 | |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 1547 | assertIntEquals(4, ShlIntLong()); |
| 1548 | assertLongEquals(12L, ShlLongInt()); |
| 1549 | |
| 1550 | assertIntEquals(1, ShrIntLong()); |
| 1551 | assertLongEquals(2L, ShrLongInt()); |
| 1552 | |
| 1553 | assertIntEquals(1073741822, UShrIntLong()); |
| 1554 | assertLongEquals(4611686018427387901L, UShrLongInt()); |
| 1555 | |
| 1556 | assertLongEquals(2, AndIntLong()); |
| 1557 | assertLongEquals(2, AndLongInt()); |
| 1558 | |
| 1559 | assertLongEquals(11, OrIntLong()); |
| 1560 | assertLongEquals(11, OrLongInt()); |
| 1561 | |
| 1562 | assertLongEquals(9, XorIntLong()); |
| 1563 | assertLongEquals(9, XorLongInt()); |
| 1564 | |
Roland Levillain | b65eb50 | 2015-07-23 12:11:42 +0100 | [diff] [blame] | 1565 | assertIntEquals(5, StaticCondition()); |
Vladimir Marko | 9e23df5 | 2015-11-10 17:14:35 +0000 | [diff] [blame] | 1566 | assertIntEquals(5, StaticConditionNulls()); |
Roland Levillain | b65eb50 | 2015-07-23 12:11:42 +0100 | [diff] [blame] | 1567 | |
| 1568 | assertIntEquals(7, JumpsAndConditionals(true)); |
| 1569 | assertIntEquals(3, JumpsAndConditionals(false)); |
| 1570 | |
Roland Levillain | 3b55ebb | 2015-05-08 13:13:19 +0100 | [diff] [blame] | 1571 | int arbitrary = 123456; // Value chosen arbitrarily. |
Roland Levillain | b65eb50 | 2015-07-23 12:11:42 +0100 | [diff] [blame] | 1572 | |
| 1573 | assertIntEquals(0, And0(arbitrary)); |
| 1574 | assertLongEquals(0, Mul0(arbitrary)); |
| 1575 | assertIntEquals(-1, OrAllOnes(arbitrary)); |
| 1576 | assertLongEquals(0, Rem0(arbitrary)); |
| 1577 | assertIntEquals(0, Rem1(arbitrary)); |
| 1578 | assertLongEquals(0, RemN1(arbitrary)); |
| 1579 | assertIntEquals(0, Shl0(arbitrary)); |
Roland Levillain | 9867bc7 | 2015-08-05 10:21:34 +0100 | [diff] [blame] | 1580 | assertLongEquals(0, ShlLong0WithInt(arbitrary)); |
Roland Levillain | b65eb50 | 2015-07-23 12:11:42 +0100 | [diff] [blame] | 1581 | assertLongEquals(0, Shr0(arbitrary)); |
| 1582 | assertLongEquals(0, SubSameLong(arbitrary)); |
| 1583 | assertIntEquals(0, UShr0(arbitrary)); |
| 1584 | assertIntEquals(0, XorSameInt(arbitrary)); |
| 1585 | |
Roland Levillain | 3b55ebb | 2015-05-08 13:13:19 +0100 | [diff] [blame] | 1586 | assertFalse(CmpFloatGreaterThanNaN(arbitrary)); |
| 1587 | assertFalse(CmpDoubleLessThanNaN(arbitrary)); |
Roland Levillain | b65eb50 | 2015-07-23 12:11:42 +0100 | [diff] [blame] | 1588 | |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame^] | 1589 | Main main = new Main(); |
| 1590 | assertIntEquals(1, main.smaliCmpLongConstants()); |
| 1591 | assertIntEquals(-1, main.smaliCmpGtFloatConstants()); |
| 1592 | assertIntEquals(-1, main.smaliCmpLtFloatConstants()); |
| 1593 | assertIntEquals(-1, main.smaliCmpGtDoubleConstants()); |
| 1594 | assertIntEquals(-1, main.smaliCmpLtDoubleConstants()); |
| 1595 | |
| 1596 | assertIntEquals(0, main.smaliCmpLongSameConstant()); |
| 1597 | assertIntEquals(0, main.smaliCmpGtFloatSameConstant()); |
| 1598 | assertIntEquals(0, main.smaliCmpLtFloatSameConstant()); |
| 1599 | assertIntEquals(0, main.smaliCmpGtDoubleSameConstant()); |
| 1600 | assertIntEquals(0, main.smaliCmpLtDoubleSameConstant()); |
| 1601 | |
| 1602 | assertIntEquals(1, main.smaliCmpGtFloatConstantWithNaN()); |
| 1603 | assertIntEquals(-1, main.smaliCmpLtFloatConstantWithNaN()); |
| 1604 | assertIntEquals(1, main.smaliCmpGtDoubleConstantWithNaN()); |
| 1605 | assertIntEquals(-1, main.smaliCmpLtDoubleConstantWithNaN()); |
| 1606 | |
Roland Levillain | b65eb50 | 2015-07-23 12:11:42 +0100 | [diff] [blame] | 1607 | assertIntEquals(33, ReturnInt33()); |
| 1608 | assertIntEquals(2147483647, ReturnIntMax()); |
| 1609 | assertIntEquals(0, ReturnInt0()); |
| 1610 | |
| 1611 | assertLongEquals(33, ReturnLong33()); |
| 1612 | assertLongEquals(34, ReturnLong34()); |
| 1613 | assertLongEquals(0, ReturnLong0()); |
| 1614 | |
| 1615 | assertFloatEquals(33, ReturnFloat33()); |
| 1616 | assertFloatEquals(34, ReturnFloat34()); |
| 1617 | assertFloatEquals(99.25f, ReturnFloat99P25()); |
| 1618 | |
| 1619 | assertDoubleEquals(33, ReturnDouble33()); |
| 1620 | assertDoubleEquals(34, ReturnDouble34()); |
| 1621 | assertDoubleEquals(99.25, ReturnDouble99P25()); |
David Brazdil | 4846d13 | 2015-01-15 19:07:08 +0000 | [diff] [blame] | 1622 | } |
Roland Levillain | 31dd3d6 | 2016-02-16 12:21:02 +0000 | [diff] [blame^] | 1623 | |
| 1624 | Main() throws ClassNotFoundException { |
| 1625 | testCmp = Class.forName("TestCmp"); |
| 1626 | } |
| 1627 | |
| 1628 | private Class<?> testCmp; |
David Brazdil | ee690a3 | 2014-12-01 17:04:16 +0000 | [diff] [blame] | 1629 | } |