Index: lib/Target/X86/X86FrameLowering.cpp =================================================================== --- lib/Target/X86/X86FrameLowering.cpp +++ lib/Target/X86/X86FrameLowering.cpp @@ -1550,6 +1550,7 @@ } uint64_t SEHStackAllocAmt = NumBytes; + MachineBasicBlock::iterator FirstCSPop = MBBI; // Skip the callee-saved pop instructions. while (MBBI != MBB.begin()) { MachineBasicBlock::iterator PI = std::prev(MBBI); @@ -1560,9 +1561,12 @@ Opc != X86::DBG_VALUE && !PI->isTerminator()) break; + if (Opc != X86::DBG_VALUE && !PI->isTerminator()) + FirstCSPop = PI; + --MBBI; } - MachineBasicBlock::iterator FirstCSPop = MBBI; + MBBI = FirstCSPop; if (TargetMBB) { // Fill EAX/RAX with the address of the target block. Index: test/CodeGen/X86/frame-lowering-debug-intrinsic.ll =================================================================== --- /dev/null +++ test/CodeGen/X86/frame-lowering-debug-intrinsic.ll @@ -0,0 +1,77 @@ +; Test ensuring debug intrinsics do not affect generated function prologue. +; +; RUN: llc -mtriple=x86_64-unknown-unknown < %s | FileCheck %s + +define double @noDebug(double %a) { +entry: + %call = tail call double @fmod(double %a, double 0x401921FB54442D18) #4 + %call1 = tail call double @fabs(double %call) #3 + %cmp = fcmp ult double %call1, 0x400921FB54442D18 + br i1 %cmp, label %if.end, label %if.then + +if.then: ; preds = %entry + %cmp2 = fcmp olt double %a, 0.000000e+00 + %cond = select i1 %cmp2, double 0xC01921FB54442D18, double 0x401921FB54442D18 + %sub = fsub double %call, %cond + br label %if.end + +if.end: ; preds = %entry, %if.then + %w.0 = phi double [ %sub, %if.then ], [ %call, %entry ] + ret double %w.0 +} + +; CHECK noDebug: +; CHECK: popq %rax +; CHECK: retq + +define double @withDebug(double %a) { +entry: + %call = tail call double @fmod(double %a, double 0x401921FB54442D18) #4 + %call1 = tail call double @fabs(double %call) #3 + %cmp = fcmp ult double %call1, 0x400921FB54442D18 + br i1 %cmp, label %if.end, label %if.then + +if.then: ; preds = %entry + %cmp2 = fcmp olt double %a, 0.000000e+00 + %cond = select i1 %cmp2, double 0xC01921FB54442D18, double 0x401921FB54442D18 + %sub = fsub double %call, %cond + br label %if.end + +if.end: ; preds = %entry, %if.then + %w.0 = phi double [ %sub, %if.then ], [ %call, %entry ] + tail call void @llvm.dbg.value(metadata double %w.0, i64 0, metadata !16, metadata !17), !dbg !20 + ret double %w.0 +} + +; CHECK withDebug: +; CHECK: popq %rax +; CHECK: ret + +declare double @fmod(double, double) + +declare double @fabs(double) + +declare void @llvm.dbg.value(metadata, i64, metadata, metadata) + +attributes #3 = { nounwind readnone } +attributes #4 = { nounwind } + +!0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, enums: !2, globals: !3) +!1 = !DIFile(filename: "test.c", directory: "./") +!2 = !{} +!3 = !{!4, !7} +!4 = distinct !DIGlobalVariable(name: "TWOPI", scope: !0, file: !1, line: 42, type: !5, isLocal: true, isDefinition: true) +!5 = !DIDerivedType(tag: DW_TAG_const_type, baseType: !6) +!6 = !DIBasicType(name: "double", size: 64, encoding: DW_ATE_float) +!7 = distinct !DIGlobalVariable(name: "PI", scope: !0, file: !1, line: 38, type: !5, isLocal: true, isDefinition: true) +!11 = distinct !DISubprogram(name: "anpm", scope: !1, file: !1, line: 208, type: !12, isLocal: false, isDefinition: true, scopeLine: 209, flags: DIFlagPrototyped, isOptimized: true, unit: !0, variables: !14) +!12 = !DISubroutineType(types: !13) +!13 = !{!6, !6} +!14 = !{!15, !16} +!15 = !DILocalVariable(name: "a", arg: 1, scope: !11, file: !1, line: 208, type: !6) +!16 = !DILocalVariable(name: "w", scope: !11, file: !1, line: 210, type: !6) +!17 = !DIExpression() +!19 = !DILocation(line: 210, column: 16, scope: !11) +!20 = !DILocation(line: 210, column: 12, scope: !11) +!21 = !DILocation(line: 212, column: 9, scope: !22) +!22 = distinct !DILexicalBlock(scope: !11, file: !1, line: 212, column: 9)