[llvm] 0982d96 - [CodeGen][AArch64] Don't split inline asm goto blocks or their targets

Daniel Hoekwater via llvm-commits llvm-commits at lists.llvm.org
Tue Aug 29 13:51:37 PDT 2023


Author: Daniel Hoekwater
Date: 2023-08-29T20:24:38Z
New Revision: 0982d96186a6c7ba78a231ae6034fa8862e8a058

URL: https://github.com/llvm/llvm-project/commit/0982d96186a6c7ba78a231ae6034fa8862e8a058
DIFF: https://github.com/llvm/llvm-project/commit/0982d96186a6c7ba78a231ae6034fa8862e8a058.diff

LOG: [CodeGen][AArch64] Don't split inline asm goto blocks or their targets

Machine function splitting + branch relaxation currently don't properly
handle inline asm goto blocks that conditional branch to cold goto
labels. While such inline asm is technically invalid, machine
function splitting is the only thing that exposes it as such.

Since machine function splitting doesn't help too much in these
circumstances anyway, disable it for asm goto blocks and their targets.

Differential Revision: https://reviews.llvm.org/D158647

Added: 
    

Modified: 
    llvm/lib/Target/AArch64/AArch64InstrInfo.cpp
    llvm/test/CodeGen/Generic/machine-function-splitter.ll

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Target/AArch64/AArch64InstrInfo.cpp b/llvm/lib/Target/AArch64/AArch64InstrInfo.cpp
index b5bc58e9e32414..088e1e5bdb6de2 100644
--- a/llvm/lib/Target/AArch64/AArch64InstrInfo.cpp
+++ b/llvm/lib/Target/AArch64/AArch64InstrInfo.cpp
@@ -8408,6 +8408,14 @@ bool AArch64InstrInfo::isFunctionSafeToSplit(const MachineFunction &MF) const {
 
 bool AArch64InstrInfo::isMBBSafeToSplitToCold(
     const MachineBasicBlock &MBB) const {
+  // Asm Goto blocks can contain conditional branches to goto labels, which can
+  // get moved out of range of the branch instruction.
+  auto isAsmGoto = [](const MachineInstr &MI) {
+    return MI.getOpcode() == AArch64::INLINEASM_BR;
+  };
+  if (llvm::any_of(MBB, isAsmGoto) || MBB.isInlineAsmBrIndirectTarget())
+    return false;
+
   // Because jump tables are label-relative instead of table-relative, they all
   // must be in the same section or relocation fixup handling will fail.
 

diff  --git a/llvm/test/CodeGen/Generic/machine-function-splitter.ll b/llvm/test/CodeGen/Generic/machine-function-splitter.ll
index 0ae03f7bb3141b..364eadd64c7556 100644
--- a/llvm/test/CodeGen/Generic/machine-function-splitter.ll
+++ b/llvm/test/CodeGen/Generic/machine-function-splitter.ll
@@ -602,6 +602,33 @@ cold2:                                            ; preds = %0
   ret i32 %4
 }
 
+define void @foo20(i1 zeroext %0) !prof !14 !section_prefix !15 {
+;; Check that blocks containing or targeted by asm goto aren't split.
+; MFS-DEFAULTS-LABEL:        foo20
+; MFS-DEFAULTS-AARCH64-NOT:  foo20.cold:
+; MFS-DEFAULTS-X86:          .section        .text.split.foo20
+; MFS-DEFAULTS-X86:          foo20.cold:
+; MFS-DEFAULTS-X86-DAG:      # %cold_asm
+; MFS-DEFAULTS-X86-DAG:      # %cold_asm_target
+
+  br i1 %0, label %hot, label %cold_asm, !prof !17
+
+hot:
+  %2 = call i32 @bar()
+  ret void
+
+cold_asm:
+    callbr void asm sideeffect "nop", "!i"() #3
+          to label %asm.fallthrough [label %cold_asm_target]
+
+asm.fallthrough:
+    br label %cold_asm_target
+
+cold_asm_target:
+  %3 = call i32 @baz()
+  ret void
+}
+
 declare i32 @bar()
 declare i32 @baz()
 declare i32 @bam()


        


More information about the llvm-commits mailing list