Skip to content
This repository was archived by the owner on Jun 26, 2020. It is now read-only.

WIP: Re-fold basic-block split edges in regalloc#950

Closed
sstangl wants to merge 3 commits intobytecodealliance:masterfrom
sstangl:branch-splitting-folding
Closed

WIP: Re-fold basic-block split edges in regalloc#950
sstangl wants to merge 3 commits intobytecodealliance:masterfrom
sstangl:branch-splitting-folding

Conversation

@sstangl
Copy link
Contributor

@sstangl sstangl commented Aug 27, 2019

This patch unregresses the extra jumps in the codegen introduced by basic-block branch splitting.

This is a simpler version of the fold-redundant-branches code that is much easier to get correct. The issue with the previous pass was that some ebbs were functioning as phi nodes in the CFG, and those blocks were not actually redundant. This patch only considers blocks that were added specifically by regalloc (in nbp's branch-splitting patch), therefore none of the blocks are effective phis, and they're formed predictably.

This is a WIP patch. If this looks good, I'll muddle through data structures to clean it up. In particular, deleting an ebb means that we need to update the Liveness struct -- currently, it just recomputes the entire data structure, but it's possible that I could update the bforest to support deletion. Although with trees, that's fairly error-prone.

At this point, just soliciting comments.

@sstangl sstangl requested a review from nbp August 27, 2019 20:29
@julian-seward1
Copy link
Collaborator

@sstangl: [..] it's possible that I could update the bforest to support deletion [..]

Just to note .. it seems at least moderately likely that I'll have to get my head around the bforest machinery as part of my (so far ineffective) attempts to reduce CL's run time. If that happens, I could maybe hack up the changes you need.

@bnjbvr
Copy link
Member

bnjbvr commented Aug 28, 2019

Just as an aside, could you please git rebase on top of master? This PR includes many unrelated commits, making it hard to see what's going on.

TODO: It would be better to avoid recomputing the liveness.
FIXME: I commented-out the binemit/relaxation.rs code that does folding.
@sstangl
Copy link
Contributor Author

sstangl commented Aug 28, 2019

Unfortunately it applies to nbp's "branch-splitting" branch, not to master. I deleted all the commits that are between "branch-splitting" and the changes I made.

This patch won't actually compile, because it depends on Function::change_branch_destination(), which doesn't exist on 'branch-splitting'.

@nbp
Copy link
Collaborator

nbp commented Aug 30, 2019

I am going to merge the branch-splitting branch soon. Otherwise, you could target the branch-splitting branch on my repository to reduce the diff, my branch recently merged from master and should not have a larger diff.

Copy link
Collaborator

@nbp nbp left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am much more in favor of keeping branch folding of empty blocks, even if this has to be restricted to cases where there is no branch parameter first than making it a special phased tied to branch splitting.

This graph transformation is useful even when branch splitting is not used.

domtree: &mut DominatorTree,
topo: &mut TopoOrder,
) {
) -> Vec<Ebb> {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at the rest of the Cranelift phases, usually it seems that these values are provided at a &mut as argument of the run command instead of returned from the run function. Then the clear function of the register allocator is used to clean the content of the vector, to be reused without reallocation for the next compiled function.

// Pass: undo branch splitting where the inserted blocks were not
// used by the register allocator.
#[cfg(feature = "basic-blocks")]
branch_folding::run(func, cfg, domtree, new_blocks);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still think this belongs to the branch relaxation part of the code. Doing so as part of the branch relaxation would avoid recomputing the liveness information.

// Pass the ebb_jump_params in the parent_jump_params.
// No rewriting is needed, because the edge ebb is parameterless.
debug_assert!(_parent_jump_params.len() == 0);
debug_assert!(func.dfg.num_ebb_params(ebb) == 0);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From my understanding this is the only thing to be added to the version which is currently merged. Just excluding any blocks with parameters would avoid the issue we have with folding empty branches without even looking at the branch splitting case.

@nbp
Copy link
Collaborator

nbp commented Sep 5, 2019

Close the pull-request as it is replaced by #972.

@nbp nbp closed this Sep 5, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants