-
Notifications
You must be signed in to change notification settings - Fork 15.1k
[HLSL][Matrix] Change MatrixSubscriptExpr flattened index to row major #165666
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
Closed
Closed
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
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,35 @@ | ||
| // RUN: %clang_cc1 -fenable-matrix -triple x86_64-apple-darwin %s -emit-llvm -disable-llvm-passes -o - | FileCheck %s | ||
|
|
||
| typedef float fx2x3_t __attribute__((matrix_type(2, 3))); | ||
| float Out[6]; | ||
|
|
||
| void one_index_test(int index, fx2x3_t M) { | ||
| // CHECK-LABEL: one_index_test | ||
| // CHECK: %row = alloca i32, align 4 | ||
| // CHECK: %col = alloca i32, align 4 | ||
| // CHECK: [[row_load:%.*]] = load i32, ptr %row, align 4 | ||
| // CHECK-NEXT: [[row_load_zext:%.*]] = zext i32 [[row_load]] to i64 | ||
| // CHECK-NEXT: [[col_load:%.*]] = load i32, ptr %col, align 4 | ||
| // CHECK-NEXT: [[col_load_zext:%.*]] = zext i32 [[col_load]] to i64 | ||
| // CHECK-NEXT: [[col_offset:%.*]] = mul i64 [[col_load_zext]], 2 | ||
| // CHECK-NEXT: [[col_major_index:%.*]] = add i64 [[col_offset]], [[row_load_zext]] | ||
| // CHECK-NEXT: [[matrix_as_vec:%.*]] = load <6 x float>, ptr %M.addr, align 4 | ||
| // CHECK-NEXT: %matrixext = extractelement <6 x float> [[matrix_as_vec]], i64 [[col_major_index]] | ||
| const unsigned int COLS = 3; | ||
| unsigned int row = index / COLS; | ||
| unsigned int col = index % COLS; | ||
| Out[index] = M[row][col]; | ||
| } | ||
|
|
||
| float two_index_test(int row, int col, fx2x3_t M) { | ||
| // CHECK-LABEL: two_index_test | ||
| // CHECK: [[row_load:%.*]] = load i32, ptr %row.addr, align 4 | ||
| // CHECK-NEXT: [[row_load_sext:%.*]] = sext i32 [[row_load]] to i64 | ||
| // CHECK-NEXT: [[col_load:%.*]] = load i32, ptr %col.addr, align 4 | ||
| // CHECK-NEXT: [[col_load_sext:%.*]] = sext i32 [[col_load]] to i64 | ||
| // CHECK-NEXT: [[col_offset:%.*]] = mul i64 [[col_load_sext]], 2 | ||
| // CHECK-NEXT: [[col_major_index:%.*]] = add i64 [[col_offset]], [[row_load_sext]] | ||
| // CHECK-NEXT: [[matrix_as_vec:%.*]] = load <6 x float>, ptr %M.addr, align 4 | ||
| // CHECK-NEXT: %matrixext = extractelement <6 x float> [[matrix_as_vec]], i64 [[col_major_index]] | ||
| return M[row][col]; | ||
| } |
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,35 @@ | ||
| // RUN: %clang_cc1 -fenable-matrix -triple x86_64-apple-darwin %s -emit-llvm -disable-llvm-passes -o - -std=c++11 | FileCheck %s | ||
|
|
||
| typedef float fx2x3_t __attribute__((matrix_type(2, 3))); | ||
| float Out[6]; | ||
|
|
||
| void one_index_test(int index, fx2x3_t M) { | ||
| // CHECK-LABEL: one_index_test | ||
| // CHECK: %row = alloca i32, align 4 | ||
| // CHECK: %col = alloca i32, align 4 | ||
| // CHECK: [[row_load:%.*]] = load i32, ptr %row, align 4 | ||
| // CHECK-NEXT: [[row_load_zext:%.*]] = zext i32 [[row_load]] to i64 | ||
| // CHECK-NEXT: [[col_load:%.*]] = load i32, ptr %col, align 4 | ||
| // CHECK-NEXT: [[col_load_zext:%.*]] = zext i32 [[col_load]] to i64 | ||
| // CHECK-NEXT: [[col_offset:%.*]] = mul i64 [[col_load_zext]], 2 | ||
| // CHECK-NEXT: [[col_major_index:%.*]] = add i64 [[col_offset]], [[row_load_zext]] | ||
| // CHECK-NEXT: [[matrix_as_vec:%.*]] = load <6 x float>, ptr %M.addr, align 4 | ||
| // CHECK-NEXT: %matrixext = extractelement <6 x float> [[matrix_as_vec]], i64 [[col_major_index]] | ||
| const unsigned int COLS = 3; | ||
| unsigned int row = index / COLS; | ||
| unsigned int col = index % COLS; | ||
| Out[index] = M[row][col]; | ||
| } | ||
|
|
||
| float two_index_test(int row, int col, fx2x3_t M) { | ||
| // CHECK-LABEL: two_index_test | ||
| // CHECK: [[row_load:%.*]] = load i32, ptr %row.addr, align 4 | ||
| // CHECK-NEXT: [[row_load_sext:%.*]] = sext i32 [[row_load]] to i64 | ||
| // CHECK-NEXT: [[col_load:%.*]] = load i32, ptr %col.addr, align 4 | ||
| // CHECK-NEXT: [[col_load_sext:%.*]] = sext i32 [[col_load]] to i64 | ||
| // CHECK-NEXT: [[col_offset:%.*]] = mul i64 [[col_load_sext]], 2 | ||
| // CHECK-NEXT: [[col_major_index:%.*]] = add i64 [[col_offset]], [[row_load_sext]] | ||
| // CHECK-NEXT: [[matrix_as_vec:%.*]] = load <6 x float>, ptr %M.addr, align 4 | ||
| // CHECK-NEXT: %matrixext = extractelement <6 x float> [[matrix_as_vec]], i64 [[col_major_index]] | ||
| return M[row][col]; | ||
| } |
30 changes: 30 additions & 0 deletions
30
clang/test/CodeGenHLSL/BasicFeatures/matrix-type-indexing.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,30 @@ | ||
| // RUN: %clang_cc1 -finclude-default-header -x hlsl -triple dxil-pc-shadermodel6.3-library %s -fnative-half-type -emit-llvm -disable-llvm-passes -o - | FileCheck %s | ||
|
|
||
| // NOTE: This test is only to confirm we can do codgen with the matrix alias. | ||
|
|
||
| RWBuffer<int> Out : register(u1); | ||
|
|
||
| void one_index_test(int index, half2x3 M) { | ||
| // CHECK-LABEL: one_index_test | ||
| // CHECK: %row = alloca i32, align 4 | ||
| // CHECK: %col = alloca i32, align 4 | ||
| // CHECK: [[row_load:%.*]] = load i32, ptr %row, align 4 | ||
| // CHECK-NEXT: [[col_load:%.*]] = load i32, ptr %col, align 4 | ||
| // CHECK-NEXT: [[row_offset:%.*]] = mul i32 [[row_load]], 3 | ||
| // CHECK-NEXT: [[row_major_index:%.*]] = add i32 [[row_offset]], [[col_load]] | ||
| // CHECK-NEXT: [[matrix_as_vec:%.*]] = load <6 x half>, ptr %M.addr, align 2 | ||
| // CHECK-NEXT: %matrixext = extractelement <6 x half> [[matrix_as_vec]], i32 [[row_major_index]] | ||
| const uint COLS = 3; | ||
| uint row = index / COLS; | ||
| uint col = index % COLS; | ||
| Out[index] = M[row][col]; | ||
| } | ||
|
|
||
| half two_index_test(int row, int col, half2x3 M) { | ||
| // CHECK-LABEL: two_index_test | ||
| // CHECK: [[row_offset:%.*]] = mul i32 [[row_load:%.*]], 3 | ||
| // CHECK-NEXT: [[row_major_index:%.*]] = add i32 [[row_offset]], [[col_load:%.*]] | ||
| // CHECK-NEXT: [[matrix_as_vec:%.*]] = load <6 x half>, ptr %M.addr, align 2 | ||
| // CHECK-NEXT: %matrixext = extractelement <6 x half> [[matrix_as_vec]], i32 [[row_major_index]] | ||
| return M[row][col]; | ||
| } |
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
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.
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.