Skip to content

Commit 942fba9

Browse files
committed
Revert r237175: [X86] Always return the sret parameter in eax/rax ...
This commit broke an x86 test and the bots have been broken for well over an hour now so I'm just reverting. llvm-svn: 237210
1 parent a6ae877 commit 942fba9

File tree

3 files changed

+40
-56
lines changed

3 files changed

+40
-56
lines changed

llvm/lib/Target/X86/X86ISelLowering.cpp

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2000,8 +2000,9 @@ X86TargetLowering::LowerReturn(SDValue Chain,
20002000
RetOps.push_back(DAG.getRegister(VA.getLocReg(), VA.getLocVT()));
20012001
}
20022002

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
20042004
// 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.
20052006
// We saved the argument into a virtual register in the entry block,
20062007
// so now we copy the value out and into %rax/%eax.
20072008
//
@@ -2010,6 +2011,8 @@ X86TargetLowering::LowerReturn(SDValue Chain,
20102011
// false, then an sret argument may be implicitly inserted in the SelDAG. In
20112012
// either case FuncInfo->setSRetReturnReg() will have been called.
20122013
if (unsigned SRetReg = FuncInfo->getSRetReturnReg()) {
2014+
assert((Subtarget->is64Bit() || Subtarget->isTargetKnownWindowsMSVC()) &&
2015+
"No need for an sret register");
20132016
SDValue Val = DAG.getCopyFromReg(Chain, dl, SRetReg, getPointerTy());
20142017

20152018
unsigned RetValReg
@@ -2431,21 +2434,24 @@ X86TargetLowering::LowerFormalArguments(SDValue Chain,
24312434
InVals.push_back(ArgValue);
24322435
}
24332436

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;
24452454
}
2446-
SDValue Copy = DAG.getCopyToReg(DAG.getEntryNode(), dl, Reg, InVals[i]);
2447-
Chain = DAG.getNode(ISD::TokenFactor, dl, MVT::Other, Copy, Chain);
2448-
break;
24492455
}
24502456
}
24512457

llvm/test/CodeGen/X86/cmovcmov.ll

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -143,30 +143,30 @@ entry:
143143
; NOCMOV-NEXT: jp [[TBB]]
144144
; NOCMOV-NEXT: leal 24(%esp), %eax
145145
; NOCMOV-NEXT: [[TBB]]:
146-
; NOCMOV-NEXT: movl (%eax), %ecx
147-
; NOCMOV-NEXT: leal 44(%esp), %edx
146+
; NOCMOV-NEXT: movl (%eax), %eax
147+
; NOCMOV-NEXT: leal 44(%esp), %ecx
148148
; NOCMOV-NEXT: jne [[TBB:.LBB[0-9_]+]]
149149
; NOCMOV-NEXT: jp [[TBB]]
150-
; NOCMOV-NEXT: leal 28(%esp), %edx
150+
; NOCMOV-NEXT: leal 28(%esp), %ecx
151151
; NOCMOV-NEXT: [[TBB]]:
152-
; NOCMOV-NEXT: movl 12(%esp), %eax
153-
; NOCMOV-NEXT: movl (%edx), %edx
152+
; NOCMOV-NEXT: movl (%ecx), %ecx
154153
; NOCMOV-NEXT: leal 48(%esp), %esi
155154
; NOCMOV-NEXT: jne [[TBB:.LBB[0-9_]+]]
156155
; NOCMOV-NEXT: jp [[TBB]]
157156
; NOCMOV-NEXT: leal 32(%esp), %esi
158157
; NOCMOV-NEXT: [[TBB]]:
158+
; NOCMOV-NEXT: movl 12(%esp), %edx
159159
; NOCMOV-NEXT: movl (%esi), %esi
160160
; NOCMOV-NEXT: leal 52(%esp), %edi
161161
; NOCMOV-NEXT: jne [[TBB:.LBB[0-9_]+]]
162162
; NOCMOV-NEXT: jp [[TBB]]
163163
; NOCMOV-NEXT: leal 36(%esp), %edi
164164
; NOCMOV-NEXT: [[TBB]]:
165165
; NOCMOV-NEXT: movl (%edi), %edi
166-
; NOCMOV-NEXT: movl %edi, 12(%eax)
167-
; NOCMOV-NEXT: movl %esi, 8(%eax)
168-
; NOCMOV-NEXT: movl %edx, 4(%eax)
169-
; NOCMOV-NEXT: movl %ecx, (%eax)
166+
; NOCMOV-NEXT: movl %edi, 12(%edx)
167+
; NOCMOV-NEXT: movl %esi, 8(%edx)
168+
; NOCMOV-NEXT: movl %ecx, 4(%edx)
169+
; NOCMOV-NEXT: movl %eax, (%edx)
170170
; NOCMOV-NEXT: popl %esi
171171
; NOCMOV-NEXT: popl %edi
172172
; NOCMOV-NEXT: retl $4
Lines changed: 10 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,12 @@
1-
; RUN: llc -mtriple=x86_64-apple-darwin8 < %s | FileCheck %s --check-prefix=X64
2-
; RUN: llc -mtriple=x86_64-pc-linux < %s | FileCheck %s --check-prefix=X64
3-
; RUN: llc -mtriple=i686-pc-linux < %s | FileCheck %s --check-prefix=X86
4-
; RUN: llc -mtriple=x86_64-apple-darwin8 -terminal-rule < %s | FileCheck %s --check-prefix=X64
5-
; RUN: llc -mtriple=x86_64-pc-linux -terminal-rule < %s | FileCheck %s --check-prefix=X64
6-
7-
define void @sret_void(i32* sret %p) {
8-
store i32 0, i32* %p
9-
ret void
10-
}
11-
12-
; X64-LABEL: sret_void
13-
; X64-DAG: movl $0, (%rdi)
14-
; X64-DAG: movq %rdi, %rax
15-
; X64: retq
16-
17-
; X86-LABEL: sret_void
18-
; X86: movl 4(%esp), %eax
19-
; X86: movl $0, (%eax)
20-
; X86: retl
21-
22-
define i256 @sret_demoted() {
1+
; RUN: llc -mtriple=x86_64-apple-darwin8 < %s | FileCheck %s
2+
; RUN: llc -mtriple=x86_64-pc-linux < %s | FileCheck %s
3+
; RUN: llc -mtriple=x86_64-apple-darwin8 -terminal-rule < %s | FileCheck %s
4+
; RUN: llc -mtriple=x86_64-pc-linux -terminal-rule < %s | FileCheck %s
5+
6+
; CHECK-LABEL: return32
7+
; CHECK-DAG: movq $0, (%rdi)
8+
; CHECK-DAG: movq %rdi, %rax
9+
; CHECK: retq
10+
define i256 @return32() {
2311
ret i256 0
2412
}
25-
26-
; X64-LABEL: sret_demoted
27-
; X64-DAG: movq $0, (%rdi)
28-
; X64-DAG: movq %rdi, %rax
29-
; X64: retq
30-
31-
; X86-LABEL: sret_demoted
32-
; X86: movl 4(%esp), %eax
33-
; X86: movl $0, (%eax)
34-
; X86: retl

0 commit comments

Comments
 (0)