Skip to content

Commit 97bd5ee

Browse files
committed
address pr comments
1 parent 82e2bc0 commit 97bd5ee

File tree

4 files changed

+3
-10
lines changed

4 files changed

+3
-10
lines changed

clang/docs/MatrixTypes.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,8 @@ Otherwise, the result is a glvalue with type ``cv T`` and with the same value
106106
category as ``E1`` which refers to the element at the given row and column in
107107
the matrix.
108108

109-
Programs containing a single subscript expression into a matrix are ill-formed.
109+
A single subscript expression into a matrix is legal in HLSL and yields the
110+
column-sized vector for the selected row, but is ill-formed in C and C++.
110111

111112
**Note**: We considered providing an expression of the form
112113
``postfix-expression [expression]`` to access columns of a matrix. We think

clang/lib/CodeGen/CGExpr.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2729,18 +2729,13 @@ void CodeGenFunction::EmitStoreThroughLValue(RValue Src, LValue Dst,
27292729

27302730
llvm::Value *Row = Dst.getMatrixRowIdx();
27312731
llvm::Value *RowVal = Src.getScalarVal(); // <NumCols x T>
2732-
27332732
llvm::MatrixBuilder MB(Builder);
27342733

27352734
for (unsigned Col = 0; Col < NumCols; ++Col) {
27362735
llvm::Value *ColIdx = llvm::ConstantInt::get(Row->getType(), Col);
2737-
27382736
llvm::Value *EltIndex = MB.CreateIndex(Row, ColIdx, NumRows);
2739-
27402737
llvm::Value *Lane = llvm::ConstantInt::get(Builder.getInt32Ty(), Col);
2741-
27422738
llvm::Value *NewElt = Builder.CreateExtractElement(RowVal, Lane);
2743-
27442739
MatrixVec = Builder.CreateInsertElement(MatrixVec, NewElt, EltIndex);
27452740
}
27462741

@@ -4968,7 +4963,6 @@ LValue CodeGenFunction::EmitMatrixSingleSubscriptExpr(
49684963
llvm::Value *RowIdx = EmitMatrixIndexExpr(E->getRowIdx());
49694964

49704965
if (auto *RowConst = llvm::dyn_cast<llvm::ConstantInt>(RowIdx)) {
4971-
49724966
// Extract matrix shape from the AST type
49734967
const auto *MatTy = E->getBase()->getType()->castAs<ConstantMatrixType>();
49744968
unsigned NumCols = MatTy->getNumColumns();

clang/lib/CodeGen/CGExprScalar.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2120,7 +2120,6 @@ Value *ScalarExprEmitter::VisitMatrixSingleSubscriptExpr(
21202120

21212121
// Row index
21222122
Value *RowIdx = CGF.EmitMatrixIndexExpr(E->getRowIdx());
2123-
21242123
llvm::MatrixBuilder MB(Builder);
21252124

21262125
// The row index must be in [0, NumRows)

clang/lib/Sema/SemaExpr.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5159,10 +5159,9 @@ ExprResult Sema::CreateBuiltinMatrixSubscriptExpr(Expr *Base, Expr *RowIdx,
51595159
return RowR;
51605160
RowIdx = RowR.get();
51615161

5162-
if (!ColumnIdx) {
5162+
if (!ColumnIdx)
51635163
return new (Context) MatrixSubscriptExpr(
51645164
Base, RowIdx, ColumnIdx, Context.IncompleteMatrixIdxTy, RBLoc);
5165-
}
51665165

51675166
// Build an unanalyzed expression if any of the operands is type-dependent.
51685167
if (Base->isTypeDependent() || RowIdx->isTypeDependent() ||

0 commit comments

Comments
 (0)