diff --git a/llvm/lib/CodeGen/BasicBlockSections.cpp b/llvm/lib/CodeGen/BasicBlockSections.cpp --- a/llvm/lib/CodeGen/BasicBlockSections.cpp +++ b/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 diff --git a/llvm/lib/CodeGen/MachineFunctionSplitter.cpp b/llvm/lib/CodeGen/MachineFunctionSplitter.cpp --- a/llvm/lib/CodeGen/MachineFunctionSplitter.cpp +++ b/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