|
1 | 1 | /* |
2 | | - * Copyright (c) 1997, 2025, Oracle and/or its affiliates. All rights reserved. |
| 2 | + * Copyright (c) 1997, 2026, 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 |
@@ -745,71 +745,40 @@ const Type* CmpINode::Value(PhaseGVN* phase) const { |
745 | 745 |
|
746 | 746 | // Simplify a CmpU (compare 2 integers) node, based on local information. |
747 | 747 | // If both inputs are constants, compare them. |
748 | | -const Type *CmpUNode::sub( const Type *t1, const Type *t2 ) const { |
749 | | - assert(!t1->isa_ptr(), "obsolete usage of CmpU"); |
| 748 | +const Type* CmpUNode::sub(const Type* t1, const Type* t2) const { |
| 749 | + const TypeInt* r0 = t1->is_int(); |
| 750 | + const TypeInt* r1 = t2->is_int(); |
750 | 751 |
|
751 | | - // comparing two unsigned ints |
752 | | - const TypeInt *r0 = t1->is_int(); // Handy access |
753 | | - const TypeInt *r1 = t2->is_int(); |
754 | | - |
755 | | - // Current installed version |
756 | | - // Compare ranges for non-overlap |
757 | | - juint lo0 = r0->_lo; |
758 | | - juint hi0 = r0->_hi; |
759 | | - juint lo1 = r1->_lo; |
760 | | - juint hi1 = r1->_hi; |
761 | | - |
762 | | - // If either one has both negative and positive values, |
763 | | - // it therefore contains both 0 and -1, and since [0..-1] is the |
764 | | - // full unsigned range, the type must act as an unsigned bottom. |
765 | | - bool bot0 = ((jint)(lo0 ^ hi0) < 0); |
766 | | - bool bot1 = ((jint)(lo1 ^ hi1) < 0); |
767 | | - |
768 | | - if (bot0 || bot1) { |
769 | | - // All unsigned values are LE -1 and GE 0. |
770 | | - if (lo0 == 0 && hi0 == 0) { |
771 | | - return TypeInt::CC_LE; // 0 <= bot |
772 | | - } else if ((jint)lo0 == -1 && (jint)hi0 == -1) { |
773 | | - return TypeInt::CC_GE; // -1 >= bot |
774 | | - } else if (lo1 == 0 && hi1 == 0) { |
775 | | - return TypeInt::CC_GE; // bot >= 0 |
776 | | - } else if ((jint)lo1 == -1 && (jint)hi1 == -1) { |
777 | | - return TypeInt::CC_LE; // bot <= -1 |
778 | | - } |
779 | | - } else { |
780 | | - // We can use ranges of the form [lo..hi] if signs are the same. |
781 | | - assert(lo0 <= hi0 && lo1 <= hi1, "unsigned ranges are valid"); |
782 | | - // results are reversed, '-' > '+' for unsigned compare |
783 | | - if (hi0 < lo1) { |
784 | | - return TypeInt::CC_LT; // smaller |
785 | | - } else if (lo0 > hi1) { |
786 | | - return TypeInt::CC_GT; // greater |
787 | | - } else if (hi0 == lo1 && lo0 == hi1) { |
788 | | - return TypeInt::CC_EQ; // Equal results |
789 | | - } else if (lo0 >= hi1) { |
790 | | - return TypeInt::CC_GE; |
791 | | - } else if (hi0 <= lo1) { |
792 | | - // Check for special case in Hashtable::get. (See below.) |
793 | | - if ((jint)lo0 >= 0 && (jint)lo1 >= 0 && is_index_range_check()) |
794 | | - return TypeInt::CC_LT; |
795 | | - return TypeInt::CC_LE; |
796 | | - } |
797 | | - } |
798 | 752 | // Check for special case in Hashtable::get - the hash index is |
799 | 753 | // mod'ed to the table size so the following range check is useless. |
800 | 754 | // Check for: (X Mod Y) CmpU Y, where the mod result and Y both have |
801 | 755 | // to be positive. |
802 | 756 | // (This is a gross hack, since the sub method never |
803 | 757 | // looks at the structure of the node in any other case.) |
804 | | - if ((jint)lo0 >= 0 && (jint)lo1 >= 0 && is_index_range_check()) |
| 758 | + if (r0->_lo >= 0 && r1->_lo >= 0 && is_index_range_check()) { |
805 | 759 | return TypeInt::CC_LT; |
| 760 | + } |
| 761 | + |
| 762 | + if (r0->_uhi < r1->_ulo) { |
| 763 | + return TypeInt::CC_LT; |
| 764 | + } else if (r0->_ulo > r1->_uhi) { |
| 765 | + return TypeInt::CC_GT; |
| 766 | + } else if (r0->is_con() && r1->is_con()) { |
| 767 | + // Since r0->_ulo == r0->_uhi == r0->get_con(), we only reach here if the constants are equal |
| 768 | + assert(r0->get_con() == r1->get_con(), "must reach a previous branch otherwise"); |
| 769 | + return TypeInt::CC_EQ; |
| 770 | + } else if (r0->_uhi == r1->_ulo) { |
| 771 | + return TypeInt::CC_LE; |
| 772 | + } else if (r0->_ulo == r1->_uhi) { |
| 773 | + return TypeInt::CC_GE; |
| 774 | + } |
806 | 775 |
|
807 | 776 | const Type* joined = r0->join(r1); |
808 | 777 | if (joined == Type::TOP) { |
809 | 778 | return TypeInt::CC_NE; |
810 | 779 | } |
811 | 780 |
|
812 | | - return TypeInt::CC; // else use worst case results |
| 781 | + return TypeInt::CC; |
813 | 782 | } |
814 | 783 |
|
815 | 784 | const Type* CmpUNode::Value(PhaseGVN* phase) const { |
@@ -963,59 +932,29 @@ const Type *CmpLNode::sub( const Type *t1, const Type *t2 ) const { |
963 | 932 | // Simplify a CmpUL (compare 2 unsigned longs) node, based on local information. |
964 | 933 | // If both inputs are constants, compare them. |
965 | 934 | const Type* CmpULNode::sub(const Type* t1, const Type* t2) const { |
966 | | - assert(!t1->isa_ptr(), "obsolete usage of CmpUL"); |
967 | | - |
968 | | - // comparing two unsigned longs |
969 | | - const TypeLong* r0 = t1->is_long(); // Handy access |
| 935 | + const TypeLong* r0 = t1->is_long(); |
970 | 936 | const TypeLong* r1 = t2->is_long(); |
971 | 937 |
|
972 | | - // Current installed version |
973 | | - // Compare ranges for non-overlap |
974 | | - julong lo0 = r0->_lo; |
975 | | - julong hi0 = r0->_hi; |
976 | | - julong lo1 = r1->_lo; |
977 | | - julong hi1 = r1->_hi; |
978 | | - |
979 | | - // If either one has both negative and positive values, |
980 | | - // it therefore contains both 0 and -1, and since [0..-1] is the |
981 | | - // full unsigned range, the type must act as an unsigned bottom. |
982 | | - bool bot0 = ((jlong)(lo0 ^ hi0) < 0); |
983 | | - bool bot1 = ((jlong)(lo1 ^ hi1) < 0); |
984 | | - |
985 | | - if (bot0 || bot1) { |
986 | | - // All unsigned values are LE -1 and GE 0. |
987 | | - if (lo0 == 0 && hi0 == 0) { |
988 | | - return TypeInt::CC_LE; // 0 <= bot |
989 | | - } else if ((jlong)lo0 == -1 && (jlong)hi0 == -1) { |
990 | | - return TypeInt::CC_GE; // -1 >= bot |
991 | | - } else if (lo1 == 0 && hi1 == 0) { |
992 | | - return TypeInt::CC_GE; // bot >= 0 |
993 | | - } else if ((jlong)lo1 == -1 && (jlong)hi1 == -1) { |
994 | | - return TypeInt::CC_LE; // bot <= -1 |
995 | | - } |
996 | | - } else { |
997 | | - // We can use ranges of the form [lo..hi] if signs are the same. |
998 | | - assert(lo0 <= hi0 && lo1 <= hi1, "unsigned ranges are valid"); |
999 | | - // results are reversed, '-' > '+' for unsigned compare |
1000 | | - if (hi0 < lo1) { |
1001 | | - return TypeInt::CC_LT; // smaller |
1002 | | - } else if (lo0 > hi1) { |
1003 | | - return TypeInt::CC_GT; // greater |
1004 | | - } else if (hi0 == lo1 && lo0 == hi1) { |
1005 | | - return TypeInt::CC_EQ; // Equal results |
1006 | | - } else if (lo0 >= hi1) { |
1007 | | - return TypeInt::CC_GE; |
1008 | | - } else if (hi0 <= lo1) { |
1009 | | - return TypeInt::CC_LE; |
1010 | | - } |
| 938 | + if (r0->_uhi < r1->_ulo) { |
| 939 | + return TypeInt::CC_LT; |
| 940 | + } else if (r0->_ulo > r1->_uhi) { |
| 941 | + return TypeInt::CC_GT; |
| 942 | + } else if (r0->is_con() && r1->is_con()) { |
| 943 | + // Since r0->_ulo == r0->_uhi == r0->get_con(), we only reach here if the constants are equal |
| 944 | + assert(r0->get_con() == r1->get_con(), "must reach a previous branch otherwise"); |
| 945 | + return TypeInt::CC_EQ; |
| 946 | + } else if (r0->_uhi == r1->_ulo) { |
| 947 | + return TypeInt::CC_LE; |
| 948 | + } else if (r0->_ulo == r1->_uhi) { |
| 949 | + return TypeInt::CC_GE; |
1011 | 950 | } |
1012 | 951 |
|
1013 | 952 | const Type* joined = r0->join(r1); |
1014 | 953 | if (joined == Type::TOP) { |
1015 | 954 | return TypeInt::CC_NE; |
1016 | 955 | } |
1017 | 956 |
|
1018 | | - return TypeInt::CC; // else use worst case results |
| 957 | + return TypeInt::CC; |
1019 | 958 | } |
1020 | 959 |
|
1021 | 960 | //============================================================================= |
|
0 commit comments