diff --git a/llvm/lib/CodeGen/MachineSink.cpp b/llvm/lib/CodeGen/MachineSink.cpp --- a/llvm/lib/CodeGen/MachineSink.cpp +++ b/llvm/lib/CodeGen/MachineSink.cpp @@ -390,15 +390,15 @@ "target\n"); continue; } - if (!isCycleInvariant(Cycle, MI)) { - LLVM_DEBUG(dbgs() << "CycleSink: Instruction is not cycle invariant\n"); - continue; - } bool DontMoveAcrossStore = true; if (!MI.isSafeToMove(AA, DontMoveAcrossStore)) { LLVM_DEBUG(dbgs() << "CycleSink: Instruction not safe to move.\n"); continue; } + if (!isCycleInvariant(Cycle, MI)) { + LLVM_DEBUG(dbgs() << "CycleSink: Instruction is not cycle invariant\n"); + continue; + } if (MI.mayLoad() && !mayLoadFromGOTOrConstantPool(MI)) { LLVM_DEBUG(dbgs() << "CycleSink: Dont sink GOT or constant pool loads\n"); continue; diff --git a/llvm/test/CodeGen/Generic/sink-insts-to-avoid-spills-debug-crash.ll b/llvm/test/CodeGen/Generic/sink-insts-to-avoid-spills-debug-crash.ll new file mode 100644 --- /dev/null +++ b/llvm/test/CodeGen/Generic/sink-insts-to-avoid-spills-debug-crash.ll @@ -0,0 +1,29 @@ +; RUN: llc -O2 -sink-insts-to-avoid-spills < %s | FileCheck %s +; REQUIRES: aarch64-registered-target + +target triple = "aarch64-unknown-linux-gnu" + +; CHECK-LABEL: a: +define i32 @a() { +entry: + %call = tail call i32 @c() + call void @llvm.dbg.value(metadata i32 %call, metadata !3, metadata !DIExpression()), !dbg !8 + 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) +!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: !7) +!4 = distinct !DISubprogram(name: "a", scope: !1, unit: !0) +!7 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed) +!8 = !DILocation(line: 0, scope: !4)