[PATCH] D22115: Teach FastISel about thiscall (and, hence, about callee-pop).
Nico Weber via llvm-commits
llvm-commits at lists.llvm.org
Thu Jul 7 15:29:13 PDT 2016
thakis created this revision.
thakis added reviewers: majnemer, rnk.
thakis added a subscriber: llvm-commits.
Without this, -O0 builds fail to use fast isel on all member functions in 32-bit Windows compiles: Fast ISel walks from back to front, and each ret on a member function uses thiscall.
Even with this patch, fast isel fails to lower thiscall calls, and it never fires in 64-bit Windows compiles, since those currently have an explicit early return too. Chrome/mac debug builds of the v8_base target get ~6% slower if I disable fast isel there, so it might be worth trying to get it to fire more often in Windows debug builds.
http://reviews.llvm.org/D22115
Files:
lib/Target/X86/X86FastISel.cpp
test/CodeGen/X86/fast-isel-x86.ll
Index: test/CodeGen/X86/fast-isel-x86.ll
===================================================================
--- test/CodeGen/X86/fast-isel-x86.ll
+++ test/CodeGen/X86/fast-isel-x86.ll
@@ -18,11 +18,18 @@
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
+}
+
; Properly initialize the pic base.
; CHECK-LABEL: test2:
; CHECK-NOT: HHH
-; CHECK: call{{.*}}L2$pb
-; CHECK-NEXT: L2$pb:
+; CHECK: call{{.*}}L3$pb
+; CHECK-NEXT: L3$pb:
; CHECK-NEXT: pop
; CHECK: HHH
; CHECK: retl
@@ -75,7 +82,7 @@
; 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-L6$pb(%eax), %eax
}
declare dllimport i32 @test5dllimport(i32)
Index: lib/Target/X86/X86FastISel.cpp
===================================================================
--- lib/Target/X86/X86FastISel.cpp
+++ lib/Target/X86/X86FastISel.cpp
@@ -1151,14 +1151,15 @@
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 @@
}
// 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;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D22115.63147.patch
Type: text/x-patch
Size: 2461 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160707/1f1b51c8/attachment.bin>
More information about the llvm-commits
mailing list