Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add some documentation on GT_CAST's semantics #67208

Merged
merged 2 commits into from
Mar 28, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 27 additions & 2 deletions src/coreclr/jit/gentree.h
Original file line number Diff line number Diff line change
Expand Up @@ -3562,8 +3562,33 @@ struct GenTreeLclFld : public GenTreeLclVarCommon
#endif
};

/* gtCast -- conversion to a different type (GT_CAST) */

// GenTreeCast - conversion to a different type (GT_CAST).
//
// This node represents all "conv[.ovf].{type}[.un]" IL opcodes.
//
// There are four semantically significant values that determine what it does:
//
// 1) "genActualType(CastOp())" - the type being cast from.
// 2) "gtCastType" - the type being cast to.
// 3) "IsUnsigned" (the "GTF_UNSIGNED" flag) - whether the cast is "unsigned".
// 4) "gtOverflow" (the "GTF_OVERFLOW" flag) - whether the cast is checked.
//
// Different "kinds" of casts use these values differently; not all are always
// meaningful or legal:
//
// 1) For casts from FP types, "IsUnsigned" will always be "false".
// 2) Checked casts use "IsUnsigned" to represent the fact the type being cast
// from is unsigned. The target type's signedness is similarly significant.
// 3) For unchecked casts, "IsUnsigned" is significant for "int -> long", where
// it decides whether the cast sign- or zero-extends its source, and "integer
// -> FP" cases. For all other unchecked casts, "IsUnsigned" is meaningless.
// 4) For unchecked casts, signedness of the target type is only meaningful if
// the cast is to an FP or small type. In the latter case (and everywhere
// else in IR) it decided whether the value will be sign- or zero-extended.
//
// For additional context on "GT_CAST"'s semantics, see "IntegralRange::ForCast"
// methods and "GenIntCastDesc"'s constructor.
//
struct GenTreeCast : public GenTreeOp
{
GenTree*& CastOp()
Expand Down