Skip to content

Fix assertion (node->GetRegNum() != REG_NA) during LSRA - #135327

Merged
dhartglassMSFT merged 2 commits into
dotnet:mainfrom
dhartglassMSFT:134831
Oct 8, 2026
Merged

dhartglassMSFT merged 2 commits into
dotnet:mainfrom
dhartglassMSFT:134831

Conversation

@dhartglassMSFT

Copy link
Copy Markdown
Contributor

Jitstress-regs inserts a copy between a LCL_VAR, referring to a struct return buffer, and an LEA

 t97 =    LCL_VAR   long   V01 RetBuf       u:1 rdx REG rdx $80
       /--*  t97    long   
t166 = *  COPY      long   REG rbx
       /--*  t166   long   
 t99 = *  LEA(b+8)  long   REG NA
 t96 =    LCL_VAR   ref    V20 tmp17        u:4 r15 (last use) REG r15 $300
       /--*  t99    long   
       +--*  t96    ref    
       *  STOREIND  ref    REG NA $VN.Void

Change #134644 made gcWriteBarrierFormFromTargetAddress use fgAddrCouldBeHeap which can't see through the copy. Generating a write barrier then asserted while trying to copy out of the LEA, which had NO_REG.

Fix is to add a gtSkipReloadOrCopy to fgAddrCouldBeHeap, after the LEA is peeled. No diffs observed.

fixes #134831

@github-actions github-actions Bot added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label Oct 7, 2026
@dhartglassMSFT

Copy link
Copy Markdown
Contributor Author

fyi @dotnet/jit-contrib @EgorBo

@dhartglassMSFT
dhartglassMSFT requested a review from EgorBo October 7, 2026 06:31
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 5 pipeline(s).
11 pipeline(s) were filtered out due to trigger conditions.
There may be pipelines that require an authorized user to comment /azp run to run.

@dotnet-policy-service

Copy link
Copy Markdown
Contributor

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

@dhartglassMSFT

Copy link
Copy Markdown
Contributor Author

I did find that JIT importer can drop the GTF_IND_TGT_NOT_HEAP flag in cases like this, when inlinee gets inlined. This would get a write barrier prior to Egor's change, so unclear whether fixing the importer would actually improve anything

struct Pod
{
    public object A;
    public object B;
    public int X;
    public int Y;
}
static Pod Inliner(object a, object b) => Inlinee(a, b);
static Pod Inlinee(object a, object b) => new Pod { A = a, B = b, X = 1, Y = 2 };

@JulieLeeMSFT

Copy link
Copy Markdown
Member

@dhartglassMSFT, please check if this fixes #134830 as well.

@dhartglassMSFT

Copy link
Copy Markdown
Contributor Author

@dhartglassMSFT, please check if this fixes #134830 as well.

This change also fixes that issue. I closed 134830 as a duplicate

@dhartglassMSFT
dhartglassMSFT merged commit def4d59 into dotnet:main Oct 8, 2026
138 of 141 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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.

Assertion failed '(node->GetRegNum() != REG_NA) && (needReg != REG_NA)' during 'Generate code'

2 participants