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

Daniel Hoekwater via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 23 11:11:44 PDT 2023


dhoekwater created this revision.
dhoekwater added reviewers: shenhan, mingmingl, wenlei.
Herald added subscribers: hiraditya, kristof.beyls.
Herald added a project: All.
dhoekwater requested review of this revision.
Herald added subscribers: llvm-commits, wangpc.
Herald added a project: LLVM.

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.

Depends on D157124 <https://reviews.llvm.org/D157124>


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D158647

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


Index: llvm/test/CodeGen/Generic/machine-function-splitter.ll
===================================================================
--- llvm/test/CodeGen/Generic/machine-function-splitter.ll
+++ llvm/test/CodeGen/Generic/machine-function-splitter.ll
@@ -514,6 +514,33 @@
   ret i32 %4
 }
 
+define void @foo17(i1 zeroext %0) !prof !14 !section_prefix !15 {
+;; Check that blocks containing or targeted by asm goto aren't split.
+; MFS-DEFAULTS-LABEL:        foo17
+; MFS-DEFAULTS-AARCH64-NOT:  foo17.cold:
+; MFS-DEFAULTS-X86:          .section        .text.split.foo17
+; MFS-DEFAULTS-X86:          foo17.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()
Index: llvm/lib/Target/AArch64/AArch64InstrInfo.cpp
===================================================================
--- llvm/lib/Target/AArch64/AArch64InstrInfo.cpp
+++ llvm/lib/Target/AArch64/AArch64InstrInfo.cpp
@@ -8418,7 +8418,16 @@
            llvm::any_of(MJTI->getJumpTables(), isInJumpTable);
   };
 
-  return !containsJumpTableLookup(MBB) && !isJumpTableTarget(MBB);
+  if (containsJumpTableLookup(MBB) || isJumpTableTarget(MBB))
+    return false;
+
+  auto isAsmGoto = [](const MachineInstr &MI) {
+    return MI.getOpcode() == AArch64::INLINEASM_BR;
+  };
+  if (llvm::any_of(MBB, isAsmGoto) || MBB.isInlineAsmBrIndirectTarget())
+    return false;
+
+  return true;
 }
 
 std::optional<ParamLoadedValue>


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D158647.552806.patch
Type: text/x-patch
Size: 1817 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230823/60c119a6/attachment.bin>


More information about the llvm-commits mailing list