[PATCH] D152221: Avoid cross-section branches in AArch64 inline asm
Daniel Hoekwater via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Mon Jun 5 18:18:36 PDT 2023
dhoekwater updated this revision to Diff 528658.
dhoekwater added a comment.
Don't format code we're not touching
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D152221/new/
https://reviews.llvm.org/D152221
Files:
llvm/lib/CodeGen/BasicBlockSections.cpp
llvm/lib/CodeGen/MachineFunctionSplitter.cpp
Index: llvm/lib/CodeGen/MachineFunctionSplitter.cpp
===================================================================
--- llvm/lib/CodeGen/MachineFunctionSplitter.cpp
+++ llvm/lib/CodeGen/MachineFunctionSplitter.cpp
@@ -115,6 +115,15 @@
if (!UseProfileData && !SplitAllEHCode)
return false;
+ // Blocks cannot be split to different sections on AArch64 if they contain
+ // inline assembly. This is because inline assembly may contain a jump to
+ // another block in a different text section, which the compiler can't
+ // guarantee is in-range of the branch instruction.
+ const auto &Triple = MF.getSubtarget().getTargetTriple();
+ assert(Triple.isX86() || Triple.isAArch64());
+ if (Triple.isAArch64() && MF.hasInlineAsm())
+ return false;
+
// TODO: We don't split functions where a section attribute has been set
// since the split part may not be placed in a contiguous region. It may also
// be more beneficial to augment the linker to ensure contiguous layout of
Index: llvm/lib/CodeGen/BasicBlockSections.cpp
===================================================================
--- llvm/lib/CodeGen/BasicBlockSections.cpp
+++ llvm/lib/CodeGen/BasicBlockSections.cpp
@@ -318,9 +318,19 @@
// clusters of basic blocks using basic block ids. Source drift can
// invalidate these groupings leading to sub-optimal code generation with
// regards to performance.
- if (BBSectionsType == BasicBlockSection::List &&
+ if (BBSectionsType == BasicBlockSection::List &&
hasInstrProfHashMismatch(MF))
return true;
+
+ // Blocks cannot be placed in different sections on AArch64 if they contain
+ // inline assembly. This is because inline assembly may contain a jump to
+ // another block in a different text section, which the compiler can't
+ // guarantee is in-range of the branch instruction.
+ const auto &Triple = MF.getSubtarget().getTargetTriple();
+ assert(Triple.isX86() || Triple.isAArch64());
+ if (Triple.isAArch64() && MF.hasInlineAsm())
+ return false;
+
// Renumber blocks before sorting them. This is useful during sorting,
// basic blocks in the same section will retain the default order.
// This renumbering should also be done for basic block labels to match the
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D152221.528658.patch
Type: text/x-patch
Size: 2252 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230606/19d49db6/attachment.bin>
More information about the llvm-commits
mailing list