Index: include/llvm/CodeGen/MachineModuleInfo.h =================================================================== --- include/llvm/CodeGen/MachineModuleInfo.h +++ include/llvm/CodeGen/MachineModuleInfo.h @@ -165,6 +165,16 @@ /// in this module. bool DbgInfoAvailable; + /// UsePreciseUnwindInfo - True if we should emit precise CFA adjustment + /// information. False if we only need CFA to be precise at call sites. + /// Ideally, what we'd like is to have a switch that allows emitting + /// synchronous (precise at call-sites only) CFA into .eh_frame. However, + /// even under this switch, we'd like .debug_frame to be precise when using. + /// -g. At this moment, there's no way to specify that some CFI directives + /// go into .eh_frame only, while others go into .debug_frame only. + /// Right now, since this is missing, the variable should always be true. + bool UsePreciseUnwindInfo; + /// UsesVAFloatArgument - True if this module calls VarArg function with /// floating-point arguments. This is used to emit an undefined reference /// to _fltused on Windows targets. @@ -235,10 +245,8 @@ bool hasDebugInfo() const { return DbgInfoAvailable; } void setDebugInfoAvailability(bool avail) { DbgInfoAvailable = avail; } - // Returns true if we need to generate precise CFI. Currently - // this is equivalent to hasDebugInfo(), but if we ever implement - // async EH, it will require precise CFI as well. - bool usePreciseUnwindInfo() const { return hasDebugInfo(); } + bool usePreciseUnwindInfo() const { return UsePreciseUnwindInfo; } + void setUsePreciseUnwindInfo(bool b) { UsePreciseUnwindInfo = b; } bool callsEHReturn() const { return CallsEHReturn; } void setCallsEHReturn(bool b) { CallsEHReturn = b; } Index: lib/CodeGen/MachineModuleInfo.cpp =================================================================== --- lib/CodeGen/MachineModuleInfo.cpp +++ lib/CodeGen/MachineModuleInfo.cpp @@ -211,6 +211,7 @@ CallsUnwindInit = false; HasEHFunclets = false; DbgInfoAvailable = UsesVAFloatArgument = UsesMorestackAddr = false; + UsePreciseUnwindInfo = true; PersonalityTypeCache = EHPersonality::Unknown; AddrLabelSymbols = nullptr; TheModule = nullptr; Index: lib/Target/X86/X86FrameLowering.cpp =================================================================== --- lib/Target/X86/X86FrameLowering.cpp +++ lib/Target/X86/X86FrameLowering.cpp @@ -2530,9 +2530,12 @@ int CFAOffset = Amount; if (!MMI.usePreciseUnwindInfo()) CFAOffset += InternalAmt; - CFAOffset = isDestroy ? -CFAOffset : CFAOffset; - BuildCFI(MBB, I, DL, - MCCFIInstruction::createAdjustCfaOffset(nullptr, CFAOffset)); + + if (CFAOffset) { + CFAOffset = isDestroy ? -CFAOffset : CFAOffset; + BuildCFI(MBB, I, DL, + MCCFIInstruction::createAdjustCfaOffset(nullptr, CFAOffset)); + } } return; Index: lib/Target/X86/X86MCInstLower.cpp =================================================================== --- lib/Target/X86/X86MCInstLower.cpp +++ lib/Target/X86/X86MCInstLower.cpp @@ -1143,8 +1143,10 @@ const X86FrameLowering* FrameLowering = MF->getSubtarget().getFrameLowering(); bool hasFP = FrameLowering->hasFP(*MF); - - bool NeedsDwarfCFI = MMI->usePreciseUnwindInfo(); + + bool NeedsDwarfCFI = + (MMI->hasDebugInfo() || MF->getFunction()->needsUnwindTableEntry()) && + MMI->usePreciseUnwindInfo(); int stackGrowth = -RI->getSlotSize(); if (NeedsDwarfCFI && !hasFP) { Index: test/CodeGen/X86/push-cfi.ll =================================================================== --- test/CodeGen/X86/push-cfi.ll +++ test/CodeGen/X86/push-cfi.ll @@ -6,17 +6,24 @@ declare void @large(i32 %a, i32 %b, i32 %c, i32 %d, i32 %e, i32 %f) declare void @empty() -; When we use an invoke, and have FP, we expect a .cfi_escape GNU_ARGS_SIZE -; with size 16 before the invocation. Without FP, we expect.cfi_adjust_cfa_offset -; before and after. -; Darwin should not generate pushes in neither circumstance. +; When we use an invoke, we expect a .cfi_escape GNU_ARGS_SIZE +; with size 16 before the invocation. Without FP, we also expect +; .cfi_adjust_cfa_offset after each push. +; Darwin should not generate pushes in either circumstance. ; CHECK-LABEL: test1_nofp: ; LINUX: .cfi_escape 0x2e, 0x10 -; LINUX: .cfi_adjust_cfa_offset 16 ; LINUX-NEXT: pushl $4 +; LINUX-NEXT: Ltmp{{[0-9]+}}: +; LINUX-NEXT: .cfi_adjust_cfa_offset 4 ; LINUX-NEXT: pushl $3 +; LINUX-NEXT: Ltmp{{[0-9]+}}: +; LINUX-NEXT: .cfi_adjust_cfa_offset 4 ; LINUX-NEXT: pushl $2 +; LINUX-NEXT: Ltmp{{[0-9]+}}: +; LINUX-NEXT: .cfi_adjust_cfa_offset 4 ; LINUX-NEXT: pushl $1 +; LINUX-NEXT: Ltmp{{[0-9]+}}: +; LINUX-NEXT: .cfi_adjust_cfa_offset 4 ; LINUX-NEXT: call ; LINUX-NEXT: addl $16, %esp ; LINUX: .cfi_adjust_cfa_offset -16 @@ -62,11 +69,18 @@ ; so darwin should not generate pushes. ; CHECK-LABEL: test2_nofp: ; LINUX-NOT: .cfi_escape -; LINUX: .cfi_adjust_cfa_offset 16 -; LINUX-NEXT: pushl $4 +; LINUX: pushl $4 +; LINUX-NEXT: Ltmp{{[0-9]+}}: +; LINUX-NEXT: .cfi_adjust_cfa_offset 4 ; LINUX-NEXT: pushl $3 +; LINUX-NEXT: Ltmp{{[0-9]+}}: +; LINUX-NEXT: .cfi_adjust_cfa_offset 4 ; LINUX-NEXT: pushl $2 +; LINUX-NEXT: Ltmp{{[0-9]+}}: +; LINUX-NEXT: .cfi_adjust_cfa_offset 4 ; LINUX-NEXT: pushl $1 +; LINUX-NEXT: Ltmp{{[0-9]+}}: +; LINUX-NEXT: .cfi_adjust_cfa_offset 4 ; LINUX-NEXT: call ; LINUX-NEXT: addl $16, %esp ; LINUX: .cfi_adjust_cfa_offset -16 @@ -170,11 +184,18 @@ ; without parameters, but don't need to adjust the cfa offset ; CHECK-LABEL: test5_nofp: ; LINUX: .cfi_escape 0x2e, 0x10 -; LINUX: .cfi_adjust_cfa_offset 16 ; LINUX-NEXT: pushl $4 +; LINUX-NEXT: Ltmp{{[0-9]+}}: +; LINUX-NEXT: .cfi_adjust_cfa_offset 4 ; LINUX-NEXT: pushl $3 +; LINUX-NEXT: Ltmp{{[0-9]+}}: +; LINUX-NEXT: .cfi_adjust_cfa_offset 4 ; LINUX-NEXT: pushl $2 +; LINUX-NEXT: Ltmp{{[0-9]+}}: +; LINUX-NEXT: .cfi_adjust_cfa_offset 4 ; LINUX-NEXT: pushl $1 +; LINUX-NEXT: Ltmp{{[0-9]+}}: +; LINUX-NEXT: .cfi_adjust_cfa_offset 4 ; LINUX-NEXT: call ; LINUX-NEXT: addl $16, %esp ; LINUX: .cfi_adjust_cfa_offset -16 Index: test/CodeGen/X86/tls-pie.ll =================================================================== --- test/CodeGen/X86/tls-pie.ll +++ test/CodeGen/X86/tls-pie.ll @@ -36,9 +36,13 @@ define i32 @f3() { ; X32-LABEL: f3: ; X32: calll .L{{[0-9]+}}$pb +; X32-NEXT: .Ltmp{{[0-9]+}}: +; X32-NEXT: .cfi_adjust_cfa_offset 4 ; X32-NEXT: .L{{[0-9]+}}$pb: ; X32-NEXT: popl %eax ; X32-NEXT: .Ltmp{{[0-9]+}}: +; X32-NEXT: .cfi_adjust_cfa_offset -4 +; X32-NEXT: .Ltmp{{[0-9]+}}: ; X32-NEXT: addl $_GLOBAL_OFFSET_TABLE_+(.Ltmp{{[0-9]+}}-.L{{[0-9]+}}$pb), %eax ; X32-NEXT: movl i2@GOTNTPOFF(%eax), %eax ; X32-NEXT: movl %gs:(%eax), %eax @@ -56,9 +60,13 @@ define i32* @f4() { ; X32-LABEL: f4: ; X32: calll .L{{[0-9]+}}$pb +; X32-NEXT: .Ltmp{{[0-9]+}}: +; X32-NEXT: .cfi_adjust_cfa_offset 4 ; X32-NEXT: .L{{[0-9]+}}$pb: ; X32-NEXT: popl %ecx ; X32-NEXT: .Ltmp{{[0-9]+}}: +; X32-NEXT: .cfi_adjust_cfa_offset -4 +; X32-NEXT: .Ltmp{{[0-9]+}}: ; X32-NEXT: addl $_GLOBAL_OFFSET_TABLE_+(.Ltmp{{[0-9]+}}-.L{{[0-9]+}}$pb), %ecx ; X32-NEXT: movl %gs:0, %eax ; X32-NEXT: addl i2@GOTNTPOFF(%ecx), %eax Index: test/CodeGen/X86/win32-pic-jumptable.ll =================================================================== --- test/CodeGen/X86/win32-pic-jumptable.ll +++ test/CodeGen/X86/win32-pic-jumptable.ll @@ -1,8 +1,12 @@ ; RUN: llc < %s -relocation-model=pic | FileCheck %s ; CHECK: calll L0$pb +; CHECK-NEXT: Ltmp{{[0-9]+}}: +; CHECK-NEXT: .cfi_adjust_cfa_offset 4 ; CHECK-NEXT: L0$pb: ; CHECK-NEXT: popl %eax +; CHECK-NEXT: Ltmp{{[0-9]+}}: +; CHECK-NEXT: .cfi_adjust_cfa_offset -4 ; CHECK-NEXT: addl LJTI0_0(,%ecx,4), %eax ; CHECK-NEXT: jmpl *%eax