-
Notifications
You must be signed in to change notification settings - Fork 15k
[clang][CodeGen][MSVC] Match how MSVC returns vector types from member functions #157365
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
henrybw
wants to merge
8
commits into
llvm:main
Choose a base branch
from
henrybw:ms-abi-vector-types
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
8f42b86
[clang][CodeGen][MSVC] Return vector types from methods indirectly
henrybw fd8dd19
amend! [clang][CodeGen][MSVC] Return vector types from methods indire…
henrybw 5970180
fixup! [clang][CodeGen][MSVC] Return vector types from methods indire…
henrybw 017bfea
fixup! [clang][CodeGen][MSVC] Return vector types from methods indire…
henrybw c0f4b22
amend! [clang][CodeGen][MSVC] Return vector types from methods indire…
henrybw c6b0cd3
fixup! [clang][CodeGen][MSVC] Return vector types from methods indire…
henrybw 71cd7fd
fixup! [clang][CodeGen][MSVC] Return vector types from methods indire…
henrybw 2964b82
fixup! [clang][CodeGen][MSVC] Return vector types from methods indire…
henrybw File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| // RUN: %clang_cc1 -ffreestanding -emit-llvm %s -o - -triple=i686-pc-windows-msvc \ | ||
| // RUN: | FileCheck --check-prefixes=CHECK,X86 %s | ||
| // RUN: %clang_cc1 -ffreestanding -emit-llvm %s -o - -triple=x86_64-pc-windows-msvc \ | ||
| // RUN: | FileCheck --check-prefixes=CHECK,X86 %s | ||
| // RUN: %clang_cc1 -ffreestanding -emit-llvm %s -o - -triple=aarch64-pc-windows-msvc \ | ||
| // RUN: | FileCheck --check-prefixes=CHECK,AARCH64 %s | ||
| // RUN: %clang_cc1 -ffreestanding -emit-llvm %s -o - -triple=i686-pc-windows-msvc \ | ||
| // RUN: -fclang-abi-compat=21 | FileCheck --check-prefixes=CHECK,CLANG21 %s | ||
| // RUN: %clang_cc1 -ffreestanding -emit-llvm %s -o - -triple=x86_64-pc-windows-msvc \ | ||
| // RUN: -fclang-abi-compat=21 | FileCheck --check-prefixes=CHECK,CLANG21 %s | ||
| // RUN: %clang_cc1 -ffreestanding -emit-llvm %s -o - -triple=aarch64-pc-windows-msvc \ | ||
| // RUN: -fclang-abi-compat=21 | FileCheck --check-prefixes=CHECK,CLANG21 %s | ||
|
|
||
| // To match the MSVC ABI, vector types are usually returned directly, but on x86 | ||
| // and x86-64 they must be returned indirectly from member functions (unless | ||
| // they use the vectorcall calling convention and the vector type is > 64 bits). | ||
|
|
||
| #if defined(__i386__) || defined(__x86_64__) | ||
| #include <xmmintrin.h> | ||
|
|
||
| #define VECTOR64_TYPE __m64 | ||
| #define VECTOR128_TYPE __m128 | ||
|
|
||
| #define VECTORCALL __vectorcall | ||
| #endif | ||
|
|
||
| #ifdef __aarch64__ | ||
| #include <arm_neon.h> | ||
|
|
||
| // These were chosen such that they lower to the same types that the x86 vector | ||
| // types lower to (e.g. int64x1_t and __m64 both lower to <1 x i64>). | ||
| #define VECTOR64_TYPE int64x1_t | ||
| #define VECTOR128_TYPE float32x4_t | ||
|
|
||
| #define VECTORCALL | ||
| #endif | ||
|
|
||
| struct Foo { | ||
| VECTOR64_TYPE method_ret_vec64(); | ||
| VECTOR128_TYPE method_ret_vec128(); | ||
|
|
||
| VECTOR64_TYPE VECTORCALL vc_method_ret_vec64(); | ||
| VECTOR128_TYPE VECTORCALL vc_method_ret_vec128(); | ||
| }; | ||
|
|
||
| VECTOR64_TYPE Foo::method_ret_vec64() { | ||
| return VECTOR64_TYPE{}; | ||
| // X86: store <1 x i64> | ||
| // X86: ret void | ||
| // AARCH64: ret <1 x i64> | ||
| // CLANG21: ret <1 x i64> | ||
| } | ||
|
|
||
| VECTOR128_TYPE Foo::method_ret_vec128() { | ||
| return VECTOR128_TYPE{}; | ||
| // X86: store <4 x float> | ||
| // X86: ret void | ||
| // AARCH64: ret <4 x float> | ||
| // CLANG21: ret <4 x float> | ||
| } | ||
|
|
||
| VECTOR64_TYPE VECTORCALL Foo::vc_method_ret_vec64() { | ||
| return VECTOR64_TYPE{}; | ||
| // X86: store <1 x i64> | ||
| // X86: ret void | ||
| // AARCH64: ret <1 x i64> | ||
| // CLANG21: ret <1 x i64> | ||
| } | ||
|
|
||
| VECTOR128_TYPE VECTORCALL Foo::vc_method_ret_vec128() { | ||
| return VECTOR128_TYPE{}; | ||
| // CHECK: ret <4 x float> | ||
| } | ||
|
|
||
| VECTOR64_TYPE func_ret_vec64() { | ||
| return VECTOR64_TYPE{}; | ||
| // CHECK: ret <1 x i64> | ||
| } | ||
|
|
||
| VECTOR128_TYPE func_ret_vec128() { | ||
| return VECTOR128_TYPE{}; | ||
| // CHECK: ret <4 x float> | ||
| } | ||
|
|
||
| VECTOR64_TYPE VECTORCALL vc_func_ret_vec64() { | ||
| return VECTOR64_TYPE{}; | ||
| // CHECK: ret <1 x i64> | ||
| } | ||
|
|
||
| VECTOR128_TYPE VECTORCALL vc_func_ret_vec128() { | ||
| return VECTOR128_TYPE{}; | ||
| // CHECK: ret <4 x float> | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please extend this test to cover arm64. I fed it to an AI tool and it did the straightforward rewrite, which I think you can adapt with some ifdefs to make this a single test case:
https://godbolt.org/z/xWon6163j
This demonstrates that ARM64 passes vectors directly. Honestly, I found that surprising, because if you look into arm(64)_neon.h, you see that MSVC defines vectors as "intrinsic_type" structs, so it makes sense that "records" go down the path of "instance methods return structs indirectly".
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. (I was also surprised by MSVC returning vectors directly on ARM64, but that's also why I constrained this behavior to only apply to x86/x86-64 targets.)