[PATCH] D147060: [MachineSink] Fix an assertion failure in isCycleInvariant

antoine moynault via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Mar 29 04:33:47 PDT 2023


antmo updated this revision to Diff 509304.
antmo added a comment.

now skipping debug instructions while looping on basic block
replaced ll test by a MIR test


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D147060/new/

https://reviews.llvm.org/D147060

Files:
  llvm/lib/CodeGen/MachineSink.cpp
  llvm/test/CodeGen/AArch64/sink-insts-to-avoid-spills-debug-crash.mir


Index: llvm/test/CodeGen/AArch64/sink-insts-to-avoid-spills-debug-crash.mir
===================================================================
--- /dev/null
+++ llvm/test/CodeGen/AArch64/sink-insts-to-avoid-spills-debug-crash.mir
@@ -0,0 +1,47 @@
+# RUN: llc -run-pass=machine-sink -sink-insts-to-avoid-spills -o - %s | FileCheck %s
+# REQUIRES: aarch64-registered-target
+
+--- |
+  target datalayout = "e-m:e-i8:8:32-i16:16:32-i64:64-i128:128-n32:64-S128"
+  target triple = "aarch64-unknown-linux-gnu"
+
+  define i32 @a() {
+  entry:
+    %call = tail call i32 @c()
+    call void @llvm.dbg.value(metadata i32 %call, metadata !3, metadata !DIExpression()), !dbg !6
+    br label %for.cond
+
+  for.cond:                                         ; preds = %for.cond, %entry
+    br label %for.cond
+  }
+
+  declare i32 @c()
+
+  declare void @llvm.dbg.value(metadata, metadata, metadata)
+
+  !llvm.dbg.cu = !{!0}
+  !llvm.module.flags = !{!2}
+
+  !0 = distinct !DICompileUnit(language: DW_LANG_C11, file: !1, isOptimized: false, runtimeVersion: 0, emissionKind: NoDebug)
+  !1 = !DIFile(filename: "bcm.c", directory: "/")
+  !2 = !{i32 2, !"Debug Info Version", i32 3}
+  !3 = !DILocalVariable(name: "b", scope: !4, file: !1, line: 8, type: !5)
+  !4 = distinct !DISubprogram(name: "a", scope: !1, spFlags: DISPFlagDefinition, unit: !0)
+  !5 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
+  !6 = !DILocation(line: 0, scope: !4)
+
+...
+---
+# CHECK-LABEL: a
+name:            a
+body:             |
+  bb.0.entry:
+    ADJCALLSTACKDOWN 0, 0, implicit-def dead $sp, implicit $sp
+    BL @c, csr_aarch64_aapcs, implicit-def dead $lr, implicit $sp, implicit-def $sp, implicit-def $w0
+    ADJCALLSTACKUP 0, 0, implicit-def dead $sp, implicit $sp
+    DBG_VALUE %0:gpr32all, $noreg, !3, !DIExpression(), debug-location !6
+
+  bb.1.for.cond:
+    B %bb.1
+
+...
Index: llvm/lib/CodeGen/MachineSink.cpp
===================================================================
--- llvm/lib/CodeGen/MachineSink.cpp
+++ llvm/lib/CodeGen/MachineSink.cpp
@@ -383,7 +383,13 @@
 void MachineSinking::FindCycleSinkCandidates(
     MachineCycle *Cycle, MachineBasicBlock *BB,
     SmallVectorImpl<MachineInstr *> &Candidates) {
-  for (auto &MI : *BB) {
+
+  for (auto II = BB->begin(), EI = BB->end(); II != EI; ++II) {
+    II = skipDebugInstructionsForward(II, EI);
+    if (II == EI)
+      break;
+    MachineInstr &MI = *II;
+
     LLVM_DEBUG(dbgs() << "CycleSink: Analysing candidate: " << MI);
     if (!TII->shouldSink(MI)) {
       LLVM_DEBUG(dbgs() << "CycleSink: Instruction not a candidate for this "


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D147060.509304.patch
Type: text/x-patch
Size: 2619 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230329/14c9e798/attachment.bin>


More information about the llvm-commits mailing list