Skip to content

Fixing assert on variable live range for simd12 LCL / STORE_LCL #79182

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

Merged

Conversation

BrianBohe
Copy link
Member

Intend to fix 78898.

Op GT_STORE_LCL_VAR for target type SIMD12 always stores the result on the stack when FEATURE_SIMD is on. Liveness and the variable descriptor were updated after emitting this operation. This PR updates the tree's variable descriptor and liveness.

Having said that, LSRA assigned a target register for GT_STORE_LCL_VAR is assigned a target register in LSRA although the result (v01 arg0) is stored on the stack. For that reason, the tree target reg is being updated inside our specific case. LSRA already has the information about the available registers, then might be better to add this SIMD12 information there and avoid changing the tree after. I am opening this PR to see if this is triggering other problems.

The same behavior may be happening for GT_STOREIND for the same target type but I cannot get an example.

@ghost ghost added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label Dec 3, 2022
@ghost ghost assigned BrianBohe Dec 3, 2022
@ghost
Copy link

ghost commented Dec 3, 2022

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

Issue Details

Intend to fix 78898.

Op GT_STORE_LCL_VAR for target type SIMD12 always stores the result on the stack when FEATURE_SIMD is on. Liveness and the variable descriptor were updated after emitting this operation. This PR updates the tree's variable descriptor and liveness.

Having said that, LSRA assigned a target register for GT_STORE_LCL_VAR is assigned a target register in LSRA although the result (v01 arg0) is stored on the stack. For that reason, the tree target reg is being updated inside our specific case. LSRA already has the information about the available registers, then might be better to add this SIMD12 information there and avoid changing the tree after. I am opening this PR to see if this is triggering other problems.

The same behavior may be happening for GT_STOREIND for the same target type but I cannot get an example.

Author: BrianBohe
Assignees: BrianBohe
Labels:

area-CodeGen-coreclr

Milestone: -

@BrianBohe
Copy link
Member Author

/azp run runtime-coreclr jitstress

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@BruceForstall
Copy link
Contributor

I wonder why the arm64 genStoreLclTypeSIMD12 code supports reg/reg mov but the x64 code doesn't.

@@ -938,10 +938,10 @@ void CodeGen::genStoreLclTypeSIMD12(GenTree* treeNode)
{
assert((treeNode->OperGet() == GT_STORE_LCL_FLD) || (treeNode->OperGet() == GT_STORE_LCL_VAR));

treeNode->SetRegNum(REG_STK); // we always store the result on stack
Copy link
Contributor

Choose a reason for hiding this comment

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

It seems odd to call this. Isn't the problem that LSRA shouldn't be assigning a register to this node at all?

@ghost ghost added the needs-author-action An issue or pull request that requires more info or actions from the author. label Dec 6, 2022
@BrianBohe
Copy link
Member Author

Just a comment I didn't share before. If we simply modify V01 varDsc home to STK (as it is done in other places) and call to update liveness, or just call to the update liveness function directly, the assert won't hit but we would be reporting a home that is not meant to be (xmm1). The liveness function would update its varDsc home to xmm1 anyway and report it to start living there, although STORE_LCL_VAR is doing a spill for this specific case (x86 and type SIMD12). That is why I changed the tree target register.

I thought the best was to update the tree target register to REG_NA but @kunalspathak suggests it could also be that we are wrongly not setting the spill flag.

@ghost ghost removed the needs-author-action An issue or pull request that requires more info or actions from the author. label Dec 7, 2022
@kunalspathak
Copy link
Member

genStoreLclTypeSIMD12() was just missing a case for a scenario where targetReg (the destination register for STORE_LCL_VAR) is not REG_NA. In this case, it is xmm1 and for such, we should just do the move and no need to store the variable on stack. Of course, if we are doing a mov, we need to also genProduceReg() which will update the life of V01.

@kunalspathak
Copy link
Member

/azp run runtime-coreclr jitstress

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@kunalspathak
Copy link
Member

Pushed fixes at other places where we were not tracking the liveness of treeNode during genCodeForStoreLclVar() and genCodeForStoreLclFld() on both x64 and arm64.

@kunalspathak
Copy link
Member

If jitstress looks ok, we should also kick off gcstress @BrianBohe

@BrianBohe
Copy link
Member Author

/azp run runtime-coreclr jitstress

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@BrianBohe BrianBohe force-pushed the fixing_assert_on_variablelive_simd12 branch from 69e6182 to 154ac7a Compare December 8, 2022 21:09
@BrianBohe
Copy link
Member Author

/azp run runtime-coreclr jitstress

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

Copy link
Contributor

@BruceForstall BruceForstall left a comment

Choose a reason for hiding this comment

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

LGTM.

Are there any asm diffs? It would be nice to summarize interesting examples here.

@kunalspathak
Copy link
Member

LGTM.

Are there any asm diffs? It would be nice to summarize interesting examples here.

The only difference is in coreclr_tests for the test case that was failing.

image

Here is the diff which removes the extra store on stack.

image

@BrianBohe
Copy link
Member Author

Errors are CI infrastructure related (timeouts) or unrelated

@BrianBohe BrianBohe merged commit 0b7fd63 into dotnet:main Dec 9, 2022
@ghost ghost locked as resolved and limited conversation to collaborators Jan 9, 2023
@BrianBohe BrianBohe deleted the fixing_assert_on_variablelive_simd12 branch February 10, 2023 23:07
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.

Test failure JIT\\Regression\\JitBlue\\Runtime_63354\\Runtime_63354\\Runtime_63354.cmd
3 participants