Skip to content

Commit 905bc23

Browse files
committed
move test from sema to codegen. fix bug in codegen which imitates bug in sema checking
1 parent 892621d commit 905bc23

File tree

3 files changed

+13
-18
lines changed

3 files changed

+13
-18
lines changed

clang/lib/CodeGen/CGHLSLBuiltins.cpp

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -368,21 +368,13 @@ 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.");
385-
376+
assert(VecTy0 && "Dot product argument must be a vector.");
377+
386378
return Builder.CreateIntrinsic(
387379
/*ReturnType=*/T0->getScalarType(),
388380
getDotProductIntrinsic(CGM.getHLSLRuntime(), VecTy0->getElementType()),

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); }

clang/test/SemaHLSL/BuiltIns/dot-errors.hlsl

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,3 @@ float builtin_dot_int_to_float_promotion ( float p0, int p1 ) {
127127
return __builtin_hlsl_dot (p0, p1 );
128128
// expected-error@-1 {{all arguments to '__builtin_hlsl_dot' must have the same type}}
129129
}
130-
131-
// should not error
132-
uint builtin_dot_literal_shouldnt_error( uint4 p0) {
133-
return dot(p0, 1u.xxxx);
134-
}

0 commit comments

Comments
 (0)