Skip to content

JIT: revised fix for fp division issue in profile synthesis #115005

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
merged 1 commit into from
Apr 24, 2025

Conversation

AndyAyersMS
Copy link
Member

The previous fix #113396 could still leave us trying to evaluate 0.0/0.0, which causes an invalid FP operation exception.

Make sure the divisor is non-zero.

The previous fix dotnet#113396 could still leave us trying to evaluate 0.0/0.0,
which causes an invalid FP operation exception.

Make sure the divisor is non-zero.
@Copilot Copilot AI review requested due to automatic review settings April 24, 2025 17:43
@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 Apr 24, 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 revises the fix for an FP division issue in profile synthesis to ensure that a division by an extremely small value (or zero) is avoided.

  • Replaces previous conditional logic with a call to max(oldWeight, 1e-12).
  • Simplifies the calculation of blockRelResidual using a lower bound threshold.
Comments suppressed due to low confidence (1)

src/coreclr/jit/fgprofilesynthesis.cpp:1394

  • Ensure that the use of max() correctly handles cases where oldWeight might be negative, if such cases are possible, to prevent unintended behavior.
weight_t const blockRelResidual = change / max(oldWeight, 1e-12);

@AndyAyersMS
Copy link
Member Author

@dotnet/jit-contrib PTAL

No diffs. Verified a port of this to 9.0 fixes the issue.

Copy link
Contributor

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

Copy link
Member

@EgorBo EgorBo left a comment

Choose a reason for hiding this comment

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

curious if you could use FLT_MIN from include <float.h> but looks like it doesn't make much sense

@AndyAyersMS
Copy link
Member Author

curious if you could use FLT_MIN from include <float.h> but looks like it doesn't make much sense

Yeah we don't want to divide by anything super-small, just small.

@AndyAyersMS AndyAyersMS merged commit 45a4cc2 into dotnet:main Apr 24, 2025
109 checks passed
@AndyAyersMS
Copy link
Member Author

/backport to release/9.0-staging

Copy link
Contributor

Started backporting to release/9.0-staging: https://github.com/dotnet/runtime/actions/runs/14653363543

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.

2 participants