Skip to content

Commit 60efed3

Browse files
authored
[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
1 parent 843ef77 commit 60efed3

File tree

3 files changed

+14
-13
lines changed

3 files changed

+14
-13
lines changed

clang/lib/CodeGen/CGHLSLBuiltins.cpp

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -368,20 +368,12 @@ Value *CodeGenFunction::EmitHLSLBuiltinExpr(unsigned BuiltinID,
368368
"Scalar dot product is only supported on ints and floats.");
369369
}
370370
// For vectors, validate types and emit the appropriate intrinsic
371-
372-
// A VectorSplat should have happened
373-
assert(T0->isVectorTy() && T1->isVectorTy() &&
374-
"Dot product of vector and scalar is not supported.");
371+
assert(CGM.getContext().hasSameUnqualifiedType(E->getArg(0)->getType(),
372+
E->getArg(1)->getType()) &&
373+
"Dot product operands must have the same type.");
375374

376375
auto *VecTy0 = E->getArg(0)->getType()->castAs<VectorType>();
377-
[[maybe_unused]] auto *VecTy1 =
378-
E->getArg(1)->getType()->castAs<VectorType>();
379-
380-
assert(VecTy0->getElementType() == VecTy1->getElementType() &&
381-
"Dot product of vectors need the same element types.");
382-
383-
assert(VecTy0->getNumElements() == VecTy1->getNumElements() &&
384-
"Dot product requires vectors to be of the same size.");
376+
assert(VecTy0 && "Dot product argument must be a vector.");
385377

386378
return Builder.CreateIntrinsic(
387379
/*ReturnType=*/T0->getScalarType(),

clang/lib/Sema/SemaHLSL.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2015,7 +2015,8 @@ static bool CheckVectorElementCallArgs(Sema *S, CallExpr *TheCall) {
20152015
}
20162016
if (VecTyA && VecTyB) {
20172017
bool retValue = false;
2018-
if (VecTyA->getElementType() != VecTyB->getElementType()) {
2018+
if (!S->Context.hasSameUnqualifiedType(VecTyA->getElementType(),
2019+
VecTyB->getElementType())) {
20192020
// Note: type promotion is intended to be handeled via the intrinsics
20202021
// and not the builtin itself.
20212022
S->Diag(TheCall->getBeginLoc(),

clang/test/CodeGenHLSL/builtins/dot.hlsl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,3 +158,11 @@ float test_dot_float4(float4 p0, float4 p1) { return dot(p0, p1); }
158158
// CHECK: %hlsl.dot = fmul reassoc nnan ninf nsz arcp afn double
159159
// CHECK: ret double %hlsl.dot
160160
double test_dot_double(double p0, double p1) { return dot(p0, p1); }
161+
162+
// CHECK-LABEL: test_dot_literal
163+
// CHECK: [[X:%.*]] = shufflevector <1 x i32> {{.*}}, <1 x i32> poison, <4 x i32> zeroinitializer
164+
// CHECK-NEXT: %hlsl.dot = call i32 @llvm.[[ICF]].udot.v4i32(<4 x i32> {{.*}}, <4 x i32> [[X]])
165+
// CHECK-NEXT: [[S1:%.*]] = insertelement <4 x i32> poison, i32 %hlsl.dot, i64 0
166+
// CHECK-NEXT: [[S2:%.*]] = shufflevector <4 x i32> [[S1]], <4 x i32> poison, <4 x i32> zeroinitializer
167+
// CHECK-NEXT: ret <4 x i32> [[S2]]
168+
uint4 test_dot_literal( uint4 p0) { return dot(p0, 1u.xxxx); }

0 commit comments

Comments
 (0)