[llvm] r275135 - Teach FastISel about thiscall (and, hence, about callee-pop).
Nico Weber via llvm-commits
llvm-commits at lists.llvm.org
Mon Jul 11 18:30:35 PDT 2016
Author: nico
Date: Mon Jul 11 20:30:35 2016
New Revision: 275135
URL: http://llvm.org/viewvc/llvm-project?rev=275135&view=rev
Log:
Teach FastISel about thiscall (and, hence, about callee-pop).
http://reviews.llvm.org/D22115
Modified:
llvm/trunk/lib/Target/X86/X86FastISel.cpp
llvm/trunk/test/CodeGen/X86/fast-isel-x86.ll
Modified: llvm/trunk/lib/Target/X86/X86FastISel.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/X86/X86FastISel.cpp?rev=275135&r1=275134&r2=275135&view=diff
==============================================================================
--- llvm/trunk/lib/Target/X86/X86FastISel.cpp (original)
+++ llvm/trunk/lib/Target/X86/X86FastISel.cpp Mon Jul 11 20:30:35 2016
@@ -1151,14 +1151,15 @@ bool X86FastISel::X86SelectRet(const Ins
if (CC != CallingConv::C &&
CC != CallingConv::Fast &&
CC != CallingConv::X86_FastCall &&
+ CC != CallingConv::X86_ThisCall &&
CC != CallingConv::X86_64_SysV)
return false;
if (Subtarget->isCallingConvWin64(CC))
return false;
- // Don't handle popping bytes on return for now.
- if (X86MFInfo->getBytesToPopOnReturn() != 0)
+ // Don't handle popping bytes if they don't fit the ret's immediate.
+ if (!isUInt<16>(X86MFInfo->getBytesToPopOnReturn()))
return false;
// fastcc with -tailcallopt is intended to provide a guaranteed
@@ -1261,9 +1262,15 @@ bool X86FastISel::X86SelectRet(const Ins
}
// Now emit the RET.
- MachineInstrBuilder MIB =
- BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
- TII.get(Subtarget->is64Bit() ? X86::RETQ : X86::RETL));
+ MachineInstrBuilder MIB;
+ if (X86MFInfo->getBytesToPopOnReturn()) {
+ MIB = BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
+ TII.get(Subtarget->is64Bit() ? X86::RETIQ : X86::RETIL))
+ .addImm(X86MFInfo->getBytesToPopOnReturn());
+ } else {
+ MIB = BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DbgLoc,
+ TII.get(Subtarget->is64Bit() ? X86::RETQ : X86::RETL));
+ }
for (unsigned i = 0, e = RetRegs.size(); i != e; ++i)
MIB.addReg(RetRegs[i], RegState::Implicit);
return true;
Modified: llvm/trunk/test/CodeGen/X86/fast-isel-x86.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/CodeGen/X86/fast-isel-x86.ll?rev=275135&r1=275134&r2=275135&view=diff
==============================================================================
--- llvm/trunk/test/CodeGen/X86/fast-isel-x86.ll (original)
+++ llvm/trunk/test/CodeGen/X86/fast-isel-x86.ll Mon Jul 11 20:30:35 2016
@@ -18,11 +18,29 @@ define void @test1({i32, i32, i32, i32}*
ret void
}
+; This should pop 8 bytes on return.
+; CHECK-LABEL: thiscallfun:
+; CHECK: retl $8
+define x86_thiscallcc void @thiscallfun(i32* %this, i32 %a, i32 %b) nounwind {
+ ret void
+}
+
+; Here, the callee pop doesn't fit the 16 bit immediate -- see x86-big-ret.ll
+; This checks that -fast-isel doesn't miscompile this.
+; CHECK-LABEL: thiscall_large:
+; CHECK: popl %ecx
+; CHECK-NEXT: addl $65536, %esp
+; CHECK-NEXT: pushl %ecx
+; CHECK-NEXT: retl
+define x86_thiscallcc void @thiscall_large(i32* %this, [65533 x i8]* byval %b) nounwind {
+ ret void
+}
+
; Properly initialize the pic base.
; CHECK-LABEL: test2:
; CHECK-NOT: HHH
-; CHECK: call{{.*}}L2$pb
-; CHECK-NEXT: L2$pb:
+; CHECK: call{{.*}}L4$pb
+; CHECK-NEXT: L4$pb:
; CHECK-NEXT: pop
; CHECK: HHH
; CHECK: retl
@@ -75,7 +93,7 @@ entry:
; SDag-ISel's arg push:
; CHECK: movl %esp, [[REGISTER:%[a-z]+]]
; CHECK: movl $42, ([[REGISTER]])
-; CHECK: movl L_test5dllimport$non_lazy_ptr-L5$pb(%eax), %eax
+; CHECK: movl L_test5dllimport$non_lazy_ptr-L7$pb(%eax), %eax
}
declare dllimport i32 @test5dllimport(i32)
More information about the llvm-commits
mailing list