Skip to content

Commit 7e01e64

Browse files
authored
[X86][vectorcall] Do not consume register for indirect return value (#97939)
This is how MSVC handles it. https://godbolt.org/z/Eav3vx7cd
1 parent f06cb3f commit 7e01e64

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

clang/lib/CodeGen/Targets/X86.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -469,7 +469,8 @@ bool X86_32ABIInfo::canExpandIndirectArgument(QualType Ty) const {
469469
ABIArgInfo X86_32ABIInfo::getIndirectReturnResult(QualType RetTy, CCState &State) const {
470470
// If the return value is indirect, then the hidden argument is consuming one
471471
// integer register.
472-
if (State.FreeRegs) {
472+
if (State.CC != llvm::CallingConv::X86_FastCall &&
473+
State.CC != llvm::CallingConv::X86_VectorCall && State.FreeRegs) {
473474
--State.FreeRegs;
474475
if (!IsMCUABI)
475476
return getNaturalAlignIndirectInReg(RetTy);

clang/test/CodeGen/stdcall-fastcall.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,3 +151,9 @@ void bar13(long long a, int b, int c) {
151151
// CHECK: call x86_fastcallcc void @foo13(i64 noundef %{{.*}}, i32 inreg noundef %{{.*}}, i32 inreg noundef %
152152
foo13(a, b, c);
153153
}
154+
155+
struct S2 __attribute__((fastcall)) foo14(int a) {
156+
// CHECK-LABEL: define dso_local x86_fastcallcc void @foo14(ptr dead_on_unwind noalias writable sret(%struct.S2) align 4 %agg.result, i32 inreg noundef %a)
157+
struct S2 r = {a};
158+
return r;
159+
}

clang/test/CodeGen/vectorcall.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ struct HVA4 __vectorcall hva6(struct HVA4 a, struct HVA4 b) { return b;}
9090
// X64: define dso_local x86_vectorcallcc %struct.HVA4 @"\01hva6@@128"(%struct.HVA4 inreg %a.coerce, ptr noundef %b)
9191

9292
struct HVA5 __vectorcall hva7(void) {struct HVA5 a = {}; return a;}
93-
// X86: define dso_local x86_vectorcallcc void @"\01hva7@@0"(ptr dead_on_unwind inreg noalias writable sret(%struct.HVA5) align 16 %agg.result)
93+
// X86: define dso_local x86_vectorcallcc void @"\01hva7@@0"(ptr dead_on_unwind noalias writable sret(%struct.HVA5) align 16 %agg.result)
9494
// X64: define dso_local x86_vectorcallcc void @"\01hva7@@0"(ptr dead_on_unwind noalias writable sret(%struct.HVA5) align 16 %agg.result)
9595

9696
v4f32 __vectorcall hva8(v4f32 a, v4f32 b, v4f32 c, v4f32 d, int e, v4f32 f) {return f;}

0 commit comments

Comments
 (0)