Fix fastcc structure return with fast-isel on x86-32
authorDerek Schuff <dschuff@google.com>
Fri, 27 Apr 2012 23:27:17 +0000 (23:27 +0000)
committerDerek Schuff <dschuff@google.com>
Fri, 27 Apr 2012 23:27:17 +0000 (23:27 +0000)
On x86-32, structure return via sret lets the callee pop the hidden
pointer argument off the stack, which the caller then re-pushes.
However if the calling convention is fastcc, then a register is used
instead, and the caller should not adjust the stack. This is
implemented with a check of IsTailCallConvention
X86TargetLowering::LowerCall but is now checked properly in
X86FastISel::DoSelectCall.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@155745 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Target/X86/X86FastISel.cpp
test/CodeGen/X86/fast-isel-x86.ll

index eca0e780828861cd648be5b7e988d3be5c03ad05..d757926c715ad37bf71a058ac25b1ede26801688 100644 (file)
@@ -1858,6 +1858,8 @@ bool X86FastISel::DoSelectCall(const Instruction *I, const char *MemIntName) {
   unsigned AdjStackUp = TII.getCallFrameDestroyOpcode();
   unsigned NumBytesCallee = 0;
   if (!Subtarget->is64Bit() && !Subtarget->isTargetWindows() &&
   unsigned AdjStackUp = TII.getCallFrameDestroyOpcode();
   unsigned NumBytesCallee = 0;
   if (!Subtarget->is64Bit() && !Subtarget->isTargetWindows() &&
+      !(CS.getCallingConv() == CallingConv::Fast ||
+        CS.getCallingConv() == CallingConv::GHC) &&
       CS.paramHasAttr(1, Attribute::StructRet))
     NumBytesCallee = 4;
   BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, TII.get(AdjStackUp))
       CS.paramHasAttr(1, Attribute::StructRet))
     NumBytesCallee = 4;
   BuildMI(*FuncInfo.MBB, FuncInfo.InsertPt, DL, TII.get(AdjStackUp))
index b9598bb465ce4f446735e1cca399e83b502a5b59..bd5c91491e09654f40c7c96d6396362a5d09386f 100644 (file)
@@ -46,3 +46,17 @@ entry:
 ; CHECK: addl $40
 }
 declare void @test3sret(%struct.a* sret)
 ; CHECK: addl $40
 }
 declare void @test3sret(%struct.a* sret)
+
+; Check that fast-isel sret works with fastcc (and does not callee-pop)
+define void @test4() nounwind ssp {
+entry:
+  %tmp = alloca %struct.a, align 8
+  call fastcc void @test4fastccsret(%struct.a* sret %tmp)
+  ret void
+; CHECK: test4:
+; CHECK: subl $44
+; CHECK: leal 16(%esp)
+; CHECK: calll _test4fastccsret
+; CHECK addl $40
+}
+declare fastcc void @test4fastccsret(%struct.a* sret)