Skip to content

Loop opts should not be recomputing pred lists from scratch #49030

Closed

Description

@AndyAyersMS

Several loop opts end up calling fgUpdateChangedFlowGraph when done, and this calls fgComputePreds, leaking previous pred lists and losing the profile weights carefully calculated earlier.

This seems wrong-headed; I think those optimizations should maintain pred lists and not rebuild them.

Removing the call to fgComputePreds shows a number of places in loop opts where pred lists are not properly updated, and more downstream failures from places unknown where BBF_JMP_TARGET is not properly set, so cleaning this up may be nontrivial.

category:cq
theme:loop-opt
skill-level:expert
cost:medium
impact:medium

Activity

  1. ghost added
    untriaged
    on Mar 2, 2021
  2. AndyAyersMS commented on Mar 2, 2021

    @AndyAyersMS
    MemberAuthor

    See notes in #48850 for some context.

  3. AndyAyersMS commented on Mar 2, 2021

    @AndyAyersMS
    MemberAuthor
  4. added
    area-CodeGen-coreclr
    and removed
    untriaged
    on Mar 2, 2021
  5. self-assigned this
    on Mar 3, 2021
  6. added this to the 6.0.0 milestone on Mar 3, 2021
  7. BruceForstall commented on Mar 3, 2021

    @BruceForstall
    Contributor

    We used to always need to rebuild pred lists after renumbering blocks due to pred list ordering being dependent on block number, so presumably phases knew they could be sloppy and things would get cleaned up later. But with the new ensurePredListOrder()/reorderPredList(), that's no longer required, as renumbering also keeps preds lists properly ordered.

    Maybe we need a pred list checker that runs fgComputePreds but doesn't update the IR, and compares the results against the existing flowgraph (does such a thing exist already?), then fgUpdateChangedFlowGraph can call the checker to verify that no preds need to be updated, and if that check fails, we know which phase caused the problem.

  8. AndyAyersMS commented on Mar 3, 2021

    @AndyAyersMS
    MemberAuthor

    I get post-phase check failures about missing preds if I remove the call to fgComputePreds so I think the current checking may be sufficient?

    The missing jump target flags might be harder to track down; it's not clear if we have agreement about when the jump target bit needs to be set, and we don't seem to check this post phase. It is checked in codegen.

  9. BruceForstall commented on Apr 13, 2021

    @BruceForstall
    Contributor

    I'm thinking we should get rid of BBF_JMP_TARGET entirely and replace its use by BBF_HAS_LABEL for marking blocks that need labels. Then, add a pass over the blocks just before codegen that sets BBF_HAS_LABEL on all necessary blocks, like genPrepForEHCodegen does for EH constructs. Then, we wouldn't need to set and maintain the BBF_JMP_TARGET throughout compilation. We may lose a couple uninteresting asserts but would greatly simplify block maintenance.

  10. AndyAyersMS commented on Apr 13, 2021

    @AndyAyersMS
    MemberAuthor

    Sounds good to me.

  11. BruceForstall commented on Apr 20, 2021

    @BruceForstall
    Contributor

    BBF_JMP_TARGET was removed with #51208

  12. 7 remaining items

  13. modified the milestones: 7.0.0, 8.0.0 on May 26, 2022
  14. ghost added
    in-pr
    on Jan 18, 2023
  15. added a commit that references this issue on Jan 18, 2023
    7f3f5ef
  16. ghost removed
    in-pr
    on Jan 18, 2023
  17. added a commit that references this issue on Jan 24, 2023
    416ca81
  18. ghost locked as resolved and limited conversation to collaborators on Feb 18, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area-CodeGen-coreclr

Type

No type

Projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions