Skip to content

Commit c9f3288

Browse files
committed
Reland "[CodeGen] Fix unconditional branch duplication issue in bbsections"
Reverted in 4c8d056 because it broke buildbot `llvm-clang-x86_64-expensive-checks-debian` due to the AArch64 test generating invalid code. The issue still exists, but it's fixed in D156767, so the AArch64 test should be added there. Differential Revision: https://reviews.llvm.org/D158674
1 parent 6021c78 commit c9f3288

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

llvm/lib/CodeGen/BasicBlockSections.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,8 @@ void llvm::sortBasicBlocksAndUpdateBranches(
258258
[[maybe_unused]] const MachineBasicBlock *EntryBlock = &MF.front();
259259
SmallVector<MachineBasicBlock *> PreLayoutFallThroughs(MF.getNumBlockIDs());
260260
for (auto &MBB : MF)
261-
PreLayoutFallThroughs[MBB.getNumber()] = MBB.getFallThrough();
261+
PreLayoutFallThroughs[MBB.getNumber()] =
262+
MBB.getFallThrough(/*JumpToFallThrough=*/false);
262263

263264
MF.sort(MBBCmp);
264265
assert(&MF.front() == EntryBlock &&

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
; RUN: llc < %s -mtriple=x86_64-unknown-linux-gnu -split-machine-functions -mfs-psi-cutoff=0 -mfs-count-threshold=2000 | FileCheck %s --dump-input=always -check-prefixes=MFS-OPTS1,MFS-OPTS1-X86
77
; RUN: llc < %s -mtriple=x86_64-unknown-linux-gnu -split-machine-functions -mfs-psi-cutoff=950000 | FileCheck %s -check-prefixes=MFS-OPTS2,MFS-OPTS2-X86
88
; RUN: llc < %s -mtriple=x86_64-unknown-linux-gnu -split-machine-functions -mfs-split-ehcode | FileCheck %s -check-prefixes=MFS-EH-SPLIT,MFS-EH-SPLIT-X86
9+
; RUN: llc < %s -mtriple=x86_64 -split-machine-functions -O0 -mfs-psi-cutoff=0 -mfs-count-threshold=10000 | FileCheck %s -check-prefixes=MFS-O0,MFS-O0-X86
910

1011
; RUN: llc < %s -mtriple=aarch64-unknown-linux-gnu -enable-split-machine-functions -mfs-allow-unsupported-triple | FileCheck %s -check-prefixes=MFS-DEFAULTS,MFS-DEFAULTS-AARCH64
1112
; RUN: llc < %s -mtriple=aarch64-unknown-linux-gnu -enable-split-machine-functions -mfs-allow-unsupported-triple -mfs-psi-cutoff=0 -mfs-count-threshold=2000 | FileCheck %s --dump-input=always -check-prefixes=MFS-OPTS1,MFS-OPTS1-AARCH64
@@ -462,6 +463,29 @@ define void @foo15(i1 zeroext %0, i1 zeroext %1) nounwind !prof !27 {
462463
ret void
463464
}
464465

466+
define void @foo16(i1 zeroext %0) nounwind !prof !14 !section_prefix !15 {
467+
;; Check that an unconditional branch is only appended to a block
468+
;; if it would fall through to the wrong block otherwise.
469+
; MFS-O0-LABEL: foo16
470+
; MFS-O0-X86: jmp
471+
; MFS-O0-X86-NOT: jmp
472+
; MFS-O0-AARCH64: br
473+
; MFS-O0-AARCH64: br
474+
; MFS-O0-AARCH64-NOT: br
475+
; MFS-O0: .section .text.split.foo16
476+
; MFS-O0-NEXT: foo16.cold
477+
%2 = call i32 @baz()
478+
br i1 false, label %3, label %5, !prof !25
479+
480+
3: ; preds = %1
481+
%4 = call i32 @bar()
482+
unreachable
483+
484+
5: ; preds = %1
485+
%6 = tail call i32 @qux()
486+
ret void
487+
}
488+
465489
declare i32 @bar()
466490
declare i32 @baz()
467491
declare i32 @bam()

0 commit comments

Comments
 (0)