diff options
author | Sarah Spall <sarahspall@microsoft.com> | 2025-04-02 12:27:01 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-04-02 12:27:01 -0700 |
commit | 60efed3f2025cc9612570487dba5cb299ee28167 (patch) | |
tree | c675e145710867bf081103af37c8e8185d288d53 | |
parent | 843ef77dc22afd1923b891acd4c46c8f8c8c93ae (diff) | |
download | llvm-60efed3f2025cc9612570487dba5cb299ee28167.zip llvm-60efed3f2025cc9612570487dba5cb299ee28167.tar.gz llvm-60efed3f2025cc9612570487dba5cb299ee28167.tar.bz2 |
[HLSL] Update __builtin_hlsl_dot builtin Sema Checking to fix error when passed an array literal 1u.xxxx (#133941)
update dot builtin sema checking and codegen
new test
fix tests
Closes #133659
-rw-r--r-- | clang/lib/CodeGen/CGHLSLBuiltins.cpp | 16 | ||||
-rw-r--r-- | clang/lib/Sema/SemaHLSL.cpp | 3 | ||||
-rw-r--r-- | clang/test/CodeGenHLSL/builtins/dot.hlsl | 8 |
3 files changed, 14 insertions, 13 deletions
diff --git a/clang/lib/CodeGen/CGHLSLBuiltins.cpp b/clang/lib/CodeGen/CGHLSLBuiltins.cpp index 136ea47..99c6280 100644 --- a/clang/lib/CodeGen/CGHLSLBuiltins.cpp +++ b/clang/lib/CodeGen/CGHLSLBuiltins.cpp @@ -368,20 +368,12 @@ Value *CodeGenFunction::EmitHLSLBuiltinExpr(unsigned BuiltinID, "Scalar dot product is only supported on ints and floats."); } // For vectors, validate types and emit the appropriate intrinsic - - // A VectorSplat should have happened - assert(T0->isVectorTy() && T1->isVectorTy() && - "Dot product of vector and scalar is not supported."); + assert(CGM.getContext().hasSameUnqualifiedType(E->getArg(0)->getType(), + E->getArg(1)->getType()) && + "Dot product operands must have the same type."); auto *VecTy0 = E->getArg(0)->getType()->castAs<VectorType>(); - [[maybe_unused]] auto *VecTy1 = - E->getArg(1)->getType()->castAs<VectorType>(); - - assert(VecTy0->getElementType() == VecTy1->getElementType() && - "Dot product of vectors need the same element types."); - - assert(VecTy0->getNumElements() == VecTy1->getNumElements() && - "Dot product requires vectors to be of the same size."); + assert(VecTy0 && "Dot product argument must be a vector."); return Builder.CreateIntrinsic( /*ReturnType=*/T0->getScalarType(), diff --git a/clang/lib/Sema/SemaHLSL.cpp b/clang/lib/Sema/SemaHLSL.cpp index 07d03e2..fe600386e 100644 --- a/clang/lib/Sema/SemaHLSL.cpp +++ b/clang/lib/Sema/SemaHLSL.cpp @@ -2015,7 +2015,8 @@ static bool CheckVectorElementCallArgs(Sema *S, CallExpr *TheCall) { } if (VecTyA && VecTyB) { bool retValue = false; - if (VecTyA->getElementType() != VecTyB->getElementType()) { + if (!S->Context.hasSameUnqualifiedType(VecTyA->getElementType(), + VecTyB->getElementType())) { // Note: type promotion is intended to be handeled via the intrinsics // and not the builtin itself. S->Diag(TheCall->getBeginLoc(), diff --git a/clang/test/CodeGenHLSL/builtins/dot.hlsl b/clang/test/CodeGenHLSL/builtins/dot.hlsl index 7064066..c1fdb07 100644 --- a/clang/test/CodeGenHLSL/builtins/dot.hlsl +++ b/clang/test/CodeGenHLSL/builtins/dot.hlsl @@ -158,3 +158,11 @@ float test_dot_float4(float4 p0, float4 p1) { return dot(p0, p1); } // CHECK: %hlsl.dot = fmul reassoc nnan ninf nsz arcp afn double // CHECK: ret double %hlsl.dot double test_dot_double(double p0, double p1) { return dot(p0, p1); } + +// CHECK-LABEL: test_dot_literal +// CHECK: [[X:%.*]] = shufflevector <1 x i32> {{.*}}, <1 x i32> poison, <4 x i32> zeroinitializer +// CHECK-NEXT: %hlsl.dot = call i32 @llvm.[[ICF]].udot.v4i32(<4 x i32> {{.*}}, <4 x i32> [[X]]) +// CHECK-NEXT: [[S1:%.*]] = insertelement <4 x i32> poison, i32 %hlsl.dot, i64 0 +// CHECK-NEXT: [[S2:%.*]] = shufflevector <4 x i32> [[S1]], <4 x i32> poison, <4 x i32> zeroinitializer +// CHECK-NEXT: ret <4 x i32> [[S2]] +uint4 test_dot_literal( uint4 p0) { return dot(p0, 1u.xxxx); } |