[clang] [HLSL][Matrix] Add support for ICK_HLSL_Matrix_Splat to add splat cast of scalars (PR #170885)
Tex Riddell via cfe-commits
cfe-commits at lists.llvm.org
Fri Dec 5 12:19:29 PST 2025
================
@@ -7806,6 +7806,39 @@ ExprResult Sema::prepareVectorSplat(QualType VectorTy, Expr *SplattedExpr) {
return ImpCastExprToType(SplattedExpr, DestElemTy, CK);
}
+ExprResult Sema::prepareMatrixSplat(QualType MatrixTy, Expr *SplattedExpr) {
+ QualType DestElemTy = MatrixTy->castAs<MatrixType>()->getElementType();
+
+ if (DestElemTy == SplattedExpr->getType())
+ return SplattedExpr;
+
+ assert(DestElemTy->isFloatingType() ||
+ DestElemTy->isIntegralOrEnumerationType());
+
+ CastKind CK;
+ if (SplattedExpr->getType()->isBooleanType()) {
+ // As with vectors, we want `true` to become -1 when splatting, and we
+ // need a two-step cast if the destination element type is floating.
----------------
tex3d wrote:
Do we have testing for this path?
HLSL doesn't define the result of a cast of a true `bool` to `int` to be `-1`, regardless of whether it's scalar, vector, or matrix.
Is this an OpenCL-specific detail? In `CheckVectorCast` it says:
>// OpenCL requires that we convert `true` boolean expressions to -1, but
>// only when splatting vectors.
Though this isn't the code which defines the behavior of the cast itself, so those details in this comment do seem misplaced.
https://github.com/llvm/llvm-project/pull/170885
More information about the cfe-commits
mailing list