-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[amdgpu] Pass variadic arguments without splitting #94083
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
Merged
JonChesterfield
merged 1 commit into
llvm:main
from
JonChesterfield:jc_varargs_amdgpu_abi_subset
Jun 4, 2024
Merged
Changes from all commits
Commits
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,293 @@ | ||
// REQUIRES: amdgpu-registered-target | ||
// NOTE: Assertions have been autogenerated by utils/update_cc_test_checks.py UTC_ARGS: --function-signature | ||
// RUN: %clang_cc1 -cc1 -std=c23 -triple amdgcn-amd-amdhsa -emit-llvm -O1 %s -o - | FileCheck %s | ||
|
||
void sink_0(...); | ||
void sink_1(int, ...); | ||
void sink_2(double, int, ...); | ||
|
||
// Simple scalar values | ||
|
||
// CHECK-LABEL: define {{[^@]+}}@zero_varargs | ||
// CHECK-SAME: (i32 noundef [[F0:%.*]], double noundef [[F1:%.*]]) local_unnamed_addr #[[ATTR0:[0-9]+]] { | ||
// CHECK-NEXT: entry: | ||
// CHECK-NEXT: tail call void (...) @sink_0() #[[ATTR2:[0-9]+]] | ||
// CHECK-NEXT: tail call void (i32, ...) @sink_1(i32 noundef [[F0]]) #[[ATTR2]] | ||
// CHECK-NEXT: tail call void (double, i32, ...) @sink_2(double noundef [[F1]], i32 noundef [[F0]]) #[[ATTR2]] | ||
// CHECK-NEXT: ret void | ||
// | ||
void zero_varargs(int f0, double f1) | ||
{ | ||
sink_0(); | ||
sink_1(f0); | ||
sink_2(f1, f0); | ||
} | ||
|
||
// CHECK-LABEL: define {{[^@]+}}@one_i32 | ||
// CHECK-SAME: (i32 noundef [[F0:%.*]], double noundef [[F1:%.*]], i32 noundef [[V0:%.*]]) local_unnamed_addr #[[ATTR0]] { | ||
// CHECK-NEXT: entry: | ||
// CHECK-NEXT: tail call void (...) @sink_0(i32 noundef [[V0]]) #[[ATTR2]] | ||
// CHECK-NEXT: tail call void (i32, ...) @sink_1(i32 noundef [[F0]], i32 noundef [[V0]]) #[[ATTR2]] | ||
// CHECK-NEXT: tail call void (double, i32, ...) @sink_2(double noundef [[F1]], i32 noundef [[F0]], i32 noundef [[V0]]) #[[ATTR2]] | ||
// CHECK-NEXT: ret void | ||
// | ||
void one_i32(int f0, double f1, int v0) | ||
{ | ||
sink_0(v0); | ||
sink_1(f0, v0); | ||
sink_2(f1, f0, v0); | ||
} | ||
|
||
// CHECK-LABEL: define {{[^@]+}}@one_ptr | ||
// CHECK-SAME: (i32 noundef [[F0:%.*]], double noundef [[F1:%.*]], ptr noundef [[V0:%.*]]) local_unnamed_addr #[[ATTR0]] { | ||
// CHECK-NEXT: entry: | ||
// CHECK-NEXT: tail call void (...) @sink_0(ptr noundef [[V0]]) #[[ATTR2]] | ||
// CHECK-NEXT: tail call void (i32, ...) @sink_1(i32 noundef [[F0]], ptr noundef [[V0]]) #[[ATTR2]] | ||
// CHECK-NEXT: tail call void (double, i32, ...) @sink_2(double noundef [[F1]], i32 noundef [[F0]], ptr noundef [[V0]]) #[[ATTR2]] | ||
// CHECK-NEXT: ret void | ||
// | ||
void one_ptr(int f0, double f1, void* v0) | ||
{ | ||
sink_0(v0); | ||
sink_1(f0, v0); | ||
sink_2(f1, f0, v0); | ||
} | ||
|
||
// CHECK-LABEL: define {{[^@]+}}@one_f64 | ||
// CHECK-SAME: (i32 noundef [[F0:%.*]], double noundef [[F1:%.*]], double noundef [[V0:%.*]]) local_unnamed_addr #[[ATTR0]] { | ||
// CHECK-NEXT: entry: | ||
// CHECK-NEXT: tail call void (...) @sink_0(double noundef [[V0]]) #[[ATTR2]] | ||
// CHECK-NEXT: tail call void (i32, ...) @sink_1(i32 noundef [[F0]], double noundef [[V0]]) #[[ATTR2]] | ||
// CHECK-NEXT: tail call void (double, i32, ...) @sink_2(double noundef [[F1]], i32 noundef [[F0]], double noundef [[V0]]) #[[ATTR2]] | ||
// CHECK-NEXT: ret void | ||
// | ||
void one_f64(int f0, double f1, double v0) | ||
{ | ||
sink_0(v0); | ||
sink_1(f0, v0); | ||
sink_2(f1, f0, v0); | ||
} | ||
|
||
|
||
// C has various type promotion rules for variadics | ||
|
||
// CHECK-LABEL: define {{[^@]+}}@one_i8 | ||
// CHECK-SAME: (i32 noundef [[F0:%.*]], double noundef [[F1:%.*]], i8 noundef signext [[V0:%.*]]) local_unnamed_addr #[[ATTR0]] { | ||
// CHECK-NEXT: entry: | ||
// CHECK-NEXT: [[CONV:%.*]] = sext i8 [[V0]] to i32 | ||
// CHECK-NEXT: tail call void (...) @sink_0(i32 noundef [[CONV]]) #[[ATTR2]] | ||
// CHECK-NEXT: tail call void (i32, ...) @sink_1(i32 noundef [[F0]], i32 noundef [[CONV]]) #[[ATTR2]] | ||
// CHECK-NEXT: tail call void (double, i32, ...) @sink_2(double noundef [[F1]], i32 noundef [[F0]], i32 noundef [[CONV]]) #[[ATTR2]] | ||
// CHECK-NEXT: ret void | ||
// | ||
void one_i8(int f0, double f1, char v0) | ||
{ | ||
sink_0(v0); | ||
sink_1(f0, v0); | ||
sink_2(f1, f0, v0); | ||
} | ||
|
||
// CHECK-LABEL: define {{[^@]+}}@one_i16 | ||
// CHECK-SAME: (i32 noundef [[F0:%.*]], double noundef [[F1:%.*]], i16 noundef signext [[V0:%.*]]) local_unnamed_addr #[[ATTR0]] { | ||
// CHECK-NEXT: entry: | ||
// CHECK-NEXT: [[CONV:%.*]] = sext i16 [[V0]] to i32 | ||
// CHECK-NEXT: tail call void (...) @sink_0(i32 noundef [[CONV]]) #[[ATTR2]] | ||
// CHECK-NEXT: tail call void (i32, ...) @sink_1(i32 noundef [[F0]], i32 noundef [[CONV]]) #[[ATTR2]] | ||
// CHECK-NEXT: tail call void (double, i32, ...) @sink_2(double noundef [[F1]], i32 noundef [[F0]], i32 noundef [[CONV]]) #[[ATTR2]] | ||
// CHECK-NEXT: ret void | ||
// | ||
void one_i16(int f0, double f1, short v0) | ||
{ | ||
sink_0(v0); | ||
sink_1(f0, v0); | ||
sink_2(f1, f0, v0); | ||
} | ||
|
||
// CHECK-LABEL: define {{[^@]+}}@one_f32 | ||
// CHECK-SAME: (i32 noundef [[F0:%.*]], double noundef [[F1:%.*]], float noundef [[V0:%.*]]) local_unnamed_addr #[[ATTR0]] { | ||
// CHECK-NEXT: entry: | ||
// CHECK-NEXT: [[CONV:%.*]] = fpext float [[V0]] to double | ||
// CHECK-NEXT: tail call void (...) @sink_0(double noundef [[CONV]]) #[[ATTR2]] | ||
// CHECK-NEXT: tail call void (i32, ...) @sink_1(i32 noundef [[F0]], double noundef [[CONV]]) #[[ATTR2]] | ||
// CHECK-NEXT: tail call void (double, i32, ...) @sink_2(double noundef [[F1]], i32 noundef [[F0]], double noundef [[CONV]]) #[[ATTR2]] | ||
// CHECK-NEXT: ret void | ||
// | ||
void one_f32(int f0, double f1, float v0) | ||
{ | ||
sink_0(v0); | ||
sink_1(f0, v0); | ||
sink_2(f1, f0, v0); | ||
} | ||
|
||
|
||
// Various half types. _Float16 is passed as half and __fp16 as double | ||
|
||
// CHECK-LABEL: define {{[^@]+}}@one_f16a | ||
// CHECK-SAME: (i32 noundef [[F0:%.*]], double noundef [[F1:%.*]], half noundef [[V0:%.*]]) local_unnamed_addr #[[ATTR0]] { | ||
// CHECK-NEXT: entry: | ||
// CHECK-NEXT: tail call void (...) @sink_0(half noundef [[V0]]) #[[ATTR2]] | ||
// CHECK-NEXT: tail call void (i32, ...) @sink_1(i32 noundef [[F0]], half noundef [[V0]]) #[[ATTR2]] | ||
// CHECK-NEXT: tail call void (double, i32, ...) @sink_2(double noundef [[F1]], i32 noundef [[F0]], half noundef [[V0]]) #[[ATTR2]] | ||
// CHECK-NEXT: ret void | ||
// | ||
void one_f16a(int f0, double f1, _Float16 v0) | ||
{ | ||
sink_0(v0); | ||
sink_1(f0, v0); | ||
sink_2(f1, f0, v0); | ||
} | ||
|
||
// CHECK-LABEL: define {{[^@]+}}@one_f16b | ||
// CHECK-SAME: (i32 noundef [[F0:%.*]], double noundef [[F1:%.*]], half noundef [[V0:%.*]]) local_unnamed_addr #[[ATTR0]] { | ||
// CHECK-NEXT: entry: | ||
// CHECK-NEXT: [[CONV:%.*]] = fpext half [[V0]] to double | ||
// CHECK-NEXT: tail call void (...) @sink_0(double noundef [[CONV]]) #[[ATTR2]] | ||
// CHECK-NEXT: tail call void (i32, ...) @sink_1(i32 noundef [[F0]], double noundef [[CONV]]) #[[ATTR2]] | ||
// CHECK-NEXT: tail call void (double, i32, ...) @sink_2(double noundef [[F1]], i32 noundef [[F0]], double noundef [[CONV]]) #[[ATTR2]] | ||
// CHECK-NEXT: ret void | ||
// | ||
void one_f16b(int f0, double f1, __fp16 v0) | ||
{ | ||
sink_0(v0); | ||
sink_1(f0, v0); | ||
sink_2(f1, f0, v0); | ||
} | ||
|
||
// CHECK-LABEL: define {{[^@]+}}@one_f16c | ||
// CHECK-SAME: (i32 noundef [[F0:%.*]], double noundef [[F1:%.*]], bfloat noundef [[V0:%.*]]) local_unnamed_addr #[[ATTR0]] { | ||
// CHECK-NEXT: entry: | ||
// CHECK-NEXT: tail call void (...) @sink_0(bfloat noundef [[V0]]) #[[ATTR2]] | ||
// CHECK-NEXT: tail call void (i32, ...) @sink_1(i32 noundef [[F0]], bfloat noundef [[V0]]) #[[ATTR2]] | ||
// CHECK-NEXT: tail call void (double, i32, ...) @sink_2(double noundef [[F1]], i32 noundef [[F0]], bfloat noundef [[V0]]) #[[ATTR2]] | ||
// CHECK-NEXT: ret void | ||
// | ||
void one_f16c(int f0, double f1, __bf16 v0) | ||
{ | ||
sink_0(v0); | ||
sink_1(f0, v0); | ||
sink_2(f1, f0, v0); | ||
} | ||
|
||
// Simple composites | ||
|
||
typedef struct | ||
{ | ||
double x0; | ||
double x1; | ||
} pair_f64; | ||
|
||
// CHECK-LABEL: define {{[^@]+}}@one_pair_f64 | ||
// CHECK-SAME: (i32 noundef [[F0:%.*]], double noundef [[F1:%.*]], double [[V0_COERCE0:%.*]], double [[V0_COERCE1:%.*]]) local_unnamed_addr #[[ATTR0]] { | ||
// CHECK-NEXT: entry: | ||
// CHECK-NEXT: [[DOTFCA_0_INSERT:%.*]] = insertvalue [[STRUCT_PAIR_F64:%.*]] poison, double [[V0_COERCE0]], 0 | ||
// CHECK-NEXT: [[DOTFCA_1_INSERT:%.*]] = insertvalue [[STRUCT_PAIR_F64]] [[DOTFCA_0_INSERT]], double [[V0_COERCE1]], 1 | ||
// CHECK-NEXT: tail call void (...) @sink_0([[STRUCT_PAIR_F64]] [[DOTFCA_1_INSERT]]) #[[ATTR2]] | ||
// CHECK-NEXT: tail call void (i32, ...) @sink_1(i32 noundef [[F0]], [[STRUCT_PAIR_F64]] [[DOTFCA_1_INSERT]]) #[[ATTR2]] | ||
// CHECK-NEXT: tail call void (double, i32, ...) @sink_2(double noundef [[F1]], i32 noundef [[F0]], [[STRUCT_PAIR_F64]] [[DOTFCA_1_INSERT]]) #[[ATTR2]] | ||
// CHECK-NEXT: ret void | ||
// | ||
void one_pair_f64(int f0, double f1, pair_f64 v0) | ||
{ | ||
sink_0(v0); | ||
sink_1(f0, v0); | ||
sink_2(f1, f0, v0); | ||
} | ||
|
||
typedef double v2f64 __attribute__((ext_vector_type(2))); | ||
|
||
// CHECK-LABEL: define {{[^@]+}}@one_pair_v2f64 | ||
// CHECK-SAME: (i32 noundef [[F0:%.*]], double noundef [[F1:%.*]], <2 x double> noundef [[V0:%.*]]) local_unnamed_addr #[[ATTR0]] { | ||
// CHECK-NEXT: entry: | ||
// CHECK-NEXT: tail call void (...) @sink_0(<2 x double> noundef [[V0]]) #[[ATTR2]] | ||
// CHECK-NEXT: tail call void (i32, ...) @sink_1(i32 noundef [[F0]], <2 x double> noundef [[V0]]) #[[ATTR2]] | ||
// CHECK-NEXT: tail call void (double, i32, ...) @sink_2(double noundef [[F1]], i32 noundef [[F0]], <2 x double> noundef [[V0]]) #[[ATTR2]] | ||
// CHECK-NEXT: ret void | ||
// | ||
void one_pair_v2f64(int f0, double f1, v2f64 v0) | ||
{ | ||
sink_0(v0); | ||
sink_1(f0, v0); | ||
sink_2(f1, f0, v0); | ||
} | ||
|
||
typedef union | ||
{ | ||
float x0; | ||
int x1; | ||
} union_f32_i32; | ||
|
||
// CHECK-LABEL: define {{[^@]+}}@one_pair_union_f32_i32 | ||
// CHECK-SAME: (i32 noundef [[F0:%.*]], double noundef [[F1:%.*]], i32 [[V0_COERCE:%.*]]) local_unnamed_addr #[[ATTR0]] { | ||
// CHECK-NEXT: entry: | ||
// CHECK-NEXT: [[TMP0:%.*]] = bitcast i32 [[V0_COERCE]] to float | ||
// CHECK-NEXT: [[DOTFCA_0_INSERT:%.*]] = insertvalue [[UNION_UNION_F32_I32:%.*]] poison, float [[TMP0]], 0 | ||
// CHECK-NEXT: tail call void (...) @sink_0([[UNION_UNION_F32_I32]] [[DOTFCA_0_INSERT]]) #[[ATTR2]] | ||
// CHECK-NEXT: tail call void (i32, ...) @sink_1(i32 noundef [[F0]], [[UNION_UNION_F32_I32]] [[DOTFCA_0_INSERT]]) #[[ATTR2]] | ||
// CHECK-NEXT: tail call void (double, i32, ...) @sink_2(double noundef [[F1]], i32 noundef [[F0]], [[UNION_UNION_F32_I32]] [[DOTFCA_0_INSERT]]) #[[ATTR2]] | ||
// CHECK-NEXT: ret void | ||
// | ||
void one_pair_union_f32_i32(int f0, double f1, union_f32_i32 v0) | ||
{ | ||
sink_0(v0); | ||
sink_1(f0, v0); | ||
sink_2(f1, f0, v0); | ||
} | ||
|
||
typedef union | ||
{ | ||
int x0; | ||
float x1; | ||
} transparent_union_f32_i32 __attribute__((transparent_union)); | ||
|
||
// CHECK-LABEL: define {{[^@]+}}@one_pair_transparent_union_f32_i32 | ||
// CHECK-SAME: (i32 noundef [[F0:%.*]], double noundef [[F1:%.*]], i32 [[V0_COERCE:%.*]]) local_unnamed_addr #[[ATTR0]] { | ||
// CHECK-NEXT: entry: | ||
// CHECK-NEXT: [[DOTFCA_0_INSERT:%.*]] = insertvalue [[UNION_TRANSPARENT_UNION_F32_I32:%.*]] poison, i32 [[V0_COERCE]], 0 | ||
// CHECK-NEXT: tail call void (...) @sink_0([[UNION_TRANSPARENT_UNION_F32_I32]] [[DOTFCA_0_INSERT]]) #[[ATTR2]] | ||
// CHECK-NEXT: tail call void (i32, ...) @sink_1(i32 noundef [[F0]], [[UNION_TRANSPARENT_UNION_F32_I32]] [[DOTFCA_0_INSERT]]) #[[ATTR2]] | ||
// CHECK-NEXT: tail call void (double, i32, ...) @sink_2(double noundef [[F1]], i32 noundef [[F0]], [[UNION_TRANSPARENT_UNION_F32_I32]] [[DOTFCA_0_INSERT]]) #[[ATTR2]] | ||
// CHECK-NEXT: ret void | ||
// | ||
void one_pair_transparent_union_f32_i32(int f0, double f1, transparent_union_f32_i32 v0) | ||
{ | ||
sink_0(v0); | ||
sink_1(f0, v0); | ||
sink_2(f1, f0, v0); | ||
} | ||
|
||
// Passing multiple values in the variadic pack | ||
|
||
// CHECK-LABEL: define {{[^@]+}}@multiple_one | ||
// CHECK-SAME: (i32 noundef [[F0:%.*]], double noundef [[F1:%.*]], i32 noundef [[V0:%.*]], double noundef [[V1:%.*]]) local_unnamed_addr #[[ATTR0]] { | ||
// CHECK-NEXT: entry: | ||
// CHECK-NEXT: tail call void (...) @sink_0(i32 noundef [[V0]], double noundef [[V1]]) #[[ATTR2]] | ||
// CHECK-NEXT: tail call void (i32, ...) @sink_1(i32 noundef [[F0]], i32 noundef [[V0]], double noundef [[V1]]) #[[ATTR2]] | ||
// CHECK-NEXT: tail call void (double, i32, ...) @sink_2(double noundef [[F1]], i32 noundef [[F0]], i32 noundef [[V0]], double noundef [[V1]]) #[[ATTR2]] | ||
// CHECK-NEXT: ret void | ||
// | ||
void multiple_one(int f0, double f1, int v0, double v1) | ||
{ | ||
sink_0(v0, v1); | ||
sink_1(f0, v0, v1); | ||
sink_2(f1, f0, v0, v1); | ||
} | ||
|
||
// CHECK-LABEL: define {{[^@]+}}@multiple_two | ||
// CHECK-SAME: (i32 noundef [[F0:%.*]], double noundef [[F1:%.*]], double [[V0_COERCE0:%.*]], double [[V0_COERCE1:%.*]], float noundef [[V1:%.*]], i32 [[V2_COERCE:%.*]], i32 noundef [[V3:%.*]]) local_unnamed_addr #[[ATTR0]] { | ||
// CHECK-NEXT: entry: | ||
// CHECK-NEXT: [[TMP0:%.*]] = bitcast i32 [[V2_COERCE]] to float | ||
// CHECK-NEXT: [[CONV:%.*]] = fpext float [[V1]] to double | ||
// CHECK-NEXT: [[DOTFCA_0_INSERT16:%.*]] = insertvalue [[STRUCT_PAIR_F64:%.*]] poison, double [[V0_COERCE0]], 0 | ||
// CHECK-NEXT: [[DOTFCA_1_INSERT:%.*]] = insertvalue [[STRUCT_PAIR_F64]] [[DOTFCA_0_INSERT16]], double [[V0_COERCE1]], 1 | ||
// CHECK-NEXT: [[DOTFCA_0_INSERT:%.*]] = insertvalue [[UNION_UNION_F32_I32:%.*]] poison, float [[TMP0]], 0 | ||
// CHECK-NEXT: tail call void (...) @sink_0([[STRUCT_PAIR_F64]] [[DOTFCA_1_INSERT]], double noundef [[CONV]], [[UNION_UNION_F32_I32]] [[DOTFCA_0_INSERT]], i32 noundef [[V3]]) #[[ATTR2]] | ||
// CHECK-NEXT: tail call void (i32, ...) @sink_1(i32 noundef [[F0]], [[STRUCT_PAIR_F64]] [[DOTFCA_1_INSERT]], double noundef [[CONV]], [[UNION_UNION_F32_I32]] [[DOTFCA_0_INSERT]], i32 noundef [[V3]]) #[[ATTR2]] | ||
// CHECK-NEXT: tail call void (double, i32, ...) @sink_2(double noundef [[F1]], i32 noundef [[F0]], [[STRUCT_PAIR_F64]] [[DOTFCA_1_INSERT]], double noundef [[CONV]], [[UNION_UNION_F32_I32]] [[DOTFCA_0_INSERT]], i32 noundef [[V3]]) #[[ATTR2]] | ||
// CHECK-NEXT: ret void | ||
// | ||
void multiple_two(int f0, double f1, pair_f64 v0, float v1, union_f32_i32 v2, int v3) | ||
{ | ||
sink_0(v0, v1, v2, v3); | ||
sink_1(f0, v0, v1, v2, v3); | ||
sink_2(f1, f0, v0, v1, v2, v3); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also test some structs that are so big they wouldn't be passed directly? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Missing big tests? |
Oops, something went wrong.
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.
Wouldn't we still want to follow the isAggregateTypeForABI rules? Large structs should still go through byref?
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.
The bigger concern is using giant aggregate types is not great IR, and not all that well supported. a 65k element array will crash in SelectionDAG for example