forked from OSchip/llvm-project
[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 llvm-svn: 290423
This commit is contained in:
parent
f344a51369
commit
1d6b1a7b79
|
@ -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
|
||||
|
|
|
@ -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)
|
|
@ -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}
|
||||
|
|
Loading…
Reference in New Issue