Skip to content

[Wasm RyuJIT] initblk fix for #125756 - #125836

Merged
kg merged 1 commit into
dotnet:mainfrom
kg:issue125756
Mar 24, 2026
Merged

kg merged 1 commit into
dotnet:mainfrom
kg:issue125756

Conversation

@kg

@kg kg commented Mar 20, 2026

Copy link
Copy Markdown
Contributor

I'm guessing this will be a TP regression but I'm not sure how much. The existing code looks blatantly wrong.

@kg kg added arch-wasm WebAssembly architecture area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI labels Mar 20, 2026
Copilot AI review requested due to automatic review settings March 20, 2026 15:20
@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.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR tightens CoreCLR JIT’s identification of initblk-style GT_STORE_BLK nodes so that they’re recognized as init blocks only when the source is both an int-typed value and has init-value semantics (i.e., IsInitVal() after skipping reload/copy wrappers). This aligns OperIsInitBlkOp() with the intended IR invariant and prevents incorrect lowering/codegen choices (notably for WASM where initblk vs copyblk maps to different native opcodes).

Changes:

  • Update GenTree::OperIsInitBlkOp() to require IsInitVal() (after gtSkipReloadOrCopy()) in addition to TYP_INT.
  • Remove the previous DEBUG assert-by-equivalence in favor of a direct semantic check.

@kg

kg commented Mar 21, 2026

Copy link
Copy Markdown
Contributor Author

TP impact seems near-zero if I'm reading the diffs correctly.

@kg
kg marked this pull request as ready for review March 21, 2026 00:03
@jakobbotsch

Copy link
Copy Markdown
Member

Did you look at why wasm produces the mistyped IR? This assert seems to imply that the mistyped IR is only expected for constant initialization. It seems wrong to be removing that invariant.

@kg

kg commented Mar 21, 2026

Copy link
Copy Markdown
Contributor Author

I don't think the IR is mistyped. The RHS of the block store is a function call returning a struct, and the struct is int-sized so the JIT turns it into TYP_INT.

@jakobbotsch

Copy link
Copy Markdown
Member

I don't think the IR is mistyped. The RHS of the block store is a function call returning a struct, and the struct is int-sized so the JIT turns it into TYP_INT.

Shouldn't this be kicking in to end up with a STOREIND?

store->SetOper(GT_STOREIND);

What happens for other backends?

@SingleAccretion

Copy link
Copy Markdown
Contributor

Shouldn't this be kicking in to end up with a STOREIND?

I suspect this is the case of a struct enregistered as a whole. Where we leave the STORE_LCL_VAR as-is.

For such a case, there is a structural ambiguity in the IR if the value is CNS_INT 0: is it an init block, or is it a copy block?

Logically it should be a copy block since that's what we support in codegen. But they're also semantically equivalent.

After this change, we will consider them init blocks. It probably doesn't matter too much.

@AndyAyersMS

Copy link
Copy Markdown
Member

@kg which assert in #125756 (comment) does this fix, or does it fix both of them?

@kg

kg commented Mar 23, 2026

Copy link
Copy Markdown
Contributor Author

@AndyAyersMS (1) Assertion failed 'isInitBlk == src->gtSkipReloadOrCopy()->IsInitVal()' i think

@kg
kg merged commit bfaa2d8 into dotnet:main Mar 24, 2026
137 checks passed
@jakobbotsch

Copy link
Copy Markdown
Member

It would still be good to understand why other backends do not hit this.

@kg

kg commented Mar 24, 2026

Copy link
Copy Markdown
Contributor Author

Do you want me to back it out?

@jakobbotsch

Copy link
Copy Markdown
Member

Do you want me to back it out?

No, the change seems innocent enough. I am just wondering what makes other backends different in their handling and if wasm is different for a good reason or not.

@SingleAccretion

Copy link
Copy Markdown
Contributor

I am just wondering what makes other backends different in their handling

I think the only difference is that we happen to not call IsCopyBlk/IsInitBlk on such STORE_LCL_VARs on other targets.

@jakobbotsch

Copy link
Copy Markdown
Member

I am just wondering what makes other backends different in their handling

I think the only difference is that we happen to not call IsCopyBlk/IsInitBlk on such STORE_LCL_VARs on other targets.

Considering the OperIsInitBlk name it came to a surprise to me that the function was 1) not based on gtOper only, and 2) returning true for STORE_LCL_VAR in the first place.

@SingleAccretion

SingleAccretion commented Mar 24, 2026 •

Copy link
Copy Markdown
Contributor

Considering the OperIsInitBlk name it came to a surprise to me that the function was 1) not based on gtOper only, and 2) returning true for STORE_LCL_VAR in the first place.

Nowadays it would be more accurate to rename these to IsStructCopyStore / IsStructInitStore. Historically it was all of course based on the IL opcodes and how they translated into GT_ASG shapes.

Edit: if memory serves me right, before struct-typed-ASG, we had these nodes as explicit "opers". A lot like today's STORE_BLK.

@github-actions github-actions Bot locked and limited conversation to collaborators Apr 24, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

arch-wasm WebAssembly architecture 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.

5 participants