Skip to content
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

Fix issues with EH in unexecuted loops #82329

Merged
merged 1 commit into from
Feb 22, 2023

Conversation

BruceForstall
Copy link
Member

Fix two problems with code in loops that are determined to not execute that have exception handling clauses:

  1. Be more specific in loop unrolling to avoid unrolling even zero-count loops (which causes the loop to be removed) if there is a block in the loop with a different handler region than the handler region of the "top" block. This should only kick in for x86, where handlers are not extracted as funclets.
  2. In Value Numbering, before actually value numbering nodes, optComputeLoopSideEffectsOfBlock() walks all the blocks of all top-level loops collecting data. Unfortunately, it sets the Value Number of certain nodes as a way to pass information "up the tree" during processing. Presumably these "fake" value numbers actually get replaced during actual value numbering for the tree. However, when we go to actually value number the IR, we only walk reachable blocks. Thus, in some cases, we would end up with a top-level "fake" value number on an unreachable statement root, thus leading fgDebugCheckExceptionSets() to check the tree and assert. To fix this, at the end of the optComputeLoopSideEffectsOfBlock(), clear the VN in case it was previously set.

Fixes #81675

@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 Feb 18, 2023
@ghost ghost assigned BruceForstall Feb 18, 2023
@ghost
Copy link

ghost commented Feb 18, 2023

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

Issue Details

Fix two problems with code in loops that are determined to not execute that have exception handling clauses:

  1. Be more specific in loop unrolling to avoid unrolling even zero-count loops (which causes the loop to be removed) if there is a block in the loop with a different handler region than the handler region of the "top" block. This should only kick in for x86, where handlers are not extracted as funclets.
  2. In Value Numbering, before actually value numbering nodes, optComputeLoopSideEffectsOfBlock() walks all the blocks of all top-level loops collecting data. Unfortunately, it sets the Value Number of certain nodes as a way to pass information "up the tree" during processing. Presumably these "fake" value numbers actually get replaced during actual value numbering for the tree. However, when we go to actually value number the IR, we only walk reachable blocks. Thus, in some cases, we would end up with a top-level "fake" value number on an unreachable statement root, thus leading fgDebugCheckExceptionSets() to check the tree and assert. To fix this, at the end of the optComputeLoopSideEffectsOfBlock(), clear the VN in case it was previously set.

Fixes #81675

Author: BruceForstall
Assignees: -
Labels:

area-CodeGen-coreclr

Milestone: -

Fix two problems with code in loops that are determined to not execute
that have exception handling clauses:
1. Be more specific in loop unrolling to avoid unrolling even zero-count
loops (which causes the loop to be removed) if there is a block in the
loop with a different handler region than the handler region of the "top"
block. This should only kick in for x86, where handlers are not extracted
as funclets.
2. In Value Numbering, before actually value numbering nodes,
`optComputeLoopSideEffectsOfBlock()` walks all the blocks of all top-level
loops collecting data. Unfortunately, it sets the Value Number of certain
nodes as a way to pass information "up the tree" during processing. Presumably
these "fake" value numbers actually get replaced during actual value numbering
for the tree. However, when we go to actually value number the IR, we only
walk reachable blocks. Thus, in some cases, we would end up with a top-level
"fake" value number on an unreachable statement root, thus leading
`fgDebugCheckExceptionSets()` to check the tree and assert. To fix this,
at the end of the `optComputeLoopSideEffectsOfBlock()`, clear the VN in case
it was previously set.

Fixes dotnet#81675
@BruceForstall
Copy link
Member Author

@AndyAyersMS @jakobbotsch PTAL
cc @dotnet/jit-contrib

@BruceForstall BruceForstall merged commit 85ed809 into dotnet:main Feb 22, 2023
@BruceForstall BruceForstall deleted the Fix81675 branch February 22, 2023 18:43
@ghost ghost locked as resolved and limited conversation to collaborators Mar 24, 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.

[Fuzzlyn] Jump into the middle of handler region
2 participants