[clang] [HLSL] Implement HLSL splatting (PR #118992)
Sarah Spall via cfe-commits
cfe-commits at lists.llvm.org
Thu Feb 13 09:58:56 PST 2025
================
@@ -2804,6 +2804,42 @@ bool SemaHLSL::ContainsBitField(QualType BaseTy) {
return false;
}
+// Can perform an HLSL splat cast if the Dest is an aggregate and the
+// Src is a scalar or a vector of length 1
+// Or if Dest is a vector and Src is a vector of length 1
+bool SemaHLSL::CanPerformSplatCast(Expr *Src, QualType DestTy) {
+
+ QualType SrcTy = Src->getType();
+ // Not a valid HLSL Splat cast if Dest is a scalar or if this is going to
+ // be a vector splat from a scalar.
+ if ((SrcTy->isScalarType() && DestTy->isVectorType()) ||
+ DestTy->isScalarType())
+ return false;
+
+ const VectorType *SrcVecTy = SrcTy->getAs<VectorType>();
+
+ // Src isn't a scalar or a vector of length 1
+ if (!SrcTy->isScalarType() && !(SrcVecTy && SrcVecTy->getNumElements() == 1))
+ return false;
+
+ if (SrcVecTy)
----------------
spall wrote:
I think the only thing I could do is have a nested if statement, but I don't think that would improve the situation.
https://github.com/llvm/llvm-project/pull/118992
More information about the cfe-commits
mailing list