Skip to content

Commit 49a2a55

Browse files
authored
JIT: Remove GTF_IND_INVARIANT and GTF_IND_NONFAULTING flags checking (#104976)
These flags are strictly optimizations. Having them required to be set for certain indirs based on context of the operand introduces IR invariants that are annoying to work with since it suddenly becomes necessary for all transformations to consider "did we just introduce this IR shape?". Instead, handle these patterns during morph as the optimization it is and remove the strict flags checking from `fgDebugCheckFlags`. Also fix `HandleKindDataIsInvariant` which returned true in some questionable cases, and remove some unnecessary indir flags that morph was setting for `GTF_ICON_OBJ_HDL`.
1 parent 1f0b156 commit 49a2a55

File tree

4 files changed

+49
-54
lines changed

4 files changed

+49
-54
lines changed

src/coreclr/jit/fgdiagnostic.cpp

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -3360,37 +3360,6 @@ void Compiler::fgDebugCheckFlags(GenTree* tree, BasicBlock* block)
33603360
break;
33613361

33623362
case GT_IND:
3363-
// Do we have a constant integer address as op1 that is also a handle?
3364-
if (op1->IsIconHandle())
3365-
{
3366-
if ((tree->gtFlags & GTF_IND_INVARIANT) != 0)
3367-
{
3368-
actualFlags |= GTF_IND_INVARIANT;
3369-
}
3370-
if ((tree->gtFlags & GTF_IND_NONFAULTING) != 0)
3371-
{
3372-
actualFlags |= GTF_IND_NONFAULTING;
3373-
}
3374-
3375-
GenTreeFlags handleKind = op1->GetIconHandleFlag();
3376-
3377-
// Some of these aren't handles to invariant data...
3378-
if (GenTree::HandleKindDataIsInvariant(handleKind) && (handleKind != GTF_ICON_FTN_ADDR))
3379-
{
3380-
expectedFlags |= GTF_IND_INVARIANT;
3381-
}
3382-
else
3383-
{
3384-
// For statics, we expect the GTF_GLOB_REF to be set. However, we currently
3385-
// fail to set it in a number of situations, and so this check is disabled.
3386-
// TODO: enable checking of GTF_GLOB_REF.
3387-
// expectedFlags |= GTF_GLOB_REF;
3388-
}
3389-
3390-
// Currently we expect all indirections with constant addresses to be nonfaulting.
3391-
expectedFlags |= GTF_IND_NONFAULTING;
3392-
}
3393-
33943363
assert(((tree->gtFlags & GTF_IND_TGT_NOT_HEAP) == 0) || ((tree->gtFlags & GTF_IND_TGT_HEAP) == 0));
33953364
break;
33963365

src/coreclr/jit/gentree.cpp

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7516,8 +7516,6 @@ GenTree* Compiler::gtNewIndOfIconHandleNode(var_types indType, size_t addr, GenT
75167516

75177517
if (isInvariant)
75187518
{
7519-
assert(GenTree::HandleKindDataIsInvariant(iconFlags));
7520-
75217519
// This indirection also is invariant.
75227520
indirFlags |= GTF_IND_INVARIANT;
75237521

@@ -10576,8 +10574,7 @@ void GenTree::SetIndirExceptionFlags(Compiler* comp)
1057610574

1057710575
//------------------------------------------------------------------------------
1057810576
// HandleKindDataIsInvariant: Returns true if the data referred to by a handle
10579-
// address is guaranteed to be invariant. Note that GTF_ICON_FTN_ADDR handles may
10580-
// or may not point to invariant data.
10577+
// address is guaranteed to be invariant.
1058110578
//
1058210579
// Arguments:
1058310580
// flags - GenTree flags for handle.
@@ -10588,11 +10585,32 @@ bool GenTree::HandleKindDataIsInvariant(GenTreeFlags flags)
1058810585
GenTreeFlags handleKind = flags & GTF_ICON_HDL_MASK;
1058910586
assert(handleKind != GTF_EMPTY);
1059010587

10591-
// All handle types are assumed invariant except those specifically listed here.
10592-
10593-
return (handleKind != GTF_ICON_STATIC_HDL) && // Pointer to a mutable class Static variable
10594-
(handleKind != GTF_ICON_BBC_PTR) && // Pointer to a mutable basic block count value
10595-
(handleKind != GTF_ICON_GLOBAL_PTR); // Pointer to mutable data from the VM state
10588+
switch (handleKind)
10589+
{
10590+
case GTF_ICON_SCOPE_HDL:
10591+
case GTF_ICON_CLASS_HDL:
10592+
case GTF_ICON_METHOD_HDL:
10593+
case GTF_ICON_FIELD_HDL:
10594+
case GTF_ICON_STR_HDL:
10595+
case GTF_ICON_CONST_PTR:
10596+
case GTF_ICON_VARG_HDL:
10597+
case GTF_ICON_PINVKI_HDL:
10598+
case GTF_ICON_TOKEN_HDL:
10599+
case GTF_ICON_TLS_HDL:
10600+
case GTF_ICON_CIDMID_HDL:
10601+
case GTF_ICON_FIELD_SEQ:
10602+
case GTF_ICON_STATIC_ADDR_PTR:
10603+
case GTF_ICON_SECREL_OFFSET:
10604+
case GTF_ICON_TLSGD_OFFSET:
10605+
return true;
10606+
case GTF_ICON_FTN_ADDR:
10607+
case GTF_ICON_GLOBAL_PTR:
10608+
case GTF_ICON_STATIC_HDL:
10609+
case GTF_ICON_BBC_PTR:
10610+
case GTF_ICON_STATIC_BOX_PTR:
10611+
default:
10612+
return false;
10613+
}
1059610614
}
1059710615

1059810616
#ifdef DEBUG

src/coreclr/jit/gentree.h

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -513,18 +513,18 @@ enum GenTreeFlags : unsigned int
513513
GTF_ICON_FIELD_HDL = 0x04000000, // GT_CNS_INT -- constant is a field handle
514514
GTF_ICON_STATIC_HDL = 0x05000000, // GT_CNS_INT -- constant is a handle to static data
515515
GTF_ICON_STR_HDL = 0x06000000, // GT_CNS_INT -- constant is a pinned handle pointing to a string object
516-
GTF_ICON_OBJ_HDL = 0x12000000, // GT_CNS_INT -- constant is an object handle (e.g. frozen string or Type object)
517-
GTF_ICON_CONST_PTR = 0x07000000, // GT_CNS_INT -- constant is a pointer to immutable data, (e.g. IAT_PPVALUE)
518-
GTF_ICON_GLOBAL_PTR = 0x08000000, // GT_CNS_INT -- constant is a pointer to mutable data (e.g. from the VM state)
519-
GTF_ICON_VARG_HDL = 0x09000000, // GT_CNS_INT -- constant is a var arg cookie handle
520-
GTF_ICON_PINVKI_HDL = 0x0A000000, // GT_CNS_INT -- constant is a pinvoke calli handle
521-
GTF_ICON_TOKEN_HDL = 0x0B000000, // GT_CNS_INT -- constant is a token handle (other than class, method or field)
522-
GTF_ICON_TLS_HDL = 0x0C000000, // GT_CNS_INT -- constant is a TLS ref with offset
523-
GTF_ICON_FTN_ADDR = 0x0D000000, // GT_CNS_INT -- constant is a function address
524-
GTF_ICON_CIDMID_HDL = 0x0E000000, // GT_CNS_INT -- constant is a class ID or a module ID
525-
GTF_ICON_BBC_PTR = 0x0F000000, // GT_CNS_INT -- constant is a basic block count pointer
526-
GTF_ICON_STATIC_BOX_PTR = 0x10000000, // GT_CNS_INT -- constant is an address of the box for a STATIC_IN_HEAP field
527-
GTF_ICON_FIELD_SEQ = 0x11000000, // <--------> -- constant is a FieldSeq* (used only as VNHandle)
516+
GTF_ICON_OBJ_HDL = 0x07000000, // GT_CNS_INT -- constant is an object handle (e.g. frozen string or Type object)
517+
GTF_ICON_CONST_PTR = 0x08000000, // GT_CNS_INT -- constant is a pointer to immutable data, (e.g. IAT_PPVALUE)
518+
GTF_ICON_GLOBAL_PTR = 0x09000000, // GT_CNS_INT -- constant is a pointer to mutable data (e.g. from the VM state)
519+
GTF_ICON_VARG_HDL = 0x0A000000, // GT_CNS_INT -- constant is a var arg cookie handle
520+
GTF_ICON_PINVKI_HDL = 0x0B000000, // GT_CNS_INT -- constant is a pinvoke calli handle
521+
GTF_ICON_TOKEN_HDL = 0x0C000000, // GT_CNS_INT -- constant is a token handle (other than class, method or field)
522+
GTF_ICON_TLS_HDL = 0x0D000000, // GT_CNS_INT -- constant is a TLS ref with offset
523+
GTF_ICON_FTN_ADDR = 0x0E000000, // GT_CNS_INT -- constant is a function address
524+
GTF_ICON_CIDMID_HDL = 0x0F000000, // GT_CNS_INT -- constant is a class ID or a module ID
525+
GTF_ICON_BBC_PTR = 0x10000000, // GT_CNS_INT -- constant is a basic block count pointer
526+
GTF_ICON_STATIC_BOX_PTR = 0x11000000, // GT_CNS_INT -- constant is an address of the box for a STATIC_IN_HEAP field
527+
GTF_ICON_FIELD_SEQ = 0x12000000, // <--------> -- constant is a FieldSeq* (used only as VNHandle)
528528
GTF_ICON_STATIC_ADDR_PTR = 0x13000000, // GT_CNS_INT -- constant is a pointer to a static base address
529529
GTF_ICON_SECREL_OFFSET = 0x14000000, // GT_CNS_INT -- constant is an offset in a certain section.
530530
GTF_ICON_TLSGD_OFFSET = 0x15000000, // GT_CNS_INT -- constant is an argument to tls_get_addr.

src/coreclr/jit/morph.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8679,9 +8679,17 @@ GenTree* Compiler::fgMorphSmpOp(GenTree* tree, MorphAddrContext* mac, bool* optA
86798679

86808680
case GT_IND:
86818681
{
8682-
if (op1->IsIconHandle(GTF_ICON_OBJ_HDL))
8682+
if (op1->IsIconHandle())
86838683
{
8684-
tree->gtFlags |= (GTF_IND_INVARIANT | GTF_IND_NONFAULTING | GTF_IND_NONNULL);
8684+
// All indirections with (handle) constant addresses are
8685+
// nonfaulting.
8686+
tree->gtFlags |= GTF_IND_NONFAULTING;
8687+
8688+
// We know some handle types always point to invariant data.
8689+
if (GenTree::HandleKindDataIsInvariant(op1->GetIconHandleFlag()))
8690+
{
8691+
tree->gtFlags |= GTF_IND_INVARIANT;
8692+
}
86858693
}
86868694

86878695
GenTree* optimizedTree = fgMorphFinalizeIndir(tree->AsIndir());

0 commit comments

Comments
 (0)