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

JIT: fgRemoveBlock does not maintain edge weights #96614

Closed
jakobbotsch opened this issue Jan 8, 2024 · 4 comments
Closed

JIT: fgRemoveBlock does not maintain edge weights #96614

jakobbotsch opened this issue Jan 8, 2024 · 4 comments
Assignees
Labels
area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI
Milestone

Comments

@jakobbotsch
Copy link
Member

jakobbotsch commented Jan 8, 2024

This code drops the old edge and weight on it:

fgRemoveRefPred(succBlock, block);

If we have blocks A -> B -> C, with an empty B, then we should end up with the same result whether we compact B into C or whether we just remove B. However, currently we drop the A -> B weight if we remove B:

BB02 [0085]  2       BB01,BB36             1    211  0 [???..???)-> BB13 ( cond )                     IBC internal Loop loopheader 
BB03 [0087]  1       BB02                  0.42  88  0 [01D..???)-> BB04 (always)                     IBC internal LoopPH q
BB04 [0002]  2       BB03,BB12             0.55 117  1 [01D..02D)-> BB41 ( cond )                     i IBC Loop bwd bwd-target loopheader 
...
Setting edge weights for BB02 -> BB03 to [88.48387 .. 88.48387]
...
fgRemoveBlock BB03, unreachable=false
Removing empty BB03
Setting edge weights for BB02 -> BB04 to [0 .. 117] // not the right weight

When removing B, should the weight on A -> C be inherited from A -> B?

There's probably a ton of these in the JIT, but I figured I would open an issue since I saw it be the cause of diffs. (Also, maybe the fact that B -> C is not already the same as A -> B is a problem in maintenance in and of itself, so maybe the issue exists elsewhere.)

out_base.txt (jitdump with fgRemoveBlock)
out.txt (jitdump with compaction)

@ghost ghost added the untriaged New issue has not been triaged by the area owner label Jan 8, 2024
@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 Jan 8, 2024
@ghost
Copy link

ghost commented Jan 8, 2024

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

Issue Details

This code drops the old edge and weight on it:

fgRemoveRefPred(succBlock, block);

If we have blocks A -> B -> C, with an empty B, then we should end up with the same result whether we compact B into C or whether we just remove B. However, currently we drop the A -> B weight if we remove B:

BB02 [0085]  2       BB01,BB36             1    211  0 [???..???)-> BB13 ( cond )                     IBC internal Loop loopheader 
BB03 [0087]  1       BB02                  0.42  88  0 [01D..???)-> BB04 (always)                     IBC internal LoopPH q
BB04 [0002]  2       BB03,BB12             0.55 117  1 [01D..02D)-> BB41 ( cond )                     i IBC Loop bwd bwd-target loopheader 
...
Setting edge weights for BB02 -> BB03 to [88.48387 .. 88.48387]
...
fgRemoveBlock BB03, unreachable=false
Removing empty BB03
Setting edge weights for BB02 -> BB04 to [0 .. 117] // not the right weight

When removing B, should the weight on A -> C be inherited from A -> B?

There's probably a ton of these in the JIT, but I figured I would open an issue since I saw it be the cause of diffs. (Also, maybe the fact that B -> C is not already the same as A -> B is a problem in maintenance in and of itself, so maybe the issue exists elsewhere.)

Author: jakobbotsch
Assignees: -
Labels:

area-CodeGen-coreclr, untriaged

Milestone: -

@JulieLeeMSFT JulieLeeMSFT added this to the 9.0.0 milestone Jan 13, 2024
@ghost ghost removed the untriaged New issue has not been triaged by the area owner label Jan 13, 2024
@AndyAyersMS
Copy link
Member

Not sure we can do much here just yet, since either the incoming profile is already consistent (which we can locally check) and so no adjustment should be needed, or else we're making it inconsistent which likely indicates a problem elsewhere.

Once we have consistency checking enabled deeper into the jit we should run across and fix those elsewhere cases and can add a suitable assert here.

@AndyAyersMS
Copy link
Member

Going to move this out of 9.0, since it depends on other work that is now opportunistic.

@jakobbotsch
Copy link
Member Author

Going to close this given Andy's comments above, since this should be naturally caught and resolved as consistency checking gets enabled for more and more phases.

@jakobbotsch jakobbotsch closed this as not planned Won't fix, can't repro, duplicate, stale Dec 13, 2024
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

No branches or pull requests

3 participants