aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/CodeGen/BasicBlockSections.cpp
diff options
context:
space:
mode:
authorDaniel Hoekwater <hoekwater@google.com>2023-08-21 16:29:02 +0000
committerDaniel Hoekwater <hoekwater@google.com>2023-08-24 16:22:55 +0000
commit994eb5adc40cd001d82d0f95d18d1827b57e496c (patch)
tree3f0526469002be9ad96d1e26f198e8ec55b170a8 /llvm/lib/CodeGen/BasicBlockSections.cpp
parent4ad89131e0de9368bc41395d770e1923366deba1 (diff)
downloadllvm-994eb5adc40cd001d82d0f95d18d1827b57e496c.zip
llvm-994eb5adc40cd001d82d0f95d18d1827b57e496c.tar.gz
llvm-994eb5adc40cd001d82d0f95d18d1827b57e496c.tar.bz2
[CodeGen] Fix unconditional branch duplication issue in bbsections
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... */ ``` Differential Revision: https://reviews.llvm.org/D158674
Diffstat (limited to 'llvm/lib/CodeGen/BasicBlockSections.cpp')
-rw-r--r--llvm/lib/CodeGen/BasicBlockSections.cpp3
1 files changed, 2 insertions, 1 deletions
diff --git a/llvm/lib/CodeGen/BasicBlockSections.cpp b/llvm/lib/CodeGen/BasicBlockSections.cpp
index 33e70b1..de7c170 100644
--- a/llvm/lib/CodeGen/BasicBlockSections.cpp
+++ b/llvm/lib/CodeGen/BasicBlockSections.cpp
@@ -258,7 +258,8 @@ void llvm::sortBasicBlocksAndUpdateBranches(
[[maybe_unused]] const MachineBasicBlock *EntryBlock = &MF.front();
SmallVector<MachineBasicBlock *> PreLayoutFallThroughs(MF.getNumBlockIDs());
for (auto &MBB : MF)
- PreLayoutFallThroughs[MBB.getNumber()] = MBB.getFallThrough();
+ PreLayoutFallThroughs[MBB.getNumber()] =
+ MBB.getFallThrough(/*JumpToFallThrough=*/false);
MF.sort(MBBCmp);
assert(&MF.front() == EntryBlock &&