From: Florian Hahn Date: Fri, 23 Dec 2016 11:35:00 +0000 (+0000) Subject: [framelowering] Skip dbg values when getting next/previous instruction. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=da92dac728d8adc43dfdf7a439cca9c4b8dd1f1f;p=llvm [framelowering] Skip dbg values when getting next/previous instruction. Summary: In mergeSPUpdates, debug values need to be ignored when getting the previous element, otherwise debug data could have an impact on codegen. In eliminateCallFramePseudoInstr, debug values after the erased element could have an impact on codegen and should be skipped. Closes PR31319 (https://llvm.org/bugs/show_bug.cgi?id=31319) Reviewers: mkuper, MatzeB, aprantl Subscribers: gbedwell, llvm-commits Differential Revision: https://reviews.llvm.org/D27688 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@290423 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Target/X86/X86FrameLowering.cpp b/lib/Target/X86/X86FrameLowering.cpp index 1deefe1231c..87355d46f9b 100644 --- a/lib/Target/X86/X86FrameLowering.cpp +++ b/lib/Target/X86/X86FrameLowering.cpp @@ -373,6 +373,10 @@ int X86FrameLowering::mergeSPUpdates(MachineBasicBlock &MBB, MachineBasicBlock::iterator PI = doMergeWithPrevious ? std::prev(MBBI) : MBBI; MachineBasicBlock::iterator NI = doMergeWithPrevious ? nullptr : std::next(MBBI); + PI = skipDebugInstructionsBackward(PI, MBB.begin()); + if (NI != nullptr) + NI = skipDebugInstructionsForward(NI, MBB.end()); + unsigned Opc = PI->getOpcode(); int Offset = 0; @@ -2586,6 +2590,7 @@ eliminateCallFramePseudoInstr(MachineFunction &MF, MachineBasicBlock &MBB, uint64_t Amount = !reserveCallFrame ? I->getOperand(0).getImm() : 0; uint64_t InternalAmt = (isDestroy || Amount) ? I->getOperand(1).getImm() : 0; I = MBB.erase(I); + I = skipDebugInstructionsForward(I, MBB.end()); if (!reserveCallFrame) { // If the stack pointer can be changed after prologue, turn the diff --git a/test/CodeGen/X86/frame-lowering-debug-intrinsic-2.ll b/test/CodeGen/X86/frame-lowering-debug-intrinsic-2.ll new file mode 100644 index 00000000000..ab797e04b40 --- /dev/null +++ b/test/CodeGen/X86/frame-lowering-debug-intrinsic-2.ll @@ -0,0 +1,72 @@ +; Test ensuring debug intrinsics do not affect generated function prologue. +; +; RUN: llc -O1 -mtriple=x86_64-unknown-unknown -o - %s | FileCheck %s + +@a = local_unnamed_addr global i64 0, align 8 + +define void @noDebug() { +entry: + %0 = load i64, i64* @a, align 8 + %1 = load i64, i64* @a, align 8 + %2 = load i64, i64* @a, align 8 + %3 = tail call { i64, i1 } @llvm.uadd.with.overflow.i64(i64 %0, i64 %1) + %4 = extractvalue { i64, i1 } %3, 0 + %5 = tail call i64 @fn1(i64 %4, i64 %2) + tail call void (...) @printf() + tail call void (...) @printf(i64 1, i64 2, i64 3, i64 4, i32 0, i64 0, i64 %4, i64 %5) + ret void +} + +; CHECK-LABEL: noDebug +; CHECK: addq $24, %rsp +; CHECK: popq %rbx +; CHECK-NEXT: popq %r14 +; CHECK-NEXT: retq + + +define void @withDebug() !dbg !18 { +entry: + %0 = load i64, i64* @a, align 8 + %1 = load i64, i64* @a, align 8 + %2 = load i64, i64* @a, align 8 + %3 = tail call { i64, i1 } @llvm.uadd.with.overflow.i64(i64 %0, i64 %1) + %4 = extractvalue { i64, i1 } %3, 0 + %5 = tail call i64 @fn1(i64 %4, i64 %2) + tail call void @llvm.dbg.value(metadata i64 %4, i64 0, metadata !23, metadata !33), !dbg !34 + tail call void @llvm.dbg.value(metadata i64 %5, i64 0, metadata !22, metadata !33), !dbg !35 + tail call void (...) @printf() + tail call void (...) @printf(i64 1, i64 2, i64 3, i64 4, i32 0, i64 0, i64 %4, i64 %5) + ret void +} + +; CHECK-LABEL: withDebug +; CHECK: #DEBUG_VALUE: test:j <- %RBX +; CHECK-NEXT: addq $24, %rsp +; CHECK: popq %rbx +; CHECK-NEXT: popq %r14 +; CHECK-NEXT: retq + +declare { i64, i1 } @llvm.uadd.with.overflow.i64(i64, i64) +declare i64 @fn1(i64, i64) + +declare void @printf(...) + +declare void @llvm.dbg.value(metadata, i64, metadata, metadata) + + +!llvm.dbg.cu = !{!1} +!llvm.module.flags = !{!15, !16} + +!1 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !2, producer: "clang version 4.0.0") +!2 = !DIFile(filename: "test.cpp", directory: "") +!11 = !DIBasicType(name: "long int", size: 64, encoding: DW_ATE_signed) +!15 = !{i32 2, !"Dwarf Version", i32 4} +!16 = !{i32 2, !"Debug Info Version", i32 3} +!18 = distinct !DISubprogram(name: "test", scope: !2, file: !2, line: 5, unit: !1) +!22 = !DILocalVariable(name: "i", scope: !18, file: !2, line: 6, type: !11) +!23 = !DILocalVariable(name: "j", scope: !18, file: !2, line: 7, type: !11) +!33 = !DIExpression() +!34 = !DILocation(line: 7, column: 17, scope: !18) +!35 = !DILocation(line: 6, column: 8, scope: !18) +!36 = !DILocation(line: 9, column: 3, scope: !18) +!37 = !DILocation(line: 10, column: 10, scope: !18) diff --git a/test/CodeGen/X86/frame-lowering-debug-intrinsic.ll b/test/CodeGen/X86/frame-lowering-debug-intrinsic.ll index 8614d1b4c6c..e86d094ac34 100644 --- a/test/CodeGen/X86/frame-lowering-debug-intrinsic.ll +++ b/test/CodeGen/X86/frame-lowering-debug-intrinsic.ll @@ -2,31 +2,56 @@ ; ; RUN: llc -O1 -mtriple=x86_64-unknown-unknown -o - %s | FileCheck %s - -define i64 @noDebug(i64 %a) { +define i64 @fn1NoDebug(i64 %a) { %call = call i64 @fn(i64 %a, i64 0) ret i64 %call } -; CHECK-LABEL: noDebug +; CHECK-LABEL: fn1NoDebug ; CHECK: popq %rcx -; CHECK: ret - +; CHECK-NEXT: ret -define i64 @withDebug(i64 %a) !dbg !4 { +define i64 @fn1WithDebug(i64 %a) !dbg !4 { %call = call i64 @fn(i64 %a, i64 0) tail call void @llvm.dbg.value(metadata i64 %call, i64 0, metadata !5, metadata !6), !dbg !7 ret i64 %call } -; CHECK-LABEL: withDebug +; CHECK-LABEL: fn1WithDebug ; CHECK: popq %rcx -; CHECK: ret +; CHECK-NEXT: ret + +%struct.Buffer = type { i8, [63 x i8] } + +define void @fn2NoDebug(%struct.Buffer* byval align 64 %p1) { + ret void +} + +; CHECK-LABEL: fn2NoDebug +; CHECK: and +; CHECK-NOT: add +; CHECK-NOT: sub +; CHECK: mov +; CHECK-NEXT: pop +; CHECK-NEXT: ret + +define void @fn2WithDebug(%struct.Buffer* byval align 64 %p1) !dbg !4 { + call void @llvm.dbg.declare(metadata %struct.Buffer* %p1, metadata !5, metadata !6), !dbg !7 + ret void +} +; CHECK-LABEL: fn2WithDebug +; CHECK: and +; CHECK-NOT: add +; CHECK-NOT: sub +; CHECK: mov +; CHECK-NEXT: pop +; CHECK-NEXT: ret declare i64 @fn(i64, i64) declare void @llvm.dbg.value(metadata, i64, metadata, metadata) +declare void @llvm.dbg.declare(metadata, metadata, metadata) !llvm.dbg.cu = !{!0} !llvm.module.flags = !{!2,!3}