Commit 34e6bb4
authored
Fix a 32-bit specific bug in
* Added a test
Verifying that checked '.un' casts from floats to small types are not treated as casts from unsigned types.
* Do not mark casts from FP types with GTF_UNSIGNED
It used to be that in the importer, whether the cast was to
be marked as GTF_UNSIGNED was decided exclusively based on
the incoming opcode. However, the flag only makes sense
for casts from integral sources, and it turns out morph
had a bug where it failed to clear this flag which resulted in
bad codegen.
The bug went as follows: "gtMorphCast" turns casts from an FP
type to a small integer into a chain of casts:
CAST(small integer <- FP) => CAST(small integer <- CAST(TYP_INT <- FP)).
On 32 bit platforms, the code failed to clear the GTF_UNSIGNED flag
from the original tree, which meant that the outer cast thought it
had TYP_UINT as the source. This matters for checked casts:
conv.ovf.i2.un(-2.0d), which is a legitimate conversion, was interpreted
wrongly as an overflowing one as the resulting codegen only checked the
upper bound via an unsigned compare.
The fix is two-fold: clear GTF_UNSIGNED for GT_CAST nodes with FP sources
on creation and unify the 64 bit and 32 bit paths in "gtMorphCast",
which, after the removal of GTF_UNSIGNED handling, are identical.
This is a zero-diff change across all SPMI collections for Windows x64, Linux x64,
Linux ARM64.
This **is not** a zero-diff change for Windows x86.
Instances of bad codegen have been corrected in some tests.
* Assert instead of normalizing
Instead of normalizing GTF_UNSIGNED for FP sources in "gtNewCastNode",
assert that it is not set in GenTreeCast's constructor and fix the
importer to respect that constraint.fgMorphCast (#52828)1 parent 7ab62de commit 34e6bb4
File tree
7 files changed
+448
-16
lines changed- src
- coreclr/jit
- tests
- JIT/Directed/Convert
7 files changed
+448
-16
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1365 | 1365 | | |
1366 | 1366 | | |
1367 | 1367 | | |
1368 | | - | |
1369 | | - | |
| 1368 | + | |
| 1369 | + | |
| 1370 | + | |
1370 | 1371 | | |
1371 | 1372 | | |
1372 | 1373 | | |
| |||
1378 | 1379 | | |
1379 | 1380 | | |
1380 | 1381 | | |
1381 | | - | |
| 1382 | + | |
1382 | 1383 | | |
1383 | | - | |
| 1384 | + | |
| 1385 | + | |
1384 | 1386 | | |
1385 | 1387 | | |
1386 | 1388 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3531 | 3531 | | |
3532 | 3532 | | |
3533 | 3533 | | |
| 3534 | + | |
| 3535 | + | |
| 3536 | + | |
| 3537 | + | |
| 3538 | + | |
3534 | 3539 | | |
3535 | 3540 | | |
3536 | 3541 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13456 | 13456 | | |
13457 | 13457 | | |
13458 | 13458 | | |
13459 | | - | |
13460 | | - | |
13461 | 13459 | | |
13462 | 13460 | | |
13463 | 13461 | | |
| 13462 | + | |
| 13463 | + | |
| 13464 | + | |
| 13465 | + | |
| 13466 | + | |
| 13467 | + | |
| 13468 | + | |
| 13469 | + | |
13464 | 13470 | | |
13465 | 13471 | | |
13466 | 13472 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
183 | 183 | | |
184 | 184 | | |
185 | 185 | | |
186 | | - | |
187 | 186 | | |
188 | 187 | | |
189 | | - | |
190 | | - | |
191 | | - | |
192 | | - | |
193 | | - | |
194 | | - | |
195 | | - | |
196 | | - | |
| 188 | + | |
197 | 189 | | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
198 | 194 | | |
199 | | - | |
200 | 195 | | |
201 | 196 | | |
202 | 197 | | |
| |||
0 commit comments