This is an archive of the discontinued LLVM Phabricator instance.

[CodeGen] Fix unconditional branch duplication issue in bbsections
ClosedPublic

Authored by dhoekwater on Aug 23 2023, 2:29 PM.

Details

Summary

If an end section basic block ends in an unconditional branch to its
fallthrough, BasicBlockSections will duplicate the unconditional branch.
This doesn't break x86, but it is a (slight) size optimization and more
importantly prevents AArch64 builds from breaking.

Ex:

bb1 (bbsections Hot):
  jmp bb2

bb2 (bbsections Cold):
  /* do work... */

After running sortBasicBlocksAndUpdateBranches():

bb1 (bbsections Hot):
  jmp bb2
  jmp bb2

bb2 (bbsections Cold):
  /* do work... */

Diff Detail

Event Timeline

dhoekwater created this revision.Aug 23 2023, 2:29 PM
Herald added a project: Restricted Project. · View Herald TranscriptAug 23 2023, 2:29 PM
dhoekwater requested review of this revision.Aug 23 2023, 2:29 PM
Herald added a project: Restricted Project. · View Herald TranscriptAug 23 2023, 2:29 PM
rahmanl accepted this revision.Aug 23 2023, 2:46 PM

Thanks.

llvm/test/CodeGen/Generic/machine-function-splitter.ll
9

Just -mtriple=x86_64 is enough.

This revision is now accepted and ready to land.Aug 23 2023, 2:46 PM