Skip to content

Commit

Permalink
[X86][vectorcall] Do not consume register for indirect return value (#…
Browse files Browse the repository at this point in the history
…97939)

This is how MSVC handles it. https://godbolt.org/z/Eav3vx7cd
  • Loading branch information
phoebewang committed Jul 8, 2024
1 parent f06cb3f commit 7e01e64
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 2 deletions.
3 changes: 2 additions & 1 deletion clang/lib/CodeGen/Targets/X86.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,8 @@ bool X86_32ABIInfo::canExpandIndirectArgument(QualType Ty) const {
ABIArgInfo X86_32ABIInfo::getIndirectReturnResult(QualType RetTy, CCState &State) const {
// If the return value is indirect, then the hidden argument is consuming one
// integer register.
if (State.FreeRegs) {
if (State.CC != llvm::CallingConv::X86_FastCall &&
State.CC != llvm::CallingConv::X86_VectorCall && State.FreeRegs) {
--State.FreeRegs;
if (!IsMCUABI)
return getNaturalAlignIndirectInReg(RetTy);
Expand Down
6 changes: 6 additions & 0 deletions clang/test/CodeGen/stdcall-fastcall.c
Original file line number Diff line number Diff line change
Expand Up @@ -151,3 +151,9 @@ void bar13(long long a, int b, int c) {
// CHECK: call x86_fastcallcc void @foo13(i64 noundef %{{.*}}, i32 inreg noundef %{{.*}}, i32 inreg noundef %
foo13(a, b, c);
}

struct S2 __attribute__((fastcall)) foo14(int a) {
// 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)
struct S2 r = {a};
return r;
}
2 changes: 1 addition & 1 deletion clang/test/CodeGen/vectorcall.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ struct HVA4 __vectorcall hva6(struct HVA4 a, struct HVA4 b) { return b;}
// X64: define dso_local x86_vectorcallcc %struct.HVA4 @"\01hva6@@128"(%struct.HVA4 inreg %a.coerce, ptr noundef %b)

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

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

0 comments on commit 7e01e64

Please sign in to comment.