Index: lib/CodeGen/MachineSink.cpp =================================================================== --- lib/CodeGen/MachineSink.cpp +++ lib/CodeGen/MachineSink.cpp @@ -1034,6 +1034,8 @@ for (auto I = CurBB.rbegin(), E = CurBB.rend(); I != E;) { MachineInstr *MI = &*I; ++I; + if (MI->isDebugValue()) + continue; // Do not move any instruction across function call. if (MI->isCall()) Index: test/CodeGen/X86/postra-ignore-dbg-intrinsics.mir =================================================================== --- test/CodeGen/X86/postra-ignore-dbg-intrinsics.mir +++ test/CodeGen/X86/postra-ignore-dbg-intrinsics.mir @@ -0,0 +1,88 @@ +# RUN: llc -mtriple=x86_64-none-linux-gnu -run-pass=postra-machine-sink -verify-machineinstrs -o - %s | FileCheck %s +# +# This test was originally generated from the following sample: +# +# int x0; +# extern void x3(int, int); +# void x1(int x2) { +# if (x0) +# x3(0, x2); +# } +# +# The code generates a COPY instruction which the PostRA Machine Sink pass will +# try to sink. Earlier versions were not performing the sink due to a +# debug intrinsic confusing the sinking algorithm. + +--- | + @x0 = common dso_local global i32 0, align 4, !dbg !0 + + define dso_local void @x1(i32) !dbg !11 { + %2 = alloca i32, align 4 + store i32 %0, i32* %2, align 4 + call void @llvm.dbg.declare(metadata i32* %2, metadata !14, metadata !DIExpression()), !dbg !16 + %3 = load i32, i32* @x0, align 4, !dbg !16 + %4 = icmp ne i32 %3, 0, !dbg !16 + br i1 %4, label %5, label %7, !dbg !16 + + ;