[llvm] 87c0f67 - [Outliner] Add an option to only enable outlining of patterns above a certain threshold
Nathan Lanza via llvm-commits
llvm-commits at lists.llvm.org
Fri Apr 7 23:13:28 PDT 2023
Author: Nathan Lanza
Date: 2023-04-08T02:12:40-04:00
New Revision: 87c0f6773970f41f0e464690862f05bc109ee8d0
URL: https://github.com/llvm/llvm-project/commit/87c0f6773970f41f0e464690862f05bc109ee8d0
DIFF: https://github.com/llvm/llvm-project/commit/87c0f6773970f41f0e464690862f05bc109ee8d0.diff
LOG: [Outliner] Add an option to only enable outlining of patterns above a certain threshold
Outlining isn't always a win when the saved instruction count is >= 1.
The overhead of representing a new function in the binary depends on
exception metadata and alignment. So parameterize this for local tuning.
Reviewed By: paquette
Differential Revision: https://reviews.llvm.org/D136774
Added:
llvm/test/CodeGen/AArch64/machine-outliner-threshold.mir
Modified:
llvm/lib/CodeGen/MachineOutliner.cpp
Removed:
################################################################################
diff --git a/llvm/lib/CodeGen/MachineOutliner.cpp b/llvm/lib/CodeGen/MachineOutliner.cpp
index 8d72208e8c581..d116c5445e307 100644
--- a/llvm/lib/CodeGen/MachineOutliner.cpp
+++ b/llvm/lib/CodeGen/MachineOutliner.cpp
@@ -116,6 +116,11 @@ static cl::opt<unsigned> OutlinerReruns(
cl::desc(
"Number of times to rerun the outliner after the initial outline"));
+static cl::opt<unsigned> OutlinerBenefitThreshold(
+ "outliner-benefit-threshold", cl::init(1), cl::Hidden,
+ cl::desc(
+ "The minimum size in bytes before an outlining candidate is accepted"));
+
namespace {
/// Maps \p MachineInstrs to unsigned integers and stores the mappings.
@@ -664,7 +669,7 @@ void MachineOutliner::findCandidates(
continue;
// Is it better to outline this candidate than not?
- if (OF->getBenefit() < 1) {
+ if (OF->getBenefit() < OutlinerBenefitThreshold) {
emitNotOutliningCheaperRemark(StringLen, CandidatesForRepeatedSeq, *OF);
continue;
}
@@ -840,7 +845,7 @@ bool MachineOutliner::outline(Module &M,
});
// If we made it unbeneficial to outline this function, skip it.
- if (OF.getBenefit() < 1)
+ if (OF.getBenefit() < OutlinerBenefitThreshold)
continue;
// It's beneficial. Create the function and outline its sequence's
diff --git a/llvm/test/CodeGen/AArch64/machine-outliner-threshold.mir b/llvm/test/CodeGen/AArch64/machine-outliner-threshold.mir
new file mode 100644
index 0000000000000..b3efb29abf5b4
--- /dev/null
+++ b/llvm/test/CodeGen/AArch64/machine-outliner-threshold.mir
@@ -0,0 +1,114 @@
+# RUN: llc -mtriple=aarch64--- -run-pass=machine-outliner -verify-machineinstrs %s -o - | FileCheck %s
+# RUN: llc -mtriple=aarch64--- -outliner-benefit-threshold=10 -run-pass=machine-outliner -verify-machineinstrs %s -o - | FileCheck %s -check-prefix=THRESHOLD
+--- |
+
+ define void @baz() #0 {
+ ret void
+ }
+
+ define void @bar(i32 %a) #0 {
+ ret void
+ }
+
+ attributes #0 = { noredzone }
+...
+---
+# Check that two we outline two
diff erent sequences, one from bb1 and one from
+# bb2 when the threshold is 1.
+# CHECK-LABEL: bb.1:
+# CHECK: BL @OUTLINED_FUNCTION_[[F0:[0-9]+]], implicit-def $lr, implicit $sp
+# CHECK-NEXT: $w11 = ORRWri $wzr, 1
+# CHECK-NEXT: $w11 = ORRWri $wzr, 1
+# CHECK-NEXT: $w11 = ORRWri $wzr, 2
+# CHECK-NEXT: BL @baz, implicit-def dead $lr, implicit $sp
+# CHECK-NEXT: BL @OUTLINED_FUNCTION_[[F0]], implicit-def $lr, implicit $sp
+# CHECK-NEXT: $w11 = ORRWri $wzr, 1
+# CHECK-NEXT: $w11 = ORRWri $wzr, 1
+# CHECK-NEXT: $w8 = ORRWri $wzr, 0
+# CHECK-NOT: $w11 = KILL renamable $w11, implicit killed $w11
+
+# CHECK-LABEL: bb.2:
+# CHECK: BL @OUTLINED_FUNCTION_[[F1:[0-9]+]], implicit-def $lr, implicit $sp
+# CHECK-NEXT: $w9 = ORRWri $wzr, 0
+# CHECK-NEXT: BL @OUTLINED_FUNCTION_[[F1]], implicit-def $lr, implicit $sp
+# CHECK-NEXT: $w8 = ORRWri $wzr, 0
+# CHECK-NOT: $w11 = KILL renamable $w11, implicit killed $w11
+
+# Check that the sequences in bb.2 don't get outlined with a threshold of 10 but
+# the sequences in bb.1 do.
+# THRESHOLD-LABEL: bb.1:
+# THRESHOLD: BL @OUTLINED_FUNCTION_[[F0:[0-9]+]], implicit-def $lr, implicit $sp
+# THRESHOLD-NEXT: $w11 = ORRWri $wzr, 1
+# THRESHOLD-NEXT: $w11 = ORRWri $wzr, 1
+# THRESHOLD-NEXT: $w11 = ORRWri $wzr, 2
+# THRESHOLD-NEXT: BL @baz, implicit-def dead $lr, implicit $sp
+# THRESHOLD-NEXT: BL @OUTLINED_FUNCTION_[[F0]], implicit-def $lr, implicit $sp
+# THRESHOLD-NEXT: $w11 = ORRWri $wzr, 1
+# THRESHOLD-NEXT: $w11 = ORRWri $wzr, 1
+# THRESHOLD-NEXT: $w8 = ORRWri $wzr, 0
+# THRESHOLD-NOT: $w11 = KILL renamable $w11, implicit killed $w11
+
+# THRESHOLD-LABEL: bb.2:
+# THRESHOLD-NOT: BL @OUTLINED_FUNCTION
+name: bar
+tracksRegLiveness: true
+body: |
+ bb.0:
+ liveins: $w0, $lr, $w8
+ $sp = frame-setup SUBXri $sp, 32, 0
+ $fp = frame-setup ADDXri $sp, 16, 0
+
+ bb.1:
+ BL @baz, implicit-def dead $lr, implicit $sp
+ $w11 = ORRWri $wzr, 1
+ $w11 = ORRWri $wzr, 1
+ $w11 = KILL renamable $w11, implicit killed $w11
+ $w11 = ORRWri $wzr, 1
+ $w11 = ORRWri $wzr, 1
+ BL @baz, implicit-def dead $lr, implicit $sp
+ $w11 = ORRWri $wzr, 1
+ $w11 = ORRWri $wzr, 1
+ $w11 = ORRWri $wzr, 2
+ BL @baz, implicit-def dead $lr, implicit $sp
+ $w11 = ORRWri $wzr, 1
+ $w11 = ORRWri $wzr, 1
+ $w11 = ORRWri $wzr, 1
+ $w11 = ORRWri $wzr, 1
+ BL @baz, implicit-def dead $lr, implicit $sp
+ $w11 = ORRWri $wzr, 1
+ $w11 = ORRWri $wzr, 1
+ $w8 = ORRWri $wzr, 0
+
+ bb.2:
+ $w15 = ORRWri $wzr, 1
+ $w15 = ORRWri $wzr, 1
+ $w15 = ORRWri $wzr, 1
+ $w15 = ORRWri $wzr, 1
+ $x15 = ADDXri $sp, 48, 0;
+ $w9 = ORRWri $wzr, 0
+ $w15 = ORRWri $wzr, 1
+ $w15 = ORRWri $wzr, 1
+ $w15 = ORRWri $wzr, 1
+ $w15 = ORRWri $wzr, 1
+ $x15 = ADDXri $sp, 48, 0;
+ $w8 = ORRWri $wzr, 0
+
+ bb.3:
+ $fp, $lr = LDPXi $sp, 2
+ $sp = ADDXri $sp, 32, 0
+ RET undef $lr
+
+...
+---
+name: baz
+tracksRegLiveness: true
+body: |
+ bb.0:
+ liveins: $w0, $lr, $w8
+ RET undef $lr
+
+# CHECK-LABEL: name: OUTLINED_FUNCTION_{{[0-9]}}
+# CHECK-LABEL: name: OUTLINED_FUNCTION_{{[1-9]}}
+
+# THRESHOLD-LABEL: name: OUTLINED_FUNCTION_{{[0-9]}}
+# THRESHOLD-NOT: name: OUTLINED_FUNCTION_{{[1-9]}}
More information about the llvm-commits
mailing list