Skip to content

Conversation

jkotas
Copy link
Member

@jkotas jkotas commented May 19, 2025

vzeroupper is AVX instruction and so it cannot be executed unconditionally in static asm helpers

Fixes #115672

@Copilot Copilot AI review requested due to automatic review settings May 19, 2025 22:09
@jkotas jkotas requested a review from MichalStrehovsky as a code owner May 19, 2025 22:09
@jkotas jkotas added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label May 19, 2025
Copy link
Contributor

@Copilot Copilot AI left a comment

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 shifts the emission of the VZEROUPPER AVX instruction from static assembly helpers into the JIT pipeline, ensuring it’s only generated when needed.

  • Removed unconditional vzeroupper from various static ASM/S assembly helper prologs and epilogs.
  • Introduced genClearAvxStateProlog and genClearAvxStateEpilog in the JIT to emit vzeroupper conditionally.
  • Updated calls to preserve/restore callee-saved float registers to use new parameterless signatures.

Reviewed Changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated no comments.

Show a summary per file
File Description
vm/amd64/asmhelpers.S Removed vzeroupper in static helper macros
vm/amd64/AsmHelpers.asm Removed duplicate vzeroupper in assembly prologs
nativeaot/Runtime/amd64/ExceptionHandling.asm Removed vzeroupper from native AOT funclet helpers
nativeaot/Runtime/amd64/ExceptionHandling.S Same removal in .S variant
jit/codegenxarch.cpp Added JIT hooks (genClearAvxState*) and refactored preserve/restore calls
jit/codegencommon.cpp Inserted genClearAvxStateProlog before float-reg save
jit/codegen.h Declared new clear-state methods and updated signatures
Comments suppressed due to low confidence (2)

src/coreclr/jit/codegencommon.cpp:5288

  • The new genClearAvxStateProlog branch logic (checking ContainsCallNeedingVzeroupper vs. Contains256bitOrMoreAVX) should have unit or integration tests to validate both code paths emit (or skip) vzeroupper as expected.
    genClearAvxStateProlog();

src/coreclr/jit/codegenxarch.cpp:11040

  • There are two calls to genClearAvxStateProlog() in the same genFuncletProlog implementation (around lines 10918 and 11040). Consider consolidating to a single insertion point to avoid duplicated VZEROUPPER emission.
    genClearAvxStateProlog();

@am11

This comment was marked as resolved.

@dotnet-policy-service
Copy link
Contributor

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

vzeroupper is AVX instruction and so it cannot be executed unconditionally in static asm helpers

Fixes dotnet#115672
int shiftByValue = (int)shiftBy->AsIntConCommon()->IconValue();

if (tree->OperIsRotate() && compiler->compOpportunisticallyDependsOn(InstructionSet_BMI2) && !tree->gtSetFlags())
if (tree->OperIsRotate() && compiler->compOpportunisticallyDependsOn(InstructionSet_BMI2) &&
Copy link
Member Author

Choose a reason for hiding this comment

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

Changes from jit format

@jkotas
Copy link
Member Author

jkotas commented May 20, 2025

/ba-g unrelated timeout

@jkotas jkotas merged commit a9114e3 into dotnet:main May 20, 2025
106 of 108 checks passed
@jkotas jkotas deleted the 115019 branch May 20, 2025 03:21
@github-actions github-actions bot locked and limited conversation to collaborators Jun 19, 2025
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.

[NETSDKE2E][ARM64][VMR]Using .NET 10 Preview 5 x64 SDK on ARM64 OS causes ".NET Host has stopped working" error.

3 participants