Skip to content

Commit 73f26c9

Browse files
committed
address pull request comments and make clang format happy
1 parent ebb4078 commit 73f26c9

File tree

9 files changed

+152
-25
lines changed

9 files changed

+152
-25
lines changed

clang/docs/ReleaseNotes.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ C++ Language Changes
114114

115115
- Accept C++26 user-defined ``static_assert`` messages in C++11 as an extension.
116116

117+
- Add ``__builtin_elementwise_popcount`` builtin for integer types only.
117118

118119
C++2c Feature Support
119120
^^^^^^^^^^^^^^^^^^^^^

clang/lib/CodeGen/CGBuiltin.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3836,7 +3836,7 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
38363836
*this, E, llvm::Intrinsic::floor, "elt.floor"));
38373837
case Builtin::BI__builtin_elementwise_popcount:
38383838
return RValue::get(emitBuiltinWithOneOverloadedType<1>(
3839-
*this, E, llvm::Intrinsic::ctpop, "elt.ctpop"));
3839+
*this, E, llvm::Intrinsic::ctpop, "elt.ctpop"));
38403840
case Builtin::BI__builtin_elementwise_roundeven:
38413841
return RValue::get(emitBuiltinWithOneOverloadedType<1>(
38423842
*this, E, llvm::Intrinsic::roundeven, "elt.roundeven"));

clang/lib/Sema/SemaHLSL.cpp

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1601,14 +1601,6 @@ bool CheckUnsignedIntRepresentation(Sema *S, CallExpr *TheCall) {
16011601
checkAllUnsignedTypes);
16021602
}
16031603

