================
@@ -7899,14 +7899,26 @@ ExprResult Sema::prepareMatrixSplat(QualType MatrixTy,
Expr *SplattedExpr) {
assert(DestElemTy->isFloatingType() ||
DestElemTy->isIntegralOrEnumerationType());
- // TODO: Add support for boolean matrix once exposed
- // https://github.com/llvm/llvm-project/issues/170920
- ExprResult CastExprRes = SplattedExpr;
- CastKind CK = PrepareScalarCast(CastExprRes, DestElemTy);
- if (CastExprRes.isInvalid())
- return ExprError();
- SplattedExpr = CastExprRes.get();
-
+ 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.
+ if (DestElemTy->isFloatingType()) {
+ // Cast boolean to signed integral, then to floating.
+ ExprResult CastExprRes = ImpCastExprToType(SplattedExpr, Context.IntTy,
+ CK_BooleanToSignedIntegral);
+ SplattedExpr = CastExprRes.get();
+ CK = CK_IntegralToFloating;
+ } else {
+ CK = CK_BooleanToSignedIntegral;
+ }
----------------
Icohedron wrote:
This code is a re-introduction of the code from @farzonl
https://github.com/llvm/llvm-project/pull/170885/changes/e80fe5c7cb993aa6e380abec94302477d56ac03a
Which itself is analogous to the existing code for prepareVectorSplat
https://github.com/llvm/llvm-project/blob/d52c7da0863f0c777382de37b22960f824ac7f48/clang/lib/Sema/SemaExpr.cpp#L7870-L7882
However, in both vector and matrix cases this code never seems to get executed
in HLSL. Or at least, I can not find any HLSL code that exercises the logic for
converting `true` to `-1` when splatting booleans to vectors and matrices.
As such, I think this code is actually dead and should really not be needed as
part of this PR. Boolean matrix splats work just fine in HLSL without this code.
https://github.com/llvm/llvm-project/pull/175809
_______________________________________________
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits