@@ -2000,8 +2000,9 @@ X86TargetLowering::LowerReturn(SDValue Chain,
2000
2000
RetOps.push_back(DAG.getRegister(VA.getLocReg(), VA.getLocVT()));
2001
2001
}
2002
2002
2003
- // All x86 ABIs require that for returning structs by value we copy
2003
+ // The x86-64 ABIs require that for returning structs by value we copy
2004
2004
// the sret argument into %rax/%eax (depending on ABI) for the return.
2005
+ // Win32 requires us to put the sret argument to %eax as well.
2005
2006
// We saved the argument into a virtual register in the entry block,
2006
2007
// so now we copy the value out and into %rax/%eax.
2007
2008
//
@@ -2010,6 +2011,8 @@ X86TargetLowering::LowerReturn(SDValue Chain,
2010
2011
// false, then an sret argument may be implicitly inserted in the SelDAG. In
2011
2012
// either case FuncInfo->setSRetReturnReg() will have been called.
2012
2013
if (unsigned SRetReg = FuncInfo->getSRetReturnReg()) {
2014
+ assert((Subtarget->is64Bit() || Subtarget->isTargetKnownWindowsMSVC()) &&
2015
+ "No need for an sret register");
2013
2016
SDValue Val = DAG.getCopyFromReg(Chain, dl, SRetReg, getPointerTy());
2014
2017
2015
2018
unsigned RetValReg
@@ -2431,21 +2434,24 @@ X86TargetLowering::LowerFormalArguments(SDValue Chain,
2431
2434
InVals.push_back(ArgValue);
2432
2435
}
2433
2436
2434
- for (unsigned i = 0, e = ArgLocs.size(); i != e; ++i) {
2435
- // All x86 ABIs require that for returning structs by value we copy the
2436
- // sret argument into %rax/%eax (depending on ABI) for the return. Save
2437
- // the argument into a virtual register so that we can access it from the
2438
- // return points.
2439
- if (Ins[i].Flags.isSRet()) {
2440
- unsigned Reg = FuncInfo->getSRetReturnReg();
2441
- if (!Reg) {
2442
- MVT PtrTy = getPointerTy();
2443
- Reg = MF.getRegInfo().createVirtualRegister(getRegClassFor(PtrTy));
2444
- FuncInfo->setSRetReturnReg(Reg);
2437
+ if (Subtarget->is64Bit() || Subtarget->isTargetKnownWindowsMSVC()) {
2438
+ for (unsigned i = 0, e = ArgLocs.size(); i != e; ++i) {
2439
+ // The x86-64 ABIs require that for returning structs by value we copy
2440
+ // the sret argument into %rax/%eax (depending on ABI) for the return.
2441
+ // Win32 requires us to put the sret argument to %eax as well.
2442
+ // Save the argument into a virtual register so that we can access it
2443
+ // from the return points.
2444
+ if (Ins[i].Flags.isSRet()) {
2445
+ unsigned Reg = FuncInfo->getSRetReturnReg();
2446
+ if (!Reg) {
2447
+ MVT PtrTy = getPointerTy();
2448
+ Reg = MF.getRegInfo().createVirtualRegister(getRegClassFor(PtrTy));
2449
+ FuncInfo->setSRetReturnReg(Reg);
2450
+ }
2451
+ SDValue Copy = DAG.getCopyToReg(DAG.getEntryNode(), dl, Reg, InVals[i]);
2452
+ Chain = DAG.getNode(ISD::TokenFactor, dl, MVT::Other, Copy, Chain);
2453
+ break;
2445
2454
}
2446
- SDValue Copy = DAG.getCopyToReg(DAG.getEntryNode(), dl, Reg, InVals[i]);
2447
- Chain = DAG.getNode(ISD::TokenFactor, dl, MVT::Other, Copy, Chain);
2448
- break;
2449
2455
}
2450
2456
}
2451
2457
0 commit comments