llvm.org GIT mirror llvm / 3f54c64
Load folding tail call should not use ebp / rbp after it's popped. PEI should use esp / rsp to reference frame instead. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@102596 91177308-0d34-0410-b5e6-96231b3b80d8 Evan Cheng 9 years ago
2 changed file(s) with 67 addition(s) and 5 deletion(s). Raw diff Collapse all Expand all
607607 int FrameIndex = MI.getOperand(i).getIndex();
608608 unsigned BasePtr;
609609
610 unsigned Opc = MI.getOpcode();
611 bool AfterFPPop = Opc == X86::TAILJMPm64 || Opc == X86::TAILJMPm;
610612 if (needsStackRealignment(MF))
611613 BasePtr = (FrameIndex < 0 ? FramePtr : StackPtr);
614 else if (AfterFPPop)
615 BasePtr = StackPtr;
612616 else
613617 BasePtr = (hasFP(MF) ? FramePtr : StackPtr);
614618
617621 MI.getOperand(i).ChangeToRegister(BasePtr, false);
618622
619623 // Now add the frame object offset to the offset from EBP.
624 int FIOffset;
625 if (AfterFPPop) {
626 // Tail call jmp happens after FP is popped.
627 const TargetFrameInfo &TFI = *MF.getTarget().getFrameInfo();
628 const MachineFrameInfo *MFI = MF.getFrameInfo();
629 FIOffset = MFI->getObjectOffset(FrameIndex) - TFI.getOffsetOfLocalArea();
630 } else
631 FIOffset = getFrameIndexOffset(MF, FrameIndex);
632
620633 if (MI.getOperand(i+3).isImm()) {
621634 // Offset is a 32-bit integer.
622 int Offset = getFrameIndexOffset(MF, FrameIndex) +
623 (int)(MI.getOperand(i + 3).getImm());
624
635 int Offset = FIOffset + (int)(MI.getOperand(i + 3).getImm());
625636 MI.getOperand(i + 3).ChangeToImmediate(Offset);
626637 } else {
627638 // Offset is symbolic. This is extremely rare.
628 uint64_t Offset = getFrameIndexOffset(MF, FrameIndex) +
629 (uint64_t)MI.getOperand(i+3).getOffset();
639 uint64_t Offset = FIOffset + (uint64_t)MI.getOperand(i+3).getOffset();
630640 MI.getOperand(i+3).setOffset(Offset);
631641 }
632642 return 0;
0 ; RUN: llc < %s -mtriple=i386-apple-darwin -disable-fp-elim | FileCheck %s -check-prefix=32
1 ; RUN: llc < %s -mtriple=x86_64-apple-darwin -disable-fp-elim | FileCheck %s -check-prefix=64
2
3 ; Tail call should not use ebp / rbp after it's popped. Use esp / rsp.
4
5 define void @t1(i8* nocapture %value) nounwind {
6 entry:
7 ; 32: t1:
8 ; 32: jmpl *4(%esp)
9
10 ; 64: t1:
11 ; 64: jmpq *%rdi
12 %0 = bitcast i8* %value to void ()*
13 tail call void %0() nounwind
14 ret void
15 }
16
17 define void @t2(i32 %a, i8* nocapture %value) nounwind {
18 entry:
19 ; 32: t2:
20 ; 32: jmpl *8(%esp)
21
22 ; 64: t2:
23 ; 64: jmpq *%rsi
24 %0 = bitcast i8* %value to void ()*
25 tail call void %0() nounwind
26 ret void
27 }
28
29 define void @t3(i32 %a, i32 %b, i32 %c, i32 %d, i32 %e, i32 %f, i8* nocapture %value) nounwind {
30 entry:
31 ; 32: t3:
32 ; 32: jmpl *28(%esp)
33
34 ; 64: t3:
35 ; 64: jmpq *8(%rsp)
36 %0 = bitcast i8* %value to void ()*
37 tail call void %0() nounwind
38 ret void
39 }
40
41 define void @t4(i32 %a, i32 %b, i32 %c, i32 %d, i32 %e, i32 %f, i32 %g, i8* nocapture %value) nounwind {
42 entry:
43 ; 32: t4:
44 ; 32: jmpl *32(%esp)
45
46 ; 64: t4:
47 ; 64: jmpq *16(%rsp)
48 %0 = bitcast i8* %value to void ()*
49 tail call void %0() nounwind
50 ret void
51 }