This is an archive of the discontinued LLVM Phabricator instance.

[AArch64] Move branch relaxation after bbsection assignment
ClosedPublic

Authored by dhoekwater on Jun 26 2023, 6:44 PM.

Details

Summary

Because branch relaxation needs to factor in if branches target
a block in the same section or a different one, it needs to run
after the Basic Block Sections / Machine Function Splitting passes.

Because Jump table compression relies on block offsets remaining
fixed after the table is compressed, we must also move the JT
compression pass.

Diff Detail

Event Timeline

dhoekwater created this revision.Jun 26 2023, 6:44 PM
Herald added a project: Restricted Project. · View Herald TranscriptJun 26 2023, 6:44 PM

Rename the pass name and give it descriptive documentation.

Update a couple tests to account for RenumberBlocks not having run yet.

Remove FIXMEs. We probably will want to rename preEmitPass functions to something
more reflective of the functions' purposes.

dhoekwater published this revision for review.Jun 28 2023, 2:01 PM
Herald added a project: Restricted Project. · View Herald TranscriptJun 28 2023, 2:01 PM
arsenm added inline comments.Jun 29 2023, 11:26 AM
llvm/include/llvm/CodeGen/TargetPassConfig.h
443

This is quite the claim, given that the wonderfully named "addPreEmitPass2" already exist

444

I don't understand this, how can such a restriction exist on the use of this?

dhoekwater added inline comments.Jun 29 2023, 12:01 PM
llvm/include/llvm/CodeGen/TargetPassConfig.h
443

I assumed that because addPreEmitPass2 happens after branch relaxation on AArch64 that it’s true on other targets, but ARM shows that’s not true. I’ll have to update this to loosen the guarantees to “happens after basic block sections are assigned”.

444

It can’t for the same reasons that your other comment addresses, so I’ll have to remove this. I named and documentation this function as I did to convey some of the invariants of the pipeline at the point they’re called, but now I’m confused. Are there _any_ guarantees between addPreEmitPass and addPreEmitPass2 other than Pass 2 happening after pass 1?

Modify function name and documentation to loosen its guarantees.

Because targets can perform instruction insertion wherever they
like, we can't guarantee that this is a safe place to perform
branch relaxation for all targets.

Make sure to push *all* changes.

dhoekwater marked 2 inline comments as done.Jun 30 2023, 4:27 PM
dhoekwater added inline comments.
llvm/include/llvm/CodeGen/TargetPassConfig.h
444

Thanks for the feedback; the updated function name and documentation should be more accurate, if a little nondescript.

Please run git clang-format HEAD~ to format the code.

llvm/test/CodeGen/AArch64/jti-correct-datatype.mir
1 ↗(On Diff #536475)

is this the next pass that would have run after branch-relaxation before this change?

dhoekwater updated this revision to Diff 542616.EditedJul 20 2023, 11:43 AM

Format code and remove changes to unaffected tests

Turns out one of those tests was necessary.

arsenm accepted this revision.Jul 20 2023, 4:56 PM

Not sure I follow how the test changes capture this but seems fine

llvm/test/DebugInfo/AArch64/fallthrough-branch.ll
10

How did this test escape opaquification?

This revision is now accepted and ready to land.Jul 20 2023, 4:56 PM
dhoekwater marked an inline comment as done.Jul 21 2023, 1:25 PM
dhoekwater added inline comments.
llvm/test/CodeGen/AArch64/jti-correct-datatype.mir
1 ↗(On Diff #536475)

Short answer: it turns out I don't actually need to modify this test, so I'm removing the change from the patch.

Long answer:
Before this change, aarch64-jump-tables isn't the next pass that would have run after branch-relaxation, but it is the next pass that modifies jump table datatypes. IIUC, this test applies to the jump compression pass and CodeGen passes afterwards, so starting it before aarch64-jump-tables should be alright.

llvm/test/DebugInfo/AArch64/fallthrough-branch.ll
10

It's not exactly self-documenting, that's for sure.

This revision was automatically updated to reflect the committed changes.
dhoekwater marked an inline comment as done.