X86: Use 'mov' instead of 'lea' in Win64 SEH prologues when possible

'mov' and 'lea' are equivalent when the displacement applied with 'lea'
is zero.  However, 'mov' should encode smaller.

llvm-svn: 230269
This commit is contained in:
David Majnemer 2015-02-23 21:50:27 +00:00
parent b85e023b8b
commit 31d868b618
3 changed files with 9 additions and 6 deletions

View File

@ -863,8 +863,11 @@ void X86FrameLowering::emitPrologue(MachineFunction &MF) const {
int SEHFrameOffset = 0;
if (IsWinEH && HasFP) {
SEHFrameOffset = calculateSetFPREG(NumBytes);
addRegOffset(BuildMI(MBB, MBBI, DL, TII.get(X86::LEA64r), FramePtr),
StackPtr, false, SEHFrameOffset);
if (SEHFrameOffset)
addRegOffset(BuildMI(MBB, MBBI, DL, TII.get(X86::LEA64r), FramePtr),
StackPtr, false, SEHFrameOffset);
else
BuildMI(MBB, MBBI, DL, TII.get(X86::MOV64rr), FramePtr).addReg(StackPtr);
if (NeedsWinEH)
BuildMI(MBB, MBBI, DL, TII.get(X86::SEH_SetFrame))

View File

@ -18,7 +18,7 @@ entry:
; CHECK-32-NEXT: ret
; CHECK-W64-LABEL: test1
; CHECK-W64: push
; CHECK-W64-NEXT: leaq (%rsp), %rbp
; CHECK-W64-NEXT: movq %rsp, %rbp
; CHECK-W64-NEXT: leaq (%rbp), %rax
; CHECK-W64-NEXT: pop
; CHECK-W64-NEXT: ret
@ -53,7 +53,7 @@ entry:
; CHECK-32-NEXT: ret
; CHECK-W64-LABEL: test2
; CHECK-W64: push
; CHECK-W64-NEXT: leaq (%rsp), %rbp
; CHECK-W64-NEXT: movq %rsp, %rbp
; CHECK-W64-NEXT: leaq (%rbp), %rax
; CHECK-W64-NEXT: pop
; CHECK-W64-NEXT: ret

View File

@ -9,7 +9,7 @@ define i32 @f1(i32 %p1, i32 %p2, i32 %p3, i32 %p4, i32 %p5) "no-frame-pointer-el
define void @f2(i32 %p, ...) "no-frame-pointer-elim"="true" {
; CHECK-LABEL: f2:
; CHECK: .seh_stackalloc 8
; CHECK: leaq (%rsp), %rbp
; CHECK: movq %rsp, %rbp
; CHECK: .seh_setframe 5, 0
; CHECK: movq %rdx, 32(%rbp)
; CHECK: leaq 32(%rbp), %rax
@ -20,7 +20,7 @@ define void @f2(i32 %p, ...) "no-frame-pointer-elim"="true" {
define i8* @f3() "no-frame-pointer-elim"="true" {
; CHECK-LABEL: f3:
; CHECK: leaq (%rsp), %rbp
; CHECK: movq %rsp, %rbp
; CHECK: .seh_setframe 5, 0
; CHECK: movq 8(%rbp), %rax
%ra = call i8* @llvm.returnaddress(i32 0)