1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640
|
/*
* Copyright (c) 2021, 2025, Red Hat, Inc. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
package compiler.c2.irTests;
import compiler.lib.ir_framework.*;
import jdk.test.lib.Utils;
import java.util.Random;
import java.util.Objects;
/*
* @test
* @bug 8277850 8278949 8285793 8346664
* @summary C2: optimize mask checks in counted loops
* @library /test/lib /
* @run driver compiler.c2.irTests.TestShiftAndMask
*/
public class TestShiftAndMask {
private static final Random RANDOM = Utils.getRandomInstance();
public static void main(String[] args) {
TestFramework.run();
}
// any X << INT_MASK_WIDTH is zero under any INT_MASK
static final int INT_MASK_WIDTH = 1 + RANDOM.nextInt(30);
static final int INT_MAX_MASK = (1 << INT_MASK_WIDTH) - 1;
static final int INT_MASK = 1 + RANDOM.nextInt(INT_MAX_MASK);
static final int INT_MASK2 = 1 + RANDOM.nextInt(INT_MAX_MASK);
static final int INT_ZERO_CONST = RANDOM.nextInt() << INT_MASK_WIDTH;
static final int INT_RANDOM_CONST = RANDOM.nextInt();
static final int INT_RANDOM_SHIFT = RANDOM.nextInt();
static final int INT_RANDOM_MASK = RANDOM.nextInt();
// any X << LONG_MASK_WIDTH is zero under any LONG_MASK
static final int LONG_MASK_WIDTH = 1 + RANDOM.nextInt(62);
static final long LONG_MAX_MASK = (1L << LONG_MASK_WIDTH) - 1;
static final long LONG_MASK = 1 + RANDOM.nextLong(LONG_MAX_MASK);
static final long LONG_MASK2 = 1 + RANDOM.nextLong(LONG_MAX_MASK);
static final long LONG_ZERO_CONST = RANDOM.nextLong() << LONG_MASK_WIDTH;
static final long LONG_RANDOM_CONST = RANDOM.nextLong();
static final long LONG_RANDOM_SHIFT = RANDOM.nextLong();
static final long LONG_RANDOM_MASK = RANDOM.nextLong();
@Test
public static int intSumAndMask(int i, int j) {
return (j + i << INT_RANDOM_SHIFT + INT_RANDOM_CONST) & INT_RANDOM_MASK;
}
@Run(test = { "intSumAndMask" })
public static void checkIntSumAndMask() {
int j = RANDOM.nextInt();
int i = RANDOM.nextInt();
int res = intSumAndMask(i, j);
if (res != ((j + i << INT_RANDOM_SHIFT + INT_RANDOM_CONST) & INT_RANDOM_MASK)) {
throw new RuntimeException("incorrect result: " + res);
}
}
@Test
@Arguments(values = Argument.RANDOM_EACH)
@IR(failOn = { IRNode.AND_I, IRNode.LSHIFT_I })
public static int shiftMaskInt(int i) {
return (i << INT_MASK_WIDTH) & INT_MASK; // transformed to: return 0;
}
@Check(test = "shiftMaskInt")
public static void checkShiftMaskInt(int res) {
if (res != 0) {
throw new RuntimeException("incorrect result: " + res);
}
}
@Test
public static long longSumAndMask(long i, long j) {
return (j + i << LONG_RANDOM_SHIFT + LONG_RANDOM_CONST) & LONG_RANDOM_MASK;
}
@Run(test = { "longSumAndMask" })
public static void checkLongSumAndMask() {
long j = RANDOM.nextLong();
long i = RANDOM.nextLong();
long res = longSumAndMask(i, j);
if (res != ((j + i << LONG_RANDOM_SHIFT + LONG_RANDOM_CONST) & LONG_RANDOM_MASK)) {
throw new RuntimeException("incorrect result: " + res);
}
}
@Test
@Arguments(values = Argument.RANDOM_EACH)
@IR(failOn = { IRNode.AND_L, IRNode.LSHIFT_L })
public static long shiftMaskLong(long i) {
return (i << LONG_MASK_WIDTH) & LONG_MASK; // transformed to: return 0;
}
@Check(test = "shiftMaskLong")
public static void checkShiftMaskLong(long res) {
if (res != 0) {
throw new RuntimeException("incorrect result: " + res);
}
}
static volatile int barrier;
@Test
@Arguments(values = {Argument.RANDOM_EACH, Argument.BOOLEAN_TOGGLE_FIRST_TRUE})
@IR(failOn = { IRNode.AND_I, IRNode.LSHIFT_I })
public static int shiftNonConstMaskInt(int i, boolean flag) {
int mask;
if (flag) {
barrier = 42;
mask = INT_MASK;
} else {
mask = INT_MASK2;
}
return mask & (i << INT_MASK_WIDTH); // transformed to: return 0;
}
@Check(test = "shiftNonConstMaskInt")
public static void checkShiftNonConstMaskInt(int res) {
if (res != 0) {
throw new RuntimeException("incorrect result: " + res);
}
}
@Test
@Arguments(values = {Argument.RANDOM_EACH, Argument.BOOLEAN_TOGGLE_FIRST_TRUE})
@IR(failOn = { IRNode.AND_L, IRNode.LSHIFT_L })
public static long shiftNonConstMaskLong(long i, boolean flag) {
long mask;
if (flag) {
barrier = 42;
mask = LONG_MASK;
} else {
mask = LONG_MASK2;
}
return mask & (i << LONG_MASK_WIDTH); // transformed to: return 0;
}
@Check(test = "shiftNonConstMaskLong")
public static void checkShiftNonConstMaskLong(long res) {
if (res != 0) {
throw new RuntimeException("incorrect result: " + res);
}
}
@Test
@IR(counts = { IRNode.AND_I, "1" })
@IR(failOn = { IRNode.ADD_I, IRNode.LSHIFT_I })
public static int addShiftMaskInt(int i, int j) {
return (j + (i << INT_MASK_WIDTH)) & INT_MASK; // transformed to: return j & INT_MASK;
}
@Run(test = "addShiftMaskInt")
public static void addShiftMaskInt_runner() {
int i = RANDOM.nextInt();
int j = RANDOM.nextInt();
int res = addShiftMaskInt(i, j);
if (res != (j & INT_MASK)) {
throw new RuntimeException("incorrect result: " + res);
}
}
@Test
@IR(counts = { IRNode.AND_I, "1" })
@IR(failOn = { IRNode.ADD_I, IRNode.LSHIFT_I })
public static int addShiftPlusConstMaskInt(int i, int j) {
return (j + ((i + INT_RANDOM_CONST) << INT_MASK_WIDTH)) & INT_MASK; // transformed to: return j & INT_MASK;
}
@Run(test = "addShiftPlusConstMaskInt")
public static void addShiftPlusConstMaskInt_runner() {
int i = RANDOM.nextInt();
int j = RANDOM.nextInt();
int res = addShiftPlusConstMaskInt(i, j);
if (res != (j & INT_MASK)) {
throw new RuntimeException("incorrect result: " + res);
}
}
@Test
@Arguments(values = {Argument.RANDOM_EACH, Argument.RANDOM_EACH})
@IR(counts = { IRNode.ADD_I, "2", IRNode.LSHIFT_I, "1" })
public static int addShiftPlusConstDisjointMaskInt(int i, int j) {
return (j + ((i + 5) << 2)) & 32; // NOT transformed even though (5<<2) & 32 == 0
}
@Test
@Arguments(values = {Argument.RANDOM_EACH, Argument.RANDOM_EACH})
@IR(counts = { IRNode.ADD_I, "1", IRNode.LSHIFT_I, "1" })
public static int addShiftPlusConstOverlyLargeShift(int i, int j) {
return (j + i << 129) & 32; // NOT transformed, only lower 5 bits of shift count.
}
@Test
@IR(counts = { IRNode.AND_I, "1" })
@IR(failOn = { IRNode.ADD_I, IRNode.LSHIFT_I })
public static int addSshiftNonConstMaskInt(int i, int j, boolean flag) {
int mask;
if (flag) {
barrier = 42;
mask = INT_MASK;
} else {
mask = INT_MASK2;
}
return mask & (j + (i << INT_MASK_WIDTH)); // transformed to: return j & mask;
}
@Run(test = "addSshiftNonConstMaskInt")
public static void addSshiftNonConstMaskInt_runner() {
int i = RANDOM.nextInt();
int j = RANDOM.nextInt();
int res = addSshiftNonConstMaskInt(i, j, true);
if (res != (j & INT_MASK)) {
throw new RuntimeException("incorrect result: " + res);
}
res = addSshiftNonConstMaskInt(i, j, false);
if (res != (j & INT_MASK2)) {
throw new RuntimeException("incorrect result: " + res);
}
}
@Test
@IR(counts = { IRNode.AND_I, "1" })
@IR(failOn = { IRNode.ADD_I })
public static int addConstNonConstMaskInt(int j, boolean flag) {
int mask;
if (flag) {
barrier = 42;
mask = INT_MASK;
} else {
mask = INT_MASK2;
}
return mask & (j + INT_ZERO_CONST); // transformed to: return j & mask;
}
@Run(test = "addConstNonConstMaskInt")
public static void addConstNonConstMaskInt_runner() {
int j = RANDOM.nextInt();
int res = addConstNonConstMaskInt(j, true);
if (res != (j & INT_MASK)) {
throw new RuntimeException("incorrect result: " + res);
}
res = addConstNonConstMaskInt(j, false);
if (res != (j & INT_MASK2)) {
throw new RuntimeException("incorrect result: " + res);
}
}
@Test
@IR(counts = { IRNode.AND_L, "1" })
@IR(failOn = { IRNode.ADD_L, IRNode.LSHIFT_L })
public static long addShiftMaskLong(long i, long j) {
return (j + (i << LONG_MASK_WIDTH)) & LONG_MASK; // transformed to: return j & INT_MASK;
}
@Run(test = "addShiftMaskLong")
public static void addShiftMaskLong_runner() {
long i = RANDOM.nextLong();
long j = RANDOM.nextLong();
long res = addShiftMaskLong(i, j);
if (res != (j & LONG_MASK)) {
throw new RuntimeException("incorrect result: " + res);
}
}
@Test
@IR(counts = { IRNode.AND_L, "1" })
@IR(failOn = { IRNode.ADD_L, IRNode.LSHIFT_L })
public static long addShiftPlusConstMaskLong(long i, long j) {
return (j + ((i + LONG_RANDOM_CONST) << LONG_MASK_WIDTH)) & LONG_MASK; // transformed to: return j & LONG_MASK;
}
@Run(test = "addShiftPlusConstMaskLong")
public static void addShiftPlusConstMaskLong_runner() {
long i = RANDOM.nextLong();
long j = RANDOM.nextLong();
long res = addShiftPlusConstMaskLong(i, j);
if (res != (j & LONG_MASK)) {
throw new RuntimeException("incorrect result: " + res);
}
}
@Test
@IR(counts = { IRNode.AND_L, "1" })
@IR(failOn = { IRNode.ADD_L, IRNode.LSHIFT_L })
public static long addSshiftNonConstMaskLong(long i, long j, boolean flag) {
long mask;
if (flag) {
barrier = 42;
mask = LONG_MASK;
} else {
mask = LONG_MASK2;
}
return mask & (j + (i << LONG_MASK_WIDTH)); // transformed to: return j & mask
}
@Run(test = "addSshiftNonConstMaskLong")
public static void addSshiftNonConstMaskLong_runner() {
long i = RANDOM.nextLong();
long j = RANDOM.nextLong();
long res = addSshiftNonConstMaskLong(i, j, true);
if (res != (j & LONG_MASK)) {
throw new RuntimeException("incorrect result: " + res);
}
res = addSshiftNonConstMaskLong(i, j, false);
if (res != (j & LONG_MASK2)) {
throw new RuntimeException("incorrect result: " + res);
}
}
@Test
@IR(counts = { IRNode.AND_L, "1" })
@IR(failOn = { IRNode.ADD_L })
public static long addConstNonConstMaskLong(long j, boolean flag) {
long mask;
if (flag) {
barrier = 42;
mask = LONG_MASK;
} else {
mask = LONG_MASK2;
}
return mask & (j + LONG_ZERO_CONST); // transformed to: return j & mask;
}
@Run(test = "addConstNonConstMaskLong")
public static void addConstNonConstMaskLong_runner() {
long j = RANDOM.nextLong();
long res = addConstNonConstMaskLong(j, true);
if (res != (j & LONG_MASK)) {
throw new RuntimeException("incorrect result: " + res);
}
res = addConstNonConstMaskLong(j, false);
if (res != (j & LONG_MASK2)) {
throw new RuntimeException("incorrect result: " + res);
}
}
@Test
@Arguments(values = {Argument.RANDOM_EACH, Argument.RANDOM_EACH})
@IR(failOn = { IRNode.AND_I, IRNode.ADD_I, IRNode.LSHIFT_I })
public static int addShiftMaskInt2(int i, int j) {
return ((j << INT_MASK_WIDTH) + (i << INT_MASK_WIDTH)) & INT_MASK; // transformed to: return 0;
}
@Check(test = "addShiftMaskInt2")
public static void checkAddShiftMaskInt2(int res) {
if (res != 0) {
throw new RuntimeException("incorrect result: " + res);
}
}
@Test
@Arguments(values = {Argument.RANDOM_EACH, Argument.RANDOM_EACH})
@IR(failOn = { IRNode.AND_L, IRNode.ADD_L, IRNode.LSHIFT_L })
public static long addShiftMaskLong2(long i, long j) {
return ((j << INT_MASK_WIDTH) + (i << INT_MASK_WIDTH)) & INT_MASK; // transformed to: return 0;
}
@Check(test = "addShiftMaskLong2")
public static void checkAddShiftMaskLong2(long res) {
if (res != 0) {
throw new RuntimeException("incorrect result: " + res);
}
}
// Try to get add inputs swapped compared to other tests
@Test
@IR(counts = { IRNode.AND_I, "1" })
@IR(failOn = { IRNode.ADD_I, IRNode.LSHIFT_I })
public static int addShiftMaskInt3(int i, long j) {
int add1 = (i << INT_MASK_WIDTH);
int add2 = (int)j;
return (add1 + add2) & INT_MASK; // transformed to: return j & INT_MASK;
}
@Run(test = "addShiftMaskInt3")
public static void addShiftMaskInt3_runner() {
int i = RANDOM.nextInt();
int j = RANDOM.nextInt();
int res = addShiftMaskInt3(i, j);
if (res != (j & INT_MASK)) {
throw new RuntimeException("incorrect result: " + res);
}
}
@Test
@IR(counts = { IRNode.AND_L, "1" })
@IR(failOn = { IRNode.ADD_L, IRNode.LSHIFT_L })
public static long addShiftMaskLong3(long i, float j) {
long add1 = (i << LONG_MASK_WIDTH);
long add2 = (long)j;
return (add1 + add2) & LONG_MASK; // transformed to: return j & LONG_MASK;
}
@Run(test = "addShiftMaskLong3")
public static void addShiftMaskLong3_runner() {
long i = RANDOM.nextLong();
float j = RANDOM.nextFloat();
long res = addShiftMaskLong3(i, j);
if (res != (((long) j) & LONG_MASK)) {
throw new RuntimeException("incorrect result: " + res);
}
}
@Test
@Arguments(values = {Argument.RANDOM_EACH})
@IR(failOn = { IRNode.AND_L, IRNode.LSHIFT_I, IRNode.CONV_I2L })
public static long shiftConvMask(int i) {
return ((long) (i << INT_MASK_WIDTH)) & INT_MASK; // transformed to: return 0;
}
@Check(test = "shiftConvMask")
public static void checkShiftConvMask(long res) {
if (res != 0) {
throw new RuntimeException("incorrect result: " + res);
}
}
@Test
@Arguments(values = {Argument.RANDOM_EACH, Argument.BOOLEAN_TOGGLE_FIRST_TRUE})
@IR(failOn = { IRNode.AND_L, IRNode.LSHIFT_I, IRNode.CONV_I2L })
public static long shiftNotConstConvMask(int i, boolean flag) {
long mask;
if (flag) {
barrier = 42;
mask = INT_MASK;
} else {
mask = INT_MASK2;
}
return mask & ((long) (i << INT_MASK_WIDTH)); // transformed to: return 0;
}
@Check(test = "shiftNotConstConvMask")
public static void checkShiftNotConstConvMask(long res) {
if (res != 0) {
throw new RuntimeException("incorrect result: " + res);
}
}
@Test
@IR(counts = { IRNode.AND_L, "1" })
@IR(failOn = { IRNode.ADD_L, IRNode.LSHIFT_I, IRNode.CONV_I2L })
public static long addShiftConvMask(int i, long j) {
return (j + (i << INT_MASK_WIDTH)) & INT_MASK; // transformed to: return j & INT_MASK;
}
@Run(test = "addShiftConvMask")
public static void addShiftConvMask_runner() {
int i = RANDOM.nextInt();
long j = RANDOM.nextLong();
long res = addShiftConvMask(i, j);
if (res != (j & INT_MASK)) {
throw new RuntimeException("incorrect result: " + res);
}
}
@Test
@Arguments(values = {Argument.RANDOM_EACH, Argument.RANDOM_EACH})
@IR(failOn = { IRNode.AND_L, IRNode.ADD_L, IRNode.LSHIFT_I, IRNode.CONV_I2L })
public static long addShiftConvMask2(int i, int j) {
return (((long) (j << INT_MASK_WIDTH)) + ((long) (i << INT_MASK_WIDTH))) & INT_MASK; // transformed to: return 0;
}
@Check(test = "addShiftConvMask2")
public static void checkAddShiftConvMask2(long res) {
if (res != 0) {
throw new RuntimeException("incorrect result: " + res);
}
}
@Test
@IR(failOn = { IRNode.AND_I })
public static int shiftMaskIntCheckIndex(int i, int length) {
return Objects.checkIndex(i << INT_MASK_WIDTH, length) & INT_MASK; // transformed to: return 0;
}
@Run(test = "shiftMaskIntCheckIndex")
public static void shiftMaskIntCheckIndex_runner() {
int i = RANDOM.nextInt((Integer.MAX_VALUE - 1) >> INT_MASK_WIDTH);
int res = shiftMaskIntCheckIndex(i, (i << INT_MASK_WIDTH) + 1);
if (res != 0) {
throw new RuntimeException("incorrect result: " + res);
}
}
@Test
@IR(failOn = { IRNode.AND_L })
public static long shiftMaskLongCheckIndex(long i, long length) {
return Objects.checkIndex(i << LONG_MASK_WIDTH, length) & LONG_MASK; // transformed to: return 0;
}
@Run(test = "shiftMaskLongCheckIndex")
public static void shiftMaskLongCheckIndex_runner() {
long i = RANDOM.nextLong((Long.MAX_VALUE - 1) >> LONG_MASK_WIDTH);
long res = shiftMaskLongCheckIndex(i, (i << LONG_MASK_WIDTH) + 1);
if (res != 0) {
throw new RuntimeException("incorrect result: " + res);
}
}
@Test
@IR(counts = { IRNode.AND_I, "1" })
@IR(failOn = { IRNode.ADD_I })
public static int addShiftMaskIntCheckIndex(int i, int j, int length) {
return (j + Objects.checkIndex(i << INT_MASK_WIDTH, length)) & INT_MASK; // transformed to: return j & INT_MASK;
}
@Run(test = "addShiftMaskIntCheckIndex")
public static void addShiftMaskIntCheckIndex_runner() {
int i = RANDOM.nextInt((Integer.MAX_VALUE - 1) >> INT_MASK_WIDTH);
int j = RANDOM.nextInt();
int res = addShiftMaskIntCheckIndex(i, j, (i << INT_MASK_WIDTH) + 1);
if (res != (j & INT_MASK)) {
throw new RuntimeException("incorrect result: " + res);
}
}
@Test
@IR(counts = { IRNode.AND_L, "1" })
@IR(failOn = { IRNode.ADD_L })
public static long addShiftMaskLongCheckIndex(long i, long j, long length) {
return (j + Objects.checkIndex(i << LONG_MASK_WIDTH, length)) & LONG_MASK; // transformed to: return j & LONG_MASK;
}
@Run(test = "addShiftMaskLongCheckIndex")
public static void addShiftMaskLongCheckIndex_runner() {
long i = RANDOM.nextLong((Long.MAX_VALUE - 1) >> LONG_MASK_WIDTH);
long j = RANDOM.nextLong();
long res = addShiftMaskLongCheckIndex(i, j, (i << LONG_MASK_WIDTH) + 1);
if (res != (j & LONG_MASK)) {
throw new RuntimeException("incorrect result: " + res);
}
}
@Test
@IR(failOn = { IRNode.AND_I, IRNode.ADD_I })
public static int addShiftMaskIntCheckIndex2(int i, int j, int length) {
return (Objects.checkIndex(j << INT_MASK_WIDTH, length) + Objects.checkIndex(i << INT_MASK_WIDTH, length)) & INT_MASK; // transformed to: return 0;
}
@Run(test = "addShiftMaskIntCheckIndex2")
public static void addShiftMaskIntCheckIndex2_runner() {
int i = RANDOM.nextInt((Integer.MAX_VALUE - 1) >> INT_MASK_WIDTH);
int j = RANDOM.nextInt((Integer.MAX_VALUE - 1) >> INT_MASK_WIDTH);
int res = addShiftMaskIntCheckIndex2(i, j, (Integer.max(i, j) << INT_MASK_WIDTH) + 1);
if (res != 0) {
throw new RuntimeException("incorrect result: " + res);
}
}
@Test
@IR(failOn = { IRNode.AND_L, IRNode.ADD_L })
public static long addShiftMaskLongCheckIndex2(long i, long j, long length) {
return (Objects.checkIndex(j << LONG_MASK_WIDTH, length) + Objects.checkIndex(i << LONG_MASK_WIDTH, length)) & LONG_MASK; // transformed to: return 0;
}
@Run(test = "addShiftMaskLongCheckIndex2")
public static void addShiftMaskLongCheckIndex2_runner() {
long i = RANDOM.nextLong((Long.MAX_VALUE - 1) >> LONG_MASK_WIDTH);
long j = RANDOM.nextLong((Long.MAX_VALUE - 1) >> LONG_MASK_WIDTH);
long res = addShiftMaskLongCheckIndex2(i, j, (Long.max(i, j) << LONG_MASK_WIDTH) + 1);
if (res != 0) {
throw new RuntimeException("incorrect result: " + res);
}
}
@Test
@IR(failOn = { IRNode.AND_L, IRNode.CONV_I2L })
public static long shiftConvMaskCheckIndex(int i, int length) {
return ((long) Objects.checkIndex(i << INT_MASK_WIDTH, length)) & INT_MASK; // transformed to: return 0;
}
@Run(test = "shiftConvMaskCheckIndex")
public static void shiftConvMaskCheckIndex_runner() {
int i = RANDOM.nextInt((Integer.MAX_VALUE - 1) >> INT_MASK_WIDTH);
long res = shiftConvMaskCheckIndex(i, (i << INT_MASK_WIDTH) + 1);
if (res != 0) {
throw new RuntimeException("incorrect result: " + res);
}
}
@Test
@IR(counts = { IRNode.AND_L, "1" })
@IR(failOn = { IRNode.ADD_L, IRNode.CONV_I2L })
public static long addShiftConvMaskCheckIndex(int i, long j, int length) {
return (j + Objects.checkIndex(i << INT_MASK_WIDTH, length)) & INT_MASK; // transformed to: return j & INT_MASK;
}
@Run(test = "addShiftConvMaskCheckIndex")
public static void addShiftConvMaskCheckIndex_runner() {
int i = RANDOM.nextInt((Integer.MAX_VALUE - 1) >> INT_MASK_WIDTH);
long j = RANDOM.nextLong();
long res = addShiftConvMaskCheckIndex(i, j, (i << INT_MASK_WIDTH) + 1);
if (res != (j & INT_MASK)) {
throw new RuntimeException("incorrect result: " + res);
}
}
@Test
@IR(failOn = { IRNode.AND_L, IRNode.ADD_L })
public static long addShiftConvMaskCheckIndex2(int i, int j, int length) {
return (((long) Objects.checkIndex(j << INT_MASK_WIDTH, length)) + ((long) Objects.checkIndex(i << INT_MASK_WIDTH, length))) & INT_MASK; // transformed to: return 0;
}
@Run(test = "addShiftConvMaskCheckIndex2")
public static void addShiftConvMaskCheckIndex2_runner() {
int i = RANDOM.nextInt((Integer.MAX_VALUE - 1) >> INT_MASK_WIDTH);
int j = RANDOM.nextInt((Integer.MAX_VALUE - 1) >> INT_MASK_WIDTH);
long res = addShiftConvMaskCheckIndex2(i, j, (Integer.max(i, j) << INT_MASK_WIDTH) + 1);
if (res != 0) {
throw new RuntimeException("incorrect result: " + res);
}
}
}
|