@@ -99,8 +99,16 @@ public boolean isLossless() {
9999 case I2F :
100100 case L2D :
101101 case L2F :
102- if (value .stamp (NodeView .DEFAULT ) instanceof IntegerStamp ) {
103- return isLosslessIntegerToFloatingPoint ((IntegerStamp ) value .stamp (NodeView .DEFAULT ), (FloatStamp ) stamp (NodeView .DEFAULT ));
102+ if (value .stamp (NodeView .DEFAULT ) instanceof IntegerStamp inputStamp ) {
103+ return isLosslessIntegerToFloatingPoint (inputStamp , (FloatStamp ) stamp (NodeView .DEFAULT ), false );
104+ } else {
105+ return false ;
106+ }
107+ case UI2F :
108+ case UL2D :
109+ case UL2F :
110+ if (value .stamp (NodeView .DEFAULT ) instanceof IntegerStamp inputStamp ) {
111+ return isLosslessIntegerToFloatingPoint (inputStamp , (FloatStamp ) stamp (NodeView .DEFAULT ), true );
104112 } else {
105113 return false ;
106114 }
@@ -119,7 +127,7 @@ public boolean canOverflow() {
119127 return ArithmeticOpTable .forStamp (inputStamp ).getFloatConvert (op ).canOverflowInteger (inputStamp );
120128 }
121129
122- private static boolean isLosslessIntegerToFloatingPoint (IntegerStamp inputStamp , FloatStamp resultStamp ) {
130+ private static boolean isLosslessIntegerToFloatingPoint (IntegerStamp inputStamp , FloatStamp resultStamp , boolean unsigned ) {
123131 int mantissaBits ;
124132 switch (resultStamp .getBits ()) {
125133 case 32 :
@@ -133,7 +141,11 @@ private static boolean isLosslessIntegerToFloatingPoint(IntegerStamp inputStamp,
133141 }
134142 long max = 1L << mantissaBits ;
135143 long min = -(1L << mantissaBits );
136- return min <= inputStamp .lowerBound () && inputStamp .upperBound () <= max ;
144+ if (unsigned ) {
145+ return Long .compareUnsigned (inputStamp .unsignedUpperBound (), max ) <= 0 ;
146+ } else {
147+ return min <= inputStamp .lowerBound () && inputStamp .upperBound () <= max ;
148+ }
137149 }
138150
139151 @ Override
0 commit comments