|
1 | 1 | /* |
2 | | - * Copyright (c) 2013, 2023, Oracle and/or its affiliates. All rights reserved. |
| 2 | + * Copyright (c) 2013, 2025, Oracle and/or its affiliates. All rights reserved. |
3 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 | 4 | * |
5 | 5 | * This code is free software; you can redistribute it and/or modify it |
@@ -649,7 +649,8 @@ private OptimizedCompareTests shouldOptimizeCompare(CompareNode compare, Inducti |
649 | 649 | if (boundStamp instanceof IntegerStamp && ivStamp instanceof IntegerStamp) { |
650 | 650 | IntegerStamp integerBoundStamp = (IntegerStamp) boundStamp; |
651 | 651 | IntegerStamp integerIvStamp = (IntegerStamp) ivStamp; |
652 | | - if (fitsIn32Bit(integerBoundStamp) && fitsIn32Bit(integerIvStamp)) { |
| 652 | + NumUtil.Signedness signedness = compare.condition().isUnsigned() ? NumUtil.Signedness.UNSIGNED : NumUtil.Signedness.SIGNED; |
| 653 | + if (fitsIn32Bit(integerBoundStamp, signedness) && fitsIn32Bit(integerIvStamp, signedness)) { |
653 | 654 | fitsInInt = true; |
654 | 655 | } |
655 | 656 | } |
@@ -757,8 +758,19 @@ private static boolean optimizedCompareUnconditionalDeopt(GuardNode guard, Optim |
757 | 758 | return false; |
758 | 759 | } |
759 | 760 |
|
760 | | - private static boolean fitsIn32Bit(IntegerStamp stamp) { |
761 | | - return NumUtil.isUInt(stamp.mayBeSet()); |
| 761 | + /** |
| 762 | + * Returns {@code true} if the given stamp fits into a 32-bit range. If the stamp is larger |
| 763 | + * than 32 bits, the bounds must be signed or unsigned according to {@code signedness}. |
| 764 | + */ |
| 765 | + private static boolean fitsIn32Bit(IntegerStamp stamp, NumUtil.Signedness signedness) { |
| 766 | + if (stamp.getBits() <= 32) { |
| 767 | + return true; |
| 768 | + } |
| 769 | + if (signedness == NumUtil.Signedness.SIGNED) { |
| 770 | + return NumUtil.isSignedNbit(32, stamp.lowerBound()) && NumUtil.isSignedNbit(32, stamp.upperBound()); |
| 771 | + } else { |
| 772 | + return NumUtil.isUnsignedNbit(32, stamp.lowerBound()) && NumUtil.isUnsignedNbit(32, stamp.upperBound()); |
| 773 | + } |
762 | 774 | } |
763 | 775 |
|
764 | 776 | private CFGLoop<HIRBlock> tryOptimizeInstanceOf(GuardNode guard, InstanceOfNode compare) { |
|
0 commit comments