Skip to content

Commit b824f7c

Browse files
authored
[X86] Add -fexperimental-new-constant-interpreter test coverage to the LZCNT/POPCNT constexpr test files (#156048)
Update tests to use builtin_test_helpers.h and the TEST_CONSTEXPR helper macro Partial fix for #155814
1 parent 7fca1f8 commit b824f7c

File tree

2 files changed

+38
-51
lines changed

2 files changed

+38
-51
lines changed
Lines changed: 19 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,54 @@
11
// RUN: %clang_cc1 -x c -ffreestanding %s -triple=x86_64-apple-darwin -emit-llvm -o - | FileCheck %s
22
// RUN: %clang_cc1 -x c++ -std=c++11 -ffreestanding %s -triple=x86_64-apple-darwin -emit-llvm -o - | FileCheck %s
33

4+
// RUN: %clang_cc1 -x c -ffreestanding %s -triple=x86_64-apple-darwin -emit-llvm -o - -fexperimental-new-constant-interpreter | FileCheck %s
5+
// RUN: %clang_cc1 -x c++ -std=c++11 -ffreestanding %s -triple=x86_64-apple-darwin -emit-llvm -o - -fexperimental-new-constant-interpreter | FileCheck %s
6+
47

58
#include <immintrin.h>
9+
#include "builtin_test_helpers.h"
610

711
unsigned short test__lzcnt16(unsigned short __X)
812
{
913
// CHECK: @llvm.ctlz.i16(i16 %{{.*}}, i1 false)
1014
return __lzcnt16(__X);
1115
}
16+
TEST_CONSTEXPR(__lzcnt16(0x0000) == 16);
17+
TEST_CONSTEXPR(__lzcnt16(0x8000) == 0);
18+
TEST_CONSTEXPR(__lzcnt16(0x0010) == 11);
1219

1320
unsigned int test_lzcnt32(unsigned int __X)
1421
{
1522
// CHECK: @llvm.ctlz.i32(i32 %{{.*}}, i1 false)
1623
return __lzcnt32(__X);
1724
}
25+
TEST_CONSTEXPR(__lzcnt32(0x00000000) == 32);
26+
TEST_CONSTEXPR(__lzcnt32(0x80000000) == 0);
27+
TEST_CONSTEXPR(__lzcnt32(0x00000010) == 27);
1828

1929
unsigned long long test__lzcnt64(unsigned long long __X)
2030
{
2131
// CHECK: @llvm.ctlz.i64(i64 %{{.*}}, i1 false)
2232
return __lzcnt64(__X);
2333
}
34+
TEST_CONSTEXPR(__lzcnt64(0x0000000000000000ULL) == 64);
35+
TEST_CONSTEXPR(__lzcnt64(0x8000000000000000ULL) == 0);
36+
TEST_CONSTEXPR(__lzcnt64(0x0000000100000000ULL) == 31);
2437

2538
unsigned int test_lzcnt_u32(unsigned int __X)
2639
{
2740
// CHECK: @llvm.ctlz.i32(i32 %{{.*}}, i1 false)
2841
return _lzcnt_u32(__X);
2942
}
43+
TEST_CONSTEXPR(_lzcnt_u32(0x00000000) == 32);
44+
TEST_CONSTEXPR(_lzcnt_u32(0x80000000) == 0);
45+
TEST_CONSTEXPR(_lzcnt_u32(0x00000010) == 27);
3046

3147
unsigned long long test__lzcnt_u64(unsigned long long __X)
3248
{
3349
// CHECK: @llvm.ctlz.i64(i64 %{{.*}}, i1 false)
3450
return _lzcnt_u64(__X);
3551
}
36-
37-
38-
// Test constexpr handling.
39-
#if defined(__cplusplus) && (__cplusplus >= 201103L)
40-
char lzcnt16_0[__lzcnt16(0x0000) == 16 ? 1 : -1];
41-
char lzcnt16_1[__lzcnt16(0x8000) == 0 ? 1 : -1];
42-
char lzcnt16_2[__lzcnt16(0x0010) == 11 ? 1 : -1];
43-
44-
char lzcnt32_0[__lzcnt32(0x00000000) == 32 ? 1 : -1];
45-
char lzcnt32_1[__lzcnt32(0x80000000) == 0 ? 1 : -1];
46-
char lzcnt32_2[__lzcnt32(0x00000010) == 27 ? 1 : -1];
47-
48-
char lzcnt64_0[__lzcnt64(0x0000000000000000ULL) == 64 ? 1 : -1];
49-
char lzcnt64_1[__lzcnt64(0x8000000000000000ULL) == 0 ? 1 : -1];
50-
char lzcnt64_2[__lzcnt64(0x0000000100000000ULL) == 31 ? 1 : -1];
51-
52-
char lzcntu32_0[_lzcnt_u32(0x00000000) == 32 ? 1 : -1];
53-
char lzcntu32_1[_lzcnt_u32(0x80000000) == 0 ? 1 : -1];
54-
char lzcntu32_2[_lzcnt_u32(0x00000010) == 27 ? 1 : -1];
55-
56-
char lzcntu64_0[_lzcnt_u64(0x0000000000000000ULL) == 64 ? 1 : -1];
57-
char lzcntu64_1[_lzcnt_u64(0x8000000000000000ULL) == 0 ? 1 : -1];
58-
char lzcntu64_2[_lzcnt_u64(0x0000000100000000ULL) == 31 ? 1 : -1];
59-
#endif
52+
TEST_CONSTEXPR(_lzcnt_u64(0x0000000000000000ULL) == 64);
53+
TEST_CONSTEXPR(_lzcnt_u64(0x8000000000000000ULL) == 0);
54+
TEST_CONSTEXPR(_lzcnt_u64(0x0000000100000000ULL) == 31);

clang/test/CodeGen/X86/popcnt-builtins.c

Lines changed: 19 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,67 +3,59 @@
33
// RUN: %clang_cc1 -x c -ffreestanding %s -triple=x86_64-apple-darwin -no-enable-noundef-analysis -emit-llvm -o - | FileCheck %s
44
// RUN: %clang_cc1 -x c++ -std=c++11 -ffreestanding %s -triple=x86_64-apple-darwin -no-enable-noundef-analysis -emit-llvm -o - | FileCheck %s
55

6+
// RUN: %clang_cc1 -x c -ffreestanding %s -triple=x86_64-apple-darwin -target-feature +popcnt -no-enable-noundef-analysis -emit-llvm -o - -fexperimental-new-constant-interpreter | FileCheck %s --check-prefixes=CHECK,CHECK-POPCNT
7+
// RUN: %clang_cc1 -x c++ -std=c++11 -ffreestanding %s -triple=x86_64-apple-darwin -target-feature +popcnt -no-enable-noundef-analysis -emit-llvm -o - -fexperimental-new-constant-interpreter | FileCheck %s --check-prefixes=CHECK,CHECK-POPCNT
8+
// RUN: %clang_cc1 -x c -ffreestanding %s -triple=x86_64-apple-darwin -no-enable-noundef-analysis -emit-llvm -o - -fexperimental-new-constant-interpreter | FileCheck %s
9+
// RUN: %clang_cc1 -x c++ -std=c++11 -ffreestanding %s -triple=x86_64-apple-darwin -no-enable-noundef-analysis -emit-llvm -o - -fexperimental-new-constant-interpreter | FileCheck %s
10+
11+
612
#include <x86intrin.h>
13+
#include "builtin_test_helpers.h"
714

815
#ifdef __POPCNT__
916
int test_mm_popcnt_u32(unsigned int __X) {
1017
//CHECK-POPCNT: call i32 @llvm.ctpop.i32
1118
return _mm_popcnt_u32(__X);
1219
}
20+
TEST_CONSTEXPR(_mm_popcnt_u32(0x00000000) == 0);
21+
TEST_CONSTEXPR(_mm_popcnt_u32(0x000000F0) == 4);
1322
#endif
1423

1524
int test_popcnt32(unsigned int __X) {
1625
//CHECK: call i32 @llvm.ctpop.i32
1726
return _popcnt32(__X);
1827
}
28+
TEST_CONSTEXPR(_popcnt32(0x00000000) == 0);
29+
TEST_CONSTEXPR(_popcnt32(0x100000F0) == 5);
1930

2031
int test__popcntd(unsigned int __X) {
2132
//CHECK: call i32 @llvm.ctpop.i32
2233
return __popcntd(__X);
2334
}
35+
TEST_CONSTEXPR(__popcntd(0x00000000) == 0);
36+
TEST_CONSTEXPR(__popcntd(0x00F000F0) == 8);
2437

2538
#ifdef __x86_64__
2639
#ifdef __POPCNT__
2740
long long test_mm_popcnt_u64(unsigned long long __X) {
2841
//CHECK-POPCNT: call i64 @llvm.ctpop.i64
2942
return _mm_popcnt_u64(__X);
3043
}
44+
TEST_CONSTEXPR(_mm_popcnt_u64(0x0000000000000000ULL) == 0);
45+
TEST_CONSTEXPR(_mm_popcnt_u64(0xF000000000000001ULL) == 5);
3146
#endif
3247

3348
long long test_popcnt64(unsigned long long __X) {
3449
//CHECK: call i64 @llvm.ctpop.i64
3550
return _popcnt64(__X);
3651
}
52+
TEST_CONSTEXPR(_popcnt64(0x0000000000000000ULL) == 0);
53+
TEST_CONSTEXPR(_popcnt64(0xF00000F000000001ULL) == 9);
3754

3855
long long test__popcntq(unsigned long long __X) {
3956
//CHECK: call i64 @llvm.ctpop.i64
4057
return __popcntq(__X);
4158
}
42-
#endif
43-
44-
// Test constexpr handling.
45-
#if defined(__cplusplus) && (__cplusplus >= 201103L)
46-
#if defined(__POPCNT__)
47-
char ctpop32_0[_mm_popcnt_u32(0x00000000) == 0 ? 1 : -1];
48-
char ctpop32_1[_mm_popcnt_u32(0x000000F0) == 4 ? 1 : -1];
49-
#endif
50-
51-
char popcnt32_0[_popcnt32(0x00000000) == 0 ? 1 : -1];
52-
char popcnt32_1[_popcnt32(0x100000F0) == 5 ? 1 : -1];
53-
54-
char popcntd_0[__popcntd(0x00000000) == 0 ? 1 : -1];
55-
char popcntd_1[__popcntd(0x00F000F0) == 8 ? 1 : -1];
56-
57-
#ifdef __x86_64__
58-
#if defined(__POPCNT__)
59-
char ctpop64_0[_mm_popcnt_u64(0x0000000000000000ULL) == 0 ? 1 : -1];
60-
char ctpop64_1[_mm_popcnt_u64(0xF000000000000001ULL) == 5 ? 1 : -1];
61-
#endif
62-
63-
char popcnt64_0[_popcnt64(0x0000000000000000ULL) == 0 ? 1 : -1];
64-
char popcnt64_1[_popcnt64(0xF00000F000000001ULL) == 9 ? 1 : -1];
65-
66-
char popcntq_0[__popcntq(0x0000000000000000ULL) == 0 ? 1 : -1];
67-
char popcntq_1[__popcntq(0xF000010000300001ULL) == 8 ? 1 : -1];
68-
#endif
59+
TEST_CONSTEXPR(__popcntq(0x0000000000000000ULL) == 0);
60+
TEST_CONSTEXPR(__popcntq(0xF000010000300001ULL) == 8);
6961
#endif

0 commit comments

Comments
 (0)