Skip to content

Commit e6b4ab6

Browse files
committed
address pr comments
1 parent 4fb0091 commit e6b4ab6

File tree

4 files changed

+26
-29
lines changed

4 files changed

+26
-29
lines changed

clang/lib/CodeGen/CGExprScalar.cpp

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2429,7 +2429,7 @@ static Value *EmitHLSLElementwiseCast(CodeGenFunction &CGF, LValue SrcVal,
24292429

24302430
llvm::Value *V =
24312431
CGF.Builder.CreateLoad(CGF.CreateIRTemp(DestTy, "flatcast.tmp"));
2432-
// write to V.
2432+
// V is an allocated temporary to build the truncated matrix into.
24332433
for (unsigned I = 0, E = MatTy->getNumElementsFlattened(); I < E; I++) {
24342434
unsigned ColMajorIndex =
24352435
(I % MatTy->getNumRows()) * MatTy->getNumColumns() +
@@ -2977,27 +2977,23 @@ Value *ScalarExprEmitter::VisitCastExpr(CastExpr *CE) {
29772977
return Builder.CreateExtractElement(Vec, Zero, "cast.vtrunc");
29782978
}
29792979
case CK_HLSLMatrixTruncation: {
2980-
assert((DestTy->isMatrixType() || DestTy->isBuiltinType()) &&
2980+
assert((DestTy->isConstantMatrixType() || DestTy->isBuiltinType()) &&
29812981
"Destination type must be a matrix or builtin type.");
29822982
Value *Mat = Visit(E);
2983-
if (auto *MatTy = DestTy->getAs<ConstantMatrixType>()) {
2984-
SmallVector<int> Mask;
2985-
unsigned NumCols = MatTy->getNumColumns();
2986-
unsigned NumRows = MatTy->getNumRows();
2987-
unsigned ColOffset = NumCols;
2988-
if (auto *SrcMatTy = E->getType()->getAs<ConstantMatrixType>())
2989-
ColOffset = SrcMatTy->getNumColumns();
2990-
for (unsigned R = 0; R < NumRows; R++) {
2991-
for (unsigned C = 0; C < NumCols; C++) {
2992-
unsigned I = R * ColOffset + C;
2993-
Mask.push_back(I);
2994-
}
2983+
auto *MatTy = DestTy->getAs<ConstantMatrixType>();
2984+
SmallVector<int> Mask;
2985+
unsigned NumCols = MatTy->getNumColumns();
2986+
unsigned NumRows = MatTy->getNumRows();
2987+
unsigned ColOffset = NumCols;
2988+
if (auto *SrcMatTy = E->getType()->getAs<ConstantMatrixType>())
2989+
ColOffset = SrcMatTy->getNumColumns();
2990+
for (unsigned R = 0; R < NumRows; R++) {
2991+
for (unsigned C = 0; C < NumCols; C++) {
2992+
unsigned I = R * ColOffset + C;
2993+
Mask.push_back(I);
29952994
}
2996-
2997-
return Builder.CreateShuffleVector(Mat, Mask, "trunc");
29982995
}
2999-
llvm::Value *Zero = llvm::Constant::getNullValue(CGF.SizeTy);
3000-
return Builder.CreateExtractElement(Mat, Zero, "cast.mtrunc");
2996+
return Builder.CreateShuffleVector(Mat, Mask, "trunc");
30012997
}
30022998
case CK_HLSLElementwiseCast: {
30032999
RValue RV = CGF.EmitAnyExpr(E);

clang/lib/Sema/SemaChecking.cpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12571,9 +12571,10 @@ void Sema::CheckImplicitConversion(Expr *E, QualType T, SourceLocation CC,
1257112571
if (SourceMgr.isInSystemMacro(CC))
1257212572
return;
1257312573
return DiagnoseImpCast(*this, E, T, CC, diag::warn_impcast_vector_scalar);
12574-
} else if (getLangOpts().HLSL &&
12575-
Target->castAs<VectorType>()->getNumElements() <
12576-
Source->castAs<VectorType>()->getNumElements()) {
12574+
}
12575+
if (getLangOpts().HLSL &&
12576+
Target->castAs<VectorType>()->getNumElements() <
12577+
Source->castAs<VectorType>()->getNumElements()) {
1257712578
// Diagnose vector truncation but don't return. We may also want to
1257812579
// diagnose an element conversion.
1257912580
DiagnoseImpCast(*this, E, T, CC,
@@ -12593,12 +12594,12 @@ void Sema::CheckImplicitConversion(Expr *E, QualType T, SourceLocation CC,
1259312594
Target = VecTy->getElementType().getTypePtr();
1259412595

1259512596
if (isa<ConstantMatrixType>(Source)) {
12596-
if (!isa<ConstantMatrixType>(Target)) {
12597+
if (Target->isScalarType())
1259712598
return DiagnoseImpCast(*this, E, T, CC, diag::warn_impcast_matrix_scalar);
12598-
} else if (getLangOpts().HLSL &&
12599-
Target->castAs<ConstantMatrixType>()->getNumElementsFlattened() <
12600-
Source->castAs<ConstantMatrixType>()
12601-
->getNumElementsFlattened()) {
12599+
12600+
if (getLangOpts().HLSL &&
12601+
Target->castAs<ConstantMatrixType>()->getNumElementsFlattened() <
12602+
Source->castAs<ConstantMatrixType>()->getNumElementsFlattened()) {
1260212603
// Diagnose Matrix truncation but don't return. We may also want to
1260312604
// diagnose an element conversion.
1260412605
DiagnoseImpCast(*this, E, T, CC,

clang/test/SemaHLSL/MatrixElementOverloadResolution.hlsl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-library -fnative-half-type -finclude-default-header -Wconversion -verify -o - %s -DERROR=1
2-
// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-library -fnative-half-type -finclude-default-header -Wno-conversion -ast-dump %s | FileCheck %s
1+
// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-library -fnative-half-type -finclude-default-header -verify -o - %s -DERROR=1
2+
// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.3-library -fnative-half-type -finclude-default-header -ast-dump %s | FileCheck %s
33

44
// This test verifies floating point type implicit conversion ranks for overload
55
// resolution. In HLSL the built-in type ranks are half < float < double. This

clang/test/SemaHLSL/Types/BuiltinMatrix/MatrixImplicitTruncCastWarnings.hlsl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.6-library -finclude-default-header -Wmatrix-conversion -verify %s
1+
// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.6-library -finclude-default-header -verify %s
22

33
export int3x4 trunc_cast(int4x4 i44) {
44
int3x4 i34 = i44;

0 commit comments

Comments
 (0)