-
Notifications
You must be signed in to change notification settings - Fork 14.7k
[HLSL] Implement HLSL Aggregate splatting #118992
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
Merged
Changes from 18 commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
e994824
splat cast wip
spall 24bea86
make clang format happy
spall 3575617
codegen test
spall 288b8da
Try to handle Cast in all the places it needs to be handled
spall 0650840
get code compiling after rebase
spall f924b13
Self review
spall 89ceeb7
move code back that broke tests
spall 7f5b3e4
fix tests
spall 844ba82
add cast to cases
spall 848315d
self review
spall cadd309
disallow splatting things with bitvectors, add tests to show casting …
spall 93c0450
fix tests + associated issues in code
spall 1d317f2
clang format
spall 41f54fe
rename cast from HLSLSplatCast to HLSLAggregateSplatCast
spall 7331af6
address pr comments
spall 5fb0b9f
In vector case do more heavy lifting in sema so codegen can reuse Vec…
spall fdc868e
make sure you can't cast intangible types
spall a56cfe9
rename file
spall e4a03e7
revert code I did not intend to modify
spall 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
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
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
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
87 changes: 87 additions & 0 deletions
87
clang/test/CodeGenHLSL/BasicFeatures/AggregateSplatCast.hlsl
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,87 @@ | ||
// RUN: %clang_cc1 -finclude-default-header -triple dxil-pc-shadermodel6.3-library -x hlsl -emit-llvm -disable-llvm-passes -o - %s | FileCheck %s | ||
|
||
// array splat | ||
// CHECK-LABEL: define void {{.*}}call4 | ||
// CHECK: [[B:%.*]] = alloca [2 x i32], align 4 | ||
// CHECK-NEXT: call void @llvm.memcpy.p0.p0.i32(ptr align 4 [[B]], ptr align 4 {{.*}}, i32 8, i1 false) | ||
// CHECK-NEXT: [[G1:%.*]] = getelementptr inbounds [2 x i32], ptr [[B]], i32 0, i32 0 | ||
// CHECK-NEXT: [[G2:%.*]] = getelementptr inbounds [2 x i32], ptr [[B]], i32 0, i32 1 | ||
// CHECK-NEXT: store i32 3, ptr [[G1]], align 4 | ||
// CHECK-NEXT: store i32 3, ptr [[G2]], align 4 | ||
export void call4() { | ||
int B[2] = {1,2}; | ||
B = (int[2])3; | ||
} | ||
|
||
// splat from vector of length 1 | ||
// CHECK-LABEL: define void {{.*}}call8 | ||
// CHECK: [[A:%.*]] = alloca <1 x i32>, align 4 | ||
// CHECK-NEXT: [[B:%.*]] = alloca [2 x i32], align 4 | ||
// CHECK-NEXT: store <1 x i32> splat (i32 1), ptr [[A]], align 4 | ||
// CHECK-NEXT: call void @llvm.memcpy.p0.p0.i32(ptr align 4 [[B]], ptr align 4 {{.*}}, i32 8, i1 false) | ||
// CHECK-NEXT: [[L:%.*]] = load <1 x i32>, ptr [[A]], align 4 | ||
// CHECK-NEXT: [[VL:%.*]] = extractelement <1 x i32> [[L]], i32 0 | ||
// CHECK-NEXT: [[G1:%.*]] = getelementptr inbounds [2 x i32], ptr [[B]], i32 0, i32 0 | ||
// CHECK-NEXT: [[G2:%.*]] = getelementptr inbounds [2 x i32], ptr [[B]], i32 0, i32 1 | ||
// CHECK-NEXT: store i32 [[VL]], ptr [[G1]], align 4 | ||
// CHECK-NEXT: store i32 [[VL]], ptr [[G2]], align 4 | ||
export void call8() { | ||
int1 A = {1}; | ||
int B[2] = {1,2}; | ||
B = (int[2])A; | ||
} | ||
|
||
// vector splat from vector of length 1 | ||
// CHECK-LABEL: define void {{.*}}call1 | ||
// CHECK: [[B:%.*]] = alloca <1 x float>, align 4 | ||
// CHECK-NEXT: [[A:%.*]] = alloca <4 x i32>, align 16 | ||
// CHECK-NEXT: store <1 x float> splat (float 1.000000e+00), ptr [[B]], align 4 | ||
// CHECK-NEXT: [[L:%.*]] = load <1 x float>, ptr [[B]], align 4 | ||
// CHECK-NEXT: [[VL:%.*]] = extractelement <1 x float> [[L]], i32 0 | ||
// CHECK-NEXT: [[C:%.*]] = fptosi float [[VL]] to i32 | ||
// CHECK-NEXT: [[SI:%.*]] = insertelement <4 x i32> poison, i32 [[C]], i64 0 | ||
// CHECK-NEXT: [[S:%.*]] = shufflevector <4 x i32> [[SI]], <4 x i32> poison, <4 x i32> zeroinitializer | ||
// CHECK-NEXT: store <4 x i32> [[S]], ptr [[A]], align 16 | ||
export void call1() { | ||
float1 B = {1.0}; | ||
int4 A = (int4)B; | ||
} | ||
|
||
struct S { | ||
int X; | ||
float Y; | ||
}; | ||
|
||
// struct splats | ||
// CHECK-LABEL: define void {{.*}}call3 | ||
// CHECK: [[A:%.*]] = alloca <1 x i32>, align 4 | ||
// CHECK: [[s:%.*]] = alloca %struct.S, align 4 | ||
// CHECK-NEXT: store <1 x i32> splat (i32 1), ptr [[A]], align 4 | ||
// CHECK-NEXT: [[L:%.*]] = load <1 x i32>, ptr [[A]], align 4 | ||
// CHECK-NEXT: [[VL:%.*]] = extractelement <1 x i32> [[L]], i32 0 | ||
// CHECK-NEXT: [[G1:%.*]] = getelementptr inbounds %struct.S, ptr [[s]], i32 0, i32 0 | ||
// CHECK-NEXT: [[G2:%.*]] = getelementptr inbounds %struct.S, ptr [[s]], i32 0, i32 1 | ||
// CHECK-NEXT: store i32 [[VL]], ptr [[G1]], align 4 | ||
// CHECK-NEXT: [[C:%.*]] = sitofp i32 [[VL]] to float | ||
// CHECK-NEXT: store float [[C]], ptr [[G2]], align 4 | ||
export void call3() { | ||
int1 A = {1}; | ||
S s = (S)A; | ||
} | ||
|
||
// struct splat from vector of length 1 | ||
// CHECK-LABEL: define void {{.*}}call5 | ||
// CHECK: [[A:%.*]] = alloca <1 x i32>, align 4 | ||
// CHECK-NEXT: [[s:%.*]] = alloca %struct.S, align 4 | ||
// CHECK-NEXT: store <1 x i32> splat (i32 1), ptr [[A]], align 4 | ||
// CHECK-NEXT: [[L:%.*]] = load <1 x i32>, ptr [[A]], align 4 | ||
// CHECK-NEXT: [[VL:%.*]] = extractelement <1 x i32> [[L]], i32 0 | ||
// CHECK-NEXT: [[G1:%.*]] = getelementptr inbounds %struct.S, ptr [[s]], i32 0, i32 0 | ||
// CHECK-NEXT: [[G2:%.*]] = getelementptr inbounds %struct.S, ptr [[s]], i32 0, i32 1 | ||
// CHECK-NEXT: store i32 [[VL]], ptr [[G1]], align 4 | ||
// CHECK-NEXT: [[C:%.*]] = sitofp i32 [[VL]] to float | ||
// CHECK-NEXT: store float [[C]], ptr [[G2]], align 4 | ||
export void call5() { | ||
int1 A = {1}; | ||
S s = (S)A; | ||
} |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.