-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
Revisit code that updates loops before block removal #68844
Comments
I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label. |
@dotnet/jit-contrib , @BruceForstall |
Tagging subscribers to this area: @JulieLeeMSFT Issue DetailsWhile working on #68803 to fix #68756, we encountered several issues about how we track and update loop tables around block that we will remove. We should revisit the logic in
Later, we also iterate through all the blocks, one of them being the preheader that we want to eliminate. We think that it is not part of a loop (because of reason mentioned above) but then see that runtime/src/coreclr/jit/optimizer.cpp Lines 509 to 512 in 4cd4cff
|
I think we should enable the code that always creates loop pre-headers when doing loop recognition (you could consider it part of loop canonicalization), and prevents removing empty pre-headers through optimization, finally letting them be removed late in compilation if they are empty. This would mean there's no need to on-demand create them, which invalidates bbNum sequential ordering and thus dominators. |
Thanks @BruceForstall. Whenever you get a chance, can you publish a draft PR of whatever changes you have so far for "always create loop pre-headers"? I can iterate on top of it to solve this problem. |
This code no longer exists |
While working on #68803 to fix #68756, we encountered several issues about how we track and update loop tables around block that we will remove. We should revisit the logic in
optUpdateLoopsBeforeRemoveBlock()
.lpContains()
method relies onbbNum
to determine if something is present in loop or not. Below is the code that is used to determine if a block is present in loop or not, but newer added blocks might have higherbbNum
and can falsely claim that the block is not in the loop.runtime/src/coreclr/jit/optimizer.cpp
Lines 515 to 518 in 4cd4cff
optUpdateLoopsBeforeRemoveBlock()
and decide if the loop should also be removed or not.runtime/src/coreclr/jit/optimizer.cpp
Lines 466 to 467 in 4cd4cff
Later, we also iterate through all the blocks, one of them being the preheader that we want to eliminate. We think that it is not part of a loop (because of reason mentioned above) but then see that
auxBlock->bbJumpDest == loop.lpEntry
and reset the flag saying we do not have to remove the loop. Here, we assume that there was a predecessor outside the loop, but never verify ifauxBlock == block
.runtime/src/coreclr/jit/optimizer.cpp
Lines 509 to 512 in 4cd4cff
loop.lpHead == block
and if yes, we should update theloop.lpHead
to point to the predecessor ofblock
we are trying to remove.loopHead
in certain cases, butbbPrev
might not be the right block we should set, but should be a predecesssor if possible. If we just addassert(block->bbPrev->KindIs(BBJ_NONE, BBJ_ALWAYS))
, we would see thatBBJ_THROW
orBBJ_RETURN
blocks are getting set aslpHead
of a loop. This portion needs to be revisited as well.runtime/src/coreclr/jit/optimizer.cpp
Lines 565 to 570 in 4cd4cff
category:implementation
theme:loop-opt
skill-level:expert
cost:medium
impact:medium
The text was updated successfully, but these errors were encountered: