[clang] [HLSL][Matrix] Add support for ICK_HLSL_Matrix_Splat to add splat cast of scalars (PR #170885)

Farzon Lotfi via cfe-commits cfe-commits at lists.llvm.org
Fri Dec 5 12:32:15 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.
----------------
farzonl wrote:

I have a branch that implements booleans  in `clang/lib/Headers/hlsl/hlsl_basic_types.h`. Maybe I should try to merge that in first so I can  put the tests for this in this pr.

https://github.com/llvm/llvm-project/pull/170885


More information about the cfe-commits mailing list