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

Don't use VN when it's already stale #97943

Merged
merged 3 commits into from
Feb 4, 2024
Merged

Conversation

EgorBo
Copy link
Member

@EgorBo EgorBo commented Feb 4, 2024

Runtime lookup expansion could use VNs when it's no longer legal.
gcIsWriteBarrierCandidate could use VNs even in codegen phase.

VN_BASED_DEAD_STORE_REMOVAL is the last phase where we still can rely on VNs.

@dotnet-issue-labeler dotnet-issue-labeler bot added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label Feb 4, 2024
@ghost ghost assigned EgorBo Feb 4, 2024
@ghost
Copy link

ghost commented Feb 4, 2024

Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch
See info in area-owners.md if you want to be subscribed.

Issue Details

Runtime lookup expansion could use VNs when it's no longer legal.
gcIsWriteBarrierCandidate could use VNs even in codegen phase.

Author: EgorBo
Assignees: -
Labels:

area-CodeGen-coreclr

Milestone: -

@EgorBo
Copy link
Member Author

EgorBo commented Feb 4, 2024

A regression example:

Details

***** BB01 [0000]
STMT00001 ( 0x008[E-] ... 0x00E )
N008 ( 26, 32) [000007] hACXGO--R--                         *  STOREIND  ref    $183
N007 (  4, 11) [000090] -A---------                         +--*  COMMA     long   $c1
N005 (  3, 10) [000088] DA---------                         |  +--*  STORE_LCL_VAR long   V10 cse2         d:1 $VN.Void
N004 (  3, 10) [000006] H----------                         |  |  \--*  CNS_INT(h) long   0x26609801f60 static Fseq[<unknown field>] $c1
N006 (  1,  1) [000089] -----------                         |  \--*  LCL_VAR   long   V10 cse2         u:1 $c1
N003 ( 18, 18) [000005] --CXG------                         \--*  CALL help ref    CORINFO_HELP_NEWARR_1_VC $182
N001 (  3, 10) [000004] H---------- arg0 in rcx                +--*  CNS_INT(h) long   0x7ffd7df983b8 class $c0
N002 (  1,  1) [000003] ----------- arg1 in rdx                \--*  CNS_INT   long   1 $100

***** BB01 [0000]
STMT00002 ( 0x013[E-] ... 0x01A )
N021 ( 22, 24) [000013] nA-XGO-----                         *  STORE_BLK struct<RefWrapper, 8> (init) <l:$18c, c:$18b>
N019 ( 14, 18) [000045] -A-XGO-----                         +--*  COMMA     byref  <l:$303, c:$302>
N006 (  4,  4) [000032] DA--G------                         |  +--*  STORE_LCL_VAR ref    V05 tmp3         d:2 $VN.Void
N005 (  4,  4) [000085] -A--G------                         |  |  \--*  COMMA     ref    <l:$200, c:$1c2>
N003 (  3,  3) [000083] DA--G------                         |  |     +--*  STORE_LCL_VAR ref    V09 cse1         d:1 $VN.Void
N002 (  3,  2) [000009] n---G------                         |  |     |  \--*  IND       ref    <l:$200, c:$1c2>
N001 (  1,  1) [000091] -----------                         |  |     |     \--*  LCL_VAR   long   V10 cse2         u:1 $c1
N004 (  1,  1) [000084] -----------                         |  |     \--*  LCL_VAR   ref    V09 cse1         u:1 <l:$200, c:$1c2>
N018 ( 10, 14) [000080] -A-X-O-----                         |  \--*  COMMA     byref  <l:$303, c:$302>
N016 (  9, 13) [000078] DA-X-O-----                         |     +--*  STORE_LCL_VAR byref  V08 cse0         d:1 $VN.Void
N015 (  9, 13) [000044] ---X-O-----                         |     |  \--*  COMMA     byref  <l:$303, c:$302>
N010 (  8, 11) [000037] ---X-O-----                         |     |     +--*  BOUNDS_CHECK_Rng void   <l:$18c, c:$18b>
N007 (  1,  1) [000010] -----------                         |     |     |  +--*  CNS_INT   int    0 $41
N009 (  3,  3) [000036] ---X-------                         |     |     |  \--*  ARR_LENGTH int    <l:$42, c:$2c0>
N008 (  1,  1) [000033] -----------                         |     |     |     \--*  LCL_VAR   ref    V05 tmp3         u:2 <l:$200, c:$1c2>
N014 (  1,  2) [000043] -----O-----                         |     |     \--*  ARR_ADDR  byref RefWrapper[] $340
N013 (  1,  2) [000042] -------N---                         |     |        \--*  ADD       byref  <l:$300, c:$301>
N011 (  1,  1) [000034] -----------                         |     |           +--*  LCL_VAR   ref    V05 tmp3         u:2 (last use) <l:$200, c:$1c2>
N012 (  1,  1) [000041] -----------                         |     |           \--*  CNS_INT   long   16 $101
N017 (  1,  1) [000079] -----------                         |     \--*  LCL_VAR   byref  V08 cse0         u:1 <l:$303, c:$302>
N020 (  1,  1) [000011] -----------                         \--*  CNS_INT   int    0 $41

***** BB01 [0000]
STMT00004 ( 0x01F[E-] ... ??? )
N006 (  9,  9) [000061] DA--GO-----                         *  STORE_LCL_VAR ref    V04 tmp2         d:2 <l:$18c, c:$192>
N005 (  5,  6) [000060] nA--GO-----                         \--*  IND       ref    <l:$194, c:$193>
N004 (  2,  4) [000059] -A--GO-----                            \--*  COMMA     byref  <l:$303, c:$305>
N002 (  1,  3) [000046] DA--G------                               +--*  STORE_LCL_VAR ref    V06 tmp4         d:2 $VN.Void
N001 (  1,  1) [000086] -----------                               |  \--*  LCL_VAR   ref    V09 cse1         u:1 <l:$200, c:$1c2>
N003 (  1,  1) [000081] -----------                               \--*  LCL_VAR   byref  V08 cse0         u:1 $340

***** BB01 [0000]
STMT00005 ( 0x025[E-] ... 0x02C )
N006 (  9,  9) [000077] nA--GO-----                         *  STOREIND  ref    <l:$18c, c:$19a>
N004 (  2,  4) [000075] -A--GO-----                         +--*  COMMA     byref  <l:$303, c:$307>
N002 (  1,  3) [000062] DA--G------                         |  +--*  STORE_LCL_VAR ref    V07 tmp5         d:2 $VN.Void
N001 (  1,  1) [000087] -----------                         |  |  \--*  LCL_VAR   ref    V09 cse1         u:1 <l:$200, c:$1c2>
N003 (  1,  1) [000082] -----------                         |  \--*  LCL_VAR   byref  V08 cse0         u:1 $340
N005 (  3,  2) [000076] -----------                         \--*  LCL_VAR   ref    V04 tmp2         u:2 (last use) <l:$VN.Null, c:$1c6>

***** BB01 [0000]
STMT00006 ( 0x031[E-] ... 0x031 )
N001 (  0,  0) [000023] -----------                         *  RETURN    void   $VN.Void

It looks like gcIsWriteBarrierCandidate was relying on Liberal VN for VNNull and it was kind of too optimistic? See [000076] tree

GenTree** callUse = nullptr;
Statement* newFirstStmt = nullptr;
block = fgSplitBlockBeforeTree(block, stmt, call, &newFirstStmt, &callUse);
assert(prevBb != nullptr && block != nullptr);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unrelated change, just a clean up since SplitAtTreeAndReplaceItWithLocal does exactly that.

@EgorBo EgorBo marked this pull request as ready for review February 4, 2024 16:07
@EgorBo
Copy link
Member Author

EgorBo commented Feb 4, 2024

PTAL @jakobbotsch @AndyAyersMS cc @dotnet/jit-contrib Diffs 12 methods regressed in Tests because of #97943 (comment)

Copy link
Member

@AndyAyersMS AndyAyersMS left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

Looks like the gcinfo use of VNs goes way back.

@EgorBo
Copy link
Member Author

EgorBo commented Feb 4, 2024

CI Failure is #97049

@EgorBo EgorBo merged commit 8aa6afc into dotnet:main Feb 4, 2024
127 of 129 checks passed
@EgorBo EgorBo deleted the assertprop-wb-fix-2 branch February 4, 2024 20:59
@@ -240,8 +240,8 @@ GCInfo::WriteBarrierForm GCInfo::gcIsWriteBarrierCandidate(GenTreeStoreInd* stor
}

// Ignore any assignments of NULL.
GenTree* const data = store->Data()->gtSkipReloadOrCopy();
if ((data->GetVN(VNK_Liberal) == ValueNumStore::VNForNull()) || data->IsIntegralConst(0))
GenTree* const data = store->Data()->gtSkipReloadOrCopy()->gtEffectiveVal();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this change? GT_COMMA should not exist at this point, and if it did it is questionable to not skip reloads inside it (would cause issues during codegen).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree, completely unnecessary, will remove as part of some other PR

@@ -4101,7 +4101,7 @@ enum GenTreeCallFlags : unsigned int
GTF_CALL_M_GUARDED_DEVIRT_CHAIN = 0x00080000, // this call is a candidate for chained guarded devirtualization
GTF_CALL_M_ALLOC_SIDE_EFFECTS = 0x00100000, // this is a call to an allocator with side effects
GTF_CALL_M_SUPPRESS_GC_TRANSITION = 0x00200000, // suppress the GC transition (i.e. during a pinvoke) but a separate GC safe point is required.
GTF_CALL_M_EXP_RUNTIME_LOOKUP = 0x00400000, // this call needs to be transformed into CFG for the dynamic dictionary expansion feature.
GTF_CALL_M_EXP_RUNTIME_LOOKUP = 0x00400000, // [DEBUG only] this call needs to be transformed into CFG for the dynamic dictionary expansion feature.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this is debug only can you please move it to GenTreeCallDebugFlags?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It was sort of unrelated to this PR, but good idea! One less bit occupied.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants