@@ -2977,26 +2977,27 @@ Value *ScalarExprEmitter::VisitCastExpr(CastExpr *CE) {
29772977 return Builder.CreateExtractElement (Vec, Zero, " cast.vtrunc" );
29782978 }
29792979 case CK_HLSLMatrixTruncation: {
2980- assert ((DestTy->isConstantMatrixType () || DestTy->isBuiltinType ()) &&
2980+ assert ((DestTy->isMatrixType () || DestTy->isBuiltinType ()) &&
29812981 " Destination type must be a matrix or builtin type." );
29822982 Value *Mat = Visit (E);
2983- unsigned NumCols = 1 ;
2984- unsigned NumRows = 1 ;
2985- SmallVector<int > Mask;
29862983 if (auto *MatTy = DestTy->getAs <ConstantMatrixType>()) {
2987- NumCols = MatTy->getNumColumns ();
2988- NumRows = MatTy->getNumRows ();
2989- }
2990- unsigned ColOffset = NumCols;
2991- if (auto *SrcMatTy = E->getType ()->getAs <ConstantMatrixType>())
2992- ColOffset = SrcMatTy->getNumColumns ();
2993- for (unsigned R = 0 ; R < NumRows; R++) {
2994- for (unsigned C = 0 ; C < NumCols; C++) {
2995- unsigned I = R * ColOffset + C;
2996- Mask.push_back (I);
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+ }
29972995 }
2996+
2997+ return Builder.CreateShuffleVector (Mat, Mask, " trunc" );
29982998 }
2999- return Builder.CreateShuffleVector (Mat, Mask, " trunc" );
2999+ llvm::Value *Zero = llvm::Constant::getNullValue (CGF.SizeTy );
3000+ return Builder.CreateExtractElement (Mat, Zero, " cast.mtrunc" );
30003001 }
30013002 case CK_HLSLElementwiseCast: {
30023003 RValue RV = CGF.EmitAnyExpr (E);
0 commit comments