Skip to content

Commit 2a03cc8

Browse files
vladimirradosavljevicakiramenai
authored andcommitted
[TailDuplication] Add option to enable tail duplication of fallthrough BBs
During the TailDuplication pass, fallthrough BBs are not duplicated. This is generally acceptable, but in scenarios where a loop contains a large switch case and the latch BB is a fallthrough, duplicating the latch BB can eliminate jump instructions in its predecessors. This patch introduces the `tail-dup-fallthrough-bbs` option to enable the duplication of fallthrough BBs. PR: #727. Signed-off-by: Vladimir Radosavljevic <[email protected]>
1 parent e3e4c2f commit 2a03cc8

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

llvm/lib/CodeGen/TailDuplicator.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,13 @@ static cl::opt<bool>
7676
static cl::opt<unsigned> TailDupLimit("tail-dup-limit", cl::init(~0U),
7777
cl::Hidden);
7878

79+
// EraVM local begin
80+
static cl::opt<bool>
81+
TailDupFallthroughBBs("tail-dup-fallthrough-bbs",
82+
cl::desc("Tail duplicate fallthrough basic blocks"),
83+
cl::init(false), cl::Hidden);
84+
// EraVM local end
85+
7986
void TailDuplicator::initMF(MachineFunction &MFin, bool PreRegAlloc,
8087
const MachineBranchProbabilityInfo *MBPIin,
8188
MBFIWrapper *MBFIin,
@@ -559,8 +566,10 @@ bool TailDuplicator::shouldTailDuplicate(bool IsSimple,
559566
// When doing tail-duplication during layout, the block ordering is in flux,
560567
// so canFallThrough returns a result based on incorrect information and
561568
// should just be ignored.
562-
if (!LayoutMode && TailBB.canFallThrough())
569+
// EraVM local begin
570+
if (!TailDupFallthroughBBs && !LayoutMode && TailBB.canFallThrough())
563571
return false;
572+
// EraVM local end
564573

565574
// Don't try to tail-duplicate single-block loops.
566575
if (TailBB.isSuccessor(&TailBB))

llvm/test/CodeGen/EraVM/tail-dup-fallthrough-bbs.mir

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# NOTE: Assertions have been autogenerated by utils/update_mir_test_checks.py UTC_ARGS: --version 2
2-
# RUN: llc -x mir -run-pass tailduplication -verify-machineinstrs -compile-twice=false < %s | FileCheck %s
2+
# RUN: llc -x mir -run-pass tailduplication -tail-dup-fallthrough-bbs -verify-machineinstrs -compile-twice=false < %s | FileCheck %s
33

44
--- |
55

@@ -15,17 +15,12 @@ tracksRegLiveness: true
1515
body: |
1616
; CHECK-LABEL: name: test
1717
; CHECK: bb.0:
18-
; CHECK-NEXT: successors: %bb.1(0x80000000)
19-
; CHECK-NEXT: liveins: $r1
20-
; CHECK-NEXT: {{ $}}
21-
; CHECK-NEXT: J %bb.1
22-
; CHECK-NEXT: {{ $}}
23-
; CHECK-NEXT: bb.1:
2418
; CHECK-NEXT: successors: %bb.3(0x40000000), %bb.2(0x40000000)
2519
; CHECK-NEXT: liveins: $r1
2620
; CHECK-NEXT: {{ $}}
2721
; CHECK-NEXT: dead $r0 = SUBxrr_v i256 10, $r1, i256 0, implicit-def $flags
28-
; CHECK-NEXT: JCl %bb.3, i256 3, implicit killed $flags
22+
; CHECK-NEXT: JCl %bb.3, 3, implicit $flags
23+
; CHECK-NEXT: J %bb.2
2924
; CHECK-NEXT: {{ $}}
3025
; CHECK-NEXT: bb.2:
3126
; CHECK-NEXT: liveins: $r1

0 commit comments

Comments
 (0)