[PATCH] D95631: [TailDuplicator] Add TargetInstrInfo hook to modify the TailDuplicateSize default threshold
Nicholas Guy via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Jan 28 09:57:01 PST 2021
NickGuy created this revision.
NickGuy added reviewers: SjoerdMeijer, dmgreen.
NickGuy added a project: LLVM.
Herald added a subscriber: hiraditya.
NickGuy requested review of this revision.
Different targets might handle branch performance differently, so this patch allows for
targets to specify the TailDuplicateSize threshold. Said threshold defines how small a branch
can be and still be duplicated to generate straight-line code instead.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D95631
Files:
llvm/include/llvm/CodeGen/TargetInstrInfo.h
llvm/lib/CodeGen/TailDuplicator.cpp
Index: llvm/lib/CodeGen/TailDuplicator.cpp
===================================================================
--- llvm/lib/CodeGen/TailDuplicator.cpp
+++ llvm/lib/CodeGen/TailDuplicator.cpp
@@ -564,12 +564,17 @@
// duplicate only one, because one branch instruction can be eliminated to
// compensate for the duplication.
unsigned MaxDuplicateCount;
+
bool OptForSize = MF->getFunction().hasOptSize() ||
llvm::shouldOptimizeForSize(&TailBB, PSI, MBFI);
- if (TailDupSize == 0)
- MaxDuplicateCount = TailDuplicateSize;
- else
+ if (TailDupSize == 0) {
+ if (TailDuplicateSize.getNumOccurrences() > 0)
+ MaxDuplicateCount = TailDuplicateSize;
+ else
+ MaxDuplicateCount = TII->getTailDuplicateSizeOverride();
+ } else
MaxDuplicateCount = TailDupSize;
+
if (OptForSize)
MaxDuplicateCount = 1;
Index: llvm/include/llvm/CodeGen/TargetInstrInfo.h
===================================================================
--- llvm/include/llvm/CodeGen/TargetInstrInfo.h
+++ llvm/include/llvm/CodeGen/TargetInstrInfo.h
@@ -1937,6 +1937,10 @@
return Formatter.get();
}
+ /// Returns the target-specific default value for tail duplication.
+ /// This value will be used if the tail-dup-size argument is not provided.
+ virtual unsigned getTailDuplicateSizeOverride() const { return 2; }
+
private:
mutable std::unique_ptr<MIRFormatter> Formatter;
unsigned CallFrameSetupOpcode, CallFrameDestroyOpcode;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D95631.319899.patch
Type: text/x-patch
Size: 1478 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210128/0e52ec50/attachment.bin>
More information about the llvm-commits
mailing list