Skip to content

Ensure that we don't try to constant fold BSF(0) or BSR(0)#81516

Merged
tannergooding merged 4 commits intodotnet:mainfrom
tannergooding:fix-81460
Feb 2, 2023
Merged

Ensure that we don't try to constant fold BSF(0) or BSR(0)#81516
tannergooding merged 4 commits intodotnet:mainfrom
tannergooding:fix-81460

Conversation

@tannergooding
Copy link
Member

@tannergooding tannergooding commented Feb 2, 2023

This resolves #81460

Even with the qmark (x == 0) ? 31 : BSR(x), we'd end up getting something like:

lcl = 0;
if (lcl == 0)
   return 31;
return BSR(lcl);

So even though the BSF(0)/BSR(0) is dead code, we don't know it yet and it leads to VN trying to fold and therefore triggering the assert.

The fix is to simply bail out if the constant is zero.

@ghost ghost added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label Feb 2, 2023
@ghost ghost assigned tannergooding Feb 2, 2023
@ghost
Copy link

ghost commented Feb 2, 2023

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

Issue Details

This resolves #81460

Even with the qmark, we'd end up getting something like:

lcl = 0;
if (lcl == 0)
   return 31;
return BSR(lcl);

So even though the BSF(0)/BSR(0) is dead code, we don't know it yet and it leads to VN trying to fold and therefore triggering the assert.

The fix is to simply bail out if the constant is zero.

Author: tannergooding
Assignees: -
Labels:

area-CodeGen-coreclr

Milestone: -

@tannergooding
Copy link
Member Author

There is potentially something here to be handled in the future in that we are doing VN on things which are "dead".

If we had some minimal early constant propagation or similar, we could avoid doing VN/CSE/folding or other potentially expensive things for code that will just be dropped in one of the next few phases.

@tannergooding
Copy link
Member Author

Brought in latest main to pickup the CI fix

@tannergooding tannergooding merged commit 4354abd into dotnet:main Feb 2, 2023
@tannergooding tannergooding deleted the fix-81460 branch February 2, 2023 05:46
@ghost ghost locked as resolved and limited conversation to collaborators Mar 4, 2023
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.

Assertion failed 'value != 0' in 'System.Tests.DoubleTests_GenericMath:GetExponentShortestBitLengthTest()' during 'Do value numbering'

2 participants