1604-
bool CheckIntRepresentation(Sema *S, CallExpr *TheCall) {
1605-
auto checkAllIntTypes = [](clang::QualType PassedType) -> bool {
1606-
return !PassedType->hasIntegerRepresentation();
1607-
};
1608-
return CheckArgsTypesAreCorrect(S, TheCall, S->Context.IntTy,
1609-
checkAllIntTypes);
1610-
}
1611-
16121604
void SetElementTypeAsReturnType(Sema *S, CallExpr *TheCall,
16131605
QualType ReturnType) {
16141606
auto *VecTyA = TheCall->getArg(0)->getType()->getAs<VectorType>();
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
// RUN: %clang_cc1 -std=hlsl2021 -finclude-default-header -x hlsl -triple \
2+
// RUN: dxil-pc-shadermodel6.3-library %s -fnative-half-type \
3+
// RUN: -emit-llvm -disable-llvm-passes -O3 -o - | FileCheck %s
4+
5+
#ifdef __HLSL_ENABLE_16_BIT
6+
// CHECK: define noundef i16 @
7+
// CHECK: call i16 @llvm.ctpop.i16(
8+
uint16_t test_countbits_ushort(uint16_t p0)
9+
{
10+
return countbits(p0);
11+
}
12+
// CHECK: define noundef <2 x i16> @
13+
// CHECK: call <2 x i16> @llvm.ctpop.v2i16
14+
uint16_t2 test_countbits_ushort2(uint16_t2 p0)
15+
{
16+
return countbits(p0);
17+
}
18+
// CHECK: define noundef <3 x i16> @
19+
// CHECK: call <3 x i16> @llvm.ctpop.v3i16
20+
uint16_t3 test_countbits_ushort3(uint16_t3 p0)
21+
{
22+
return countbits(p0);
23+
}
24+
// CHECK: define noundef <4 x i16> @
25+
// CHECK: call <4 x i16> @llvm.ctpop.v4i16
26+
uint16_t4 test_countbits_ushort4(uint16_t4 p0)
27+
{
28+
return countbits(p0);
29+
}
30+
#endif
31+
32+
// CHECK: define noundef i32 @
33+
// CHECK: call i32 @llvm.ctpop.i32(
34+
int test_countbits_uint(uint p0)
35+
{
36+
return countbits(p0);
37+
}
38+
// CHECK: define noundef <2 x i32> @
39+
// CHECK: call <2 x i32> @llvm.ctpop.v2i32
40+
uint2 test_countbits_uint2(uint2 p0)
41+
{
42+
return countbits(p0);
43+
}
44+
// CHECK: define noundef <3 x i32> @
45+
// CHECK: call <3 x i32> @llvm.ctpop.v3i32
46+
uint3 test_countbits_uint3(uint3 p0)
47+
{
48+
return countbits(p0);
49+
}
50+
// CHECK: define noundef <4 x i32> @
51+
// CHECK: call <4 x i32> @llvm.ctpop.v4i32
52+
uint4 test_countbits_uint4(uint4 p0)
53+
{
54+
return countbits(p0);
55+
}
56+
57+
// CHECK: define noundef i64 @
58+
// CHECK: call i64 @llvm.ctpop.i64(
59+
uint64_t test_countbits_long(uint64_t p0)
60+
{
61+
return countbits(p0);
62+
}
63+
// CHECK: define noundef <2 x i64> @
64+
// CHECK: call <2 x i64> @llvm.ctpop.v2i64
65+
uint64_t2 test_countbits_long2(uint64_t2 p0)
66+
{
67+
return countbits(p0);
68+
}
69+
// CHECK: define noundef <3 x i64> @
70+
// CHECK: call <3 x i64> @llvm.ctpop.v3i64
71+
uint64_t3 test_countbits_long3(uint64_t3 p0)
72+
{
73+
return countbits(p0);
74+
}
75+
// CHECK: define noundef <4 x i64> @
76+
// CHECK: call <4 x i64> @llvm.ctpop.v4i64
77+
uint64_t4 test_countbits_long4(uint64_t4 p0)
78+
{
79+
return countbits(p0);
80+
}

clang/test/Sema/builtins-elementwise-math.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,18 @@ void test_builtin_elementwise_popcount(int i, float f, double d, float4 v, int3
524524

525525
v = __builtin_elementwise_popcount(v);
526526
// expected-error@-1 {{1st argument must be a vector of integers (was 'float4' (vector of 4 'float' values))}}
527+
528+
int2 i2 = __builtin_elementwise_popcount(iv);
529+
// expected-error@-1 {{initializing 'int2' (vector of 2 'int' values) with an expression of incompatible type 'int3' (vector of 3 'int' values)}}
530+
531+
iv = __builtin_elementwise_popcount(i2);
532+
// expected-error@-1 {{assigning to 'int3' (vector of 3 'int' values) from incompatible type 'int2' (vector of 2 'int' values)}}
533+
534+
unsigned3 u3 = __builtin_elementwise_popcount(iv);
535+
// expected-error@-1 {{initializing 'unsigned3' (vector of 3 'unsigned int' values) with an expression of incompatible type 'int3' (vector of 3 'int' values)}}
536+
537+
iv = __builtin_elementwise_popcount(u3);
538+
// expected-error@-1 {{assigning to 'int3' (vector of 3 'int' values) from incompatible type 'unsigned3' (vector of 3 'unsigned int' values)}}
527539
}
528540

529541
void test_builtin_elementwise_pow(int i, short s, double d, float4 v, int3 iv, unsigned3 uv, int *p) {

clang/test/Sema/countbits-errors.hlsl

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// RUN: %clang_cc1 -finclude-default-header
2+
// -triple dxil-pc-shadermodel6.6-library %s -fnative-half-type -emit-llvm-only
3+
// -disable-llvm-passes -verify
4+
5+
double2 test_int_builtin(double2 p0) {
6+
return __builtin_hlsl_elementwise_countbits(p0);
7+
// expected-error@-1 {{passing 'double2' (aka 'vector<double, 2>') to
8+
// parameter of incompatible type
9+
// '__attribute__((__vector_size__(2 * sizeof(int)))) int'
10+
// (vector of 2 'int' values)}}
11+
}
12+
13+
float test_ambiguous(float p0) {
14+
return countbits(p0);
15+
// expected-error@-1 {{call to 'countbits' is ambiguous}}
16+
// expected-note@hlsl/hlsl_intrinsics.h:* {{candidate function}}
17+
// expected-note@hlsl/hlsl_intrinsics.h:* {{candidate function}}
18+
// expected-note@hlsl/hlsl_intrinsics.h:* {{candidate function}}
19+
// expected-note@hlsl/hlsl_intrinsics.h:* {{candidate function}}
20+
// expected-note@hlsl/hlsl_intrinsics.h:* {{candidate function}}
21+
// expected-note@hlsl/hlsl_intrinsics.h:* {{candidate function}}
22+
}
23+
24+
float test_float_builtin(float p0) {
25+
return __builtin_hlsl_elementwise_countbits(p0);
26+
// expected-error@-1 {{passing 'double' to parameter of incompatible type
27+
// 'int'}}
28+
}
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// RUN: %clang_cc1 -finclude-default-header
2+
// -triple dxil-pc-shadermodel6.6-library %s -fnative-half-type -emit-llvm-only
3+
// -disable-llvm-passes -verify
4+
5+
6+
double test_int_builtin(double p0) {
7+
return countbits(p0);
8+
// expected-error@-1 {{call to 'countbits' is ambiguous}}
9+
// expected-note@hlsl/hlsl_intrinsics.h:* {{candidate function}}
10+
// expected-note@hlsl/hlsl_intrinsics.h:* {{candidate function}}
11+
// expected-note@hlsl/hlsl_intrinsics.h:* {{candidate function}}
12+
// expected-note@hlsl/hlsl_intrinsics.h:* {{candidate function}}
13+
// expected-note@hlsl/hlsl_intrinsics.h:* {{candidate function}}
14+
// expected-note@hlsl/hlsl_intrinsics.h:* {{candidate function}}
15+
}
16+
17+
double2 test_int_builtin_2(double2 p0) {
18+
return __builtin_elementwise_popcount(p0);
19+
// expected-error@-1 {{1st argument must be a vector of integers
20+
// (was 'double2' (aka 'vector<double, 2>'))}}
21+
}
22+
23+
double test_int_builtin_3(float p0) {
24+
return __builtin_elementwise_popcount(p0);
25+
// expected-error@-1 {{1st argument must be a vector of integers
26+
// (was 'float')}}
27+
}

llvm/test/CodeGen/DirectX/countbits.ll

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,23 @@
22

33
; Make sure dxil operation function calls for countbits are generated for all integer types.
44

5-
; Function Attrs: nounwind
65
define noundef i16 @test_countbits_short(i16 noundef %a) {
76
entry:
8-
; CHECK:call i16 @dx.op.unary.i16(i32 31, i16 %{{.*}})
7+
; CHECK: call i16 @dx.op.unary.i16(i32 31, i16 %{{.*}})
98
%elt.ctpop = call i16 @llvm.ctpop.i16(i16 %a)
109
ret i16 %elt.ctpop
1110
}
1211

13-
; Function Attrs: nounwind
1412
define noundef i32 @test_countbits_int(i32 noundef %a) {
1513
entry:
16-
; CHECK:call i32 @dx.op.unary.i32(i32 31, i32 %{{.*}})
14+
; CHECK: call i32 @dx.op.unary.i32(i32 31, i32 %{{.*}})
1715
%elt.ctpop = call i32 @llvm.ctpop.i32(i32 %a)
1816
ret i32 %elt.ctpop
1917
}
2018

21-
; Function Attrs: nounwind
2219
define noundef i64 @test_countbits_long(i64 noundef %a) {
2320
entry:
24-
; CHECK:call i64 @dx.op.unary.i64(i32 31, i64 %{{.*}})
21+
; CHECK: call i64 @dx.op.unary.i64(i32 31, i64 %{{.*}})
2522
%elt.ctpop = call i64 @llvm.ctpop.i64(i64 %a)
2623
ret i64 %elt.ctpop
2724
}

llvm/test/CodeGen/DirectX/countbits_error.ll

Lines changed: 0 additions & 10 deletions
This file was deleted.

0 commit comments

Comments
 (0)