JIT: avoid fp divide by zero in profile synthesis#113396
Merged
AndyAyersMS merged 1 commit intodotnet:mainfrom Mar 12, 2025
Merged
JIT: avoid fp divide by zero in profile synthesis#113396AndyAyersMS merged 1 commit intodotnet:mainfrom
AndyAyersMS merged 1 commit intodotnet:mainfrom
Conversation
This can trip up users that have enabled floating point exceptions. While we don't generally support changing the exception modes we also can easily avoid dividing by zero here. Addresses dotnet#113369
Contributor
|
Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch |
Member
Author
|
@amanasifkhalid PTAL Should be no diff. |
amanasifkhalid
approved these changes
Mar 11, 2025
hez2010
reviewed
Mar 12, 2025
Comment on lines
+1419
to
+1426
| weight_t const smallFractionOfChange = 1e-9 * change; | ||
| weight_t relDivisor = oldWeight; | ||
| if (relDivisor < smallFractionOfChange) | ||
| { | ||
| relDivisor = smallFractionOfChange; | ||
| } | ||
|
|
||
| weight_t const blockRelResidual = change / relDivisor; |
Contributor
There was a problem hiding this comment.
Wondering can't it just be something like weight_t const blockRelResidual = change / (oldWeight + 1e-10)?
Member
Author
There was a problem hiding this comment.
Yeah, that would have worked too.
Member
Author
There was a problem hiding this comment.
Turns out @hez2010 had a better fix. If change is zero we will end up with 0.0 / 0.0 which causes an "invalid FP operation" exception.
Member
Author
|
/backport to release/9.0-staging |
Contributor
|
Started backporting to release/9.0-staging: https://github.com/dotnet/runtime/actions/runs/13814988612 |
4 tasks
AndyAyersMS
added a commit
to AndyAyersMS/runtime
that referenced
this pull request
Apr 24, 2025
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.
AndyAyersMS
added a commit
that referenced
this pull request
Apr 24, 2025
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.
github-actions bot
pushed a commit
that referenced
this pull request
Apr 24, 2025
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.
AndyAyersMS
added a commit
that referenced
this pull request
May 8, 2025
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. Co-authored-by: Andy Ayers <andya@microsoft.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This can trip up users that have enabled floating point exceptions.
While we don't generally support changing the exception modes we also can easily avoid dividing by zero here.
Addresses #113369