@@ -99,8 +99,16 @@ public boolean isLossless() {
99
99
case I2F :
100
100
case L2D :
101
101
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 );
104
112
} else {
105
113
return false ;
106
114
}
@@ -119,7 +127,7 @@ public boolean canOverflow() {
119
127
return ArithmeticOpTable .forStamp (inputStamp ).getFloatConvert (op ).canOverflowInteger (inputStamp );
120
128
}
121
129
122
- private static boolean isLosslessIntegerToFloatingPoint (IntegerStamp inputStamp , FloatStamp resultStamp ) {
130
+ private static boolean isLosslessIntegerToFloatingPoint (IntegerStamp inputStamp , FloatStamp resultStamp , boolean unsigned ) {
123
131
int mantissaBits ;
124
132
switch (resultStamp .getBits ()) {
125
133
case 32 :
@@ -133,7 +141,11 @@ private static boolean isLosslessIntegerToFloatingPoint(IntegerStamp inputStamp,
133
141
}
134
142
long max = 1L << mantissaBits ;
135
143
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
+ }
137
149
}
138
150
139
151
@ Override
0 commit comments