Revert "[llvm] Improve llvm.objectsize computation by computing GEP, alloca and mallo...
[llvm-project.git] / clang / test / CodeGen / X86 / bmi2-builtins.c
blob48424f553768be5f01dd09f1d53b881c8ca7b6b3
1 // RUN: %clang_cc1 -x c -ffreestanding %s -triple=x86_64-apple-darwin -target-feature +bmi2 -emit-llvm -o - | FileCheck %s
2 // RUN: %clang_cc1 -x c -ffreestanding %s -triple=i386-apple-darwin -target-feature +bmi2 -emit-llvm -o - | FileCheck %s --check-prefix=B32
3 // RUN: %clang_cc1 -x c++ -ffreestanding %s -triple=x86_64-apple-darwin -target-feature +bmi2 -emit-llvm -o - | FileCheck %s
4 // RUN: %clang_cc1 -x c++ -ffreestanding %s -triple=i386-apple-darwin -target-feature +bmi2 -emit-llvm -o - | FileCheck %s --check-prefix=B32
7 #include <immintrin.h>
9 unsigned int test_bzhi_u32(unsigned int __X, unsigned int __Y) {
10 // CHECK: @llvm.x86.bmi.bzhi.32
11 return _bzhi_u32(__X, __Y);
14 unsigned int test_pdep_u32(unsigned int __X, unsigned int __Y) {
15 // CHECK: @llvm.x86.bmi.pdep.32
16 return _pdep_u32(__X, __Y);
19 unsigned int test_pext_u32(unsigned int __X, unsigned int __Y) {
20 // CHECK: @llvm.x86.bmi.pext.32
21 return _pext_u32(__X, __Y);
24 #ifdef __i386__
25 unsigned int test_mulx_u32(unsigned int __X, unsigned int __Y,
26 unsigned int *__P) {
27 // B32: mul i64
28 return _mulx_u32(__X, __Y, __P);
30 #endif
32 #ifdef __x86_64__
33 unsigned long long test_bzhi_u64(unsigned long long __X, unsigned long long __Y) {
34 // CHECK: @llvm.x86.bmi.bzhi.64
35 return _bzhi_u64(__X, __Y);
38 unsigned long long test_pdep_u64(unsigned long long __X, unsigned long long __Y) {
39 // CHECK: @llvm.x86.bmi.pdep.64
40 return _pdep_u64(__X, __Y);
43 unsigned long long test_pext_u64(unsigned long long __X, unsigned long long __Y) {
44 // CHECK: @llvm.x86.bmi.pext.64
45 return _pext_u64(__X, __Y);
48 unsigned long long test_mulx_u64(unsigned long long __X, unsigned long long __Y,
49 unsigned long long *__P) {
50 // CHECK: mul i128
51 return _mulx_u64(__X, __Y, __P);
53 #endif
55 // Test constexpr handling.
56 #if defined(__cplusplus) && (__cplusplus >= 201103L)
57 char bzhi32_0[_bzhi_u32(0x89ABCDEF, 0) == 0x00000000 ? 1 : -1];
58 char bzhi32_1[_bzhi_u32(0x89ABCDEF, 16) == 0x0000CDEF ? 1 : -1];
59 char bzhi32_2[_bzhi_u32(0x89ABCDEF, 31) == 0x09ABCDEF ? 1 : -1];
60 char bzhi32_3[_bzhi_u32(0x89ABCDEF, 32) == 0x89ABCDEF ? 1 : -1];
61 char bzhi32_4[_bzhi_u32(0x89ABCDEF, 99) == 0x89ABCDEF ? 1 : -1];
62 char bzhi32_5[_bzhi_u32(0x89ABCDEF, 260) == 0x0000000F ? 1 : -1];
64 char pdep32_0[_pdep_u32(0x89ABCDEF, 0x00000000) == 0x00000000 ? 1 : -1];
65 char pdep32_1[_pdep_u32(0x89ABCDEF, 0x000000F0) == 0x000000F0 ? 1 : -1];
66 char pdep32_2[_pdep_u32(0x89ABCDEF, 0xF00000F0) == 0xE00000F0 ? 1 : -1];
67 char pdep32_3[_pdep_u32(0x89ABCDEF, 0xFFFFFFFF) == 0x89ABCDEF ? 1 : -1];
69 char pext32_0[_pext_u32(0x89ABCDEF, 0x00000000) == 0x00000000 ? 1 : -1];
70 char pext32_1[_pext_u32(0x89ABCDEF, 0x000000F0) == 0x0000000E ? 1 : -1];
71 char pext32_2[_pext_u32(0x89ABCDEF, 0xF00000F0) == 0x0000008E ? 1 : -1];
72 char pext32_3[_pext_u32(0x89ABCDEF, 0xFFFFFFFF) == 0x89ABCDEF ? 1 : -1];
74 constexpr unsigned long long
75 test_mulx_u32(unsigned int X, unsigned int Y)
77 unsigned int H{};
78 return _mulx_u32(X, Y, &H) | ((unsigned long long) H << 32);
81 void mulxu32() {
82 constexpr unsigned X = 0x89ABCDEF, Y = 0x01234567;
83 static_assert(test_mulx_u32(X,Y) == ((unsigned long long)X * Y));
86 #ifdef __x86_64__
87 char bzhi64_0[_bzhi_u64(0x0123456789ABCDEFULL, 0) == 0x0000000000000000ULL ? 1 : -1];
88 char bzhi64_1[_bzhi_u64(0x0123456789ABCDEFULL, 32) == 0x0000000089ABCDEFULL ? 1 : -1];
89 char bzhi64_2[_bzhi_u64(0x0123456789ABCDEFULL, 99) == 0x0123456789ABCDEFULL ? 1 : -1];
90 char bzhi64_3[_bzhi_u64(0x0123456789ABCDEFULL, 520) == 0x00000000000000EFULL ? 1 : -1];
92 char pdep64_0[_pdep_u64(0x0123456789ABCDEFULL, 0x0000000000000000ULL) == 0x0000000000000000ULL ? 1 : -1];
93 char pdep64_1[_pdep_u64(0x0123456789ABCDEFULL, 0x00000000000000F0ULL) == 0x00000000000000F0ULL ? 1 : -1];
94 char pdep64_2[_pdep_u64(0x0123456789ABCDEFULL, 0xF00000F0F00000F0ULL) == 0xC00000D0E00000F0ULL ? 1 : -1];
95 char pdep64_3[_pdep_u64(0x0123456789ABCDEFULL, 0xFFFFFFFFFFFFFFFFULL) == 0x0123456789ABCDEFULL ? 1 : -1];
97 char pext64_0[_pext_u64(0x0123456789ABCDEFULL, 0x0000000000000000ULL) == 0x0000000000000000ULL ? 1 : -1];
98 char pext64_1[_pext_u64(0x0123456789ABCDEFULL, 0x00000000000000F0ULL) == 0x000000000000000EULL ? 1 : -1];
99 char pext64_2[_pext_u64(0x0123456789ABCDEFULL, 0xF00000F0F00000F0ULL) == 0x000000000000068EULL ? 1 : -1];
100 char pext64_3[_pext_u64(0x0123456789ABCDEFULL, 0xFFFFFFFFFFFFFFFFULL) == 0x0123456789ABCDEFULL ? 1 : -1];
102 constexpr unsigned __int128
103 test_mulx_u64(unsigned long long X, unsigned long long Y)
105 unsigned long long H{};
106 return _mulx_u64(X, Y, &H) | ((unsigned __int128) H << 64);
109 void mulxu64() {
110 constexpr unsigned long long X = 0x0123456789ABCDEFULL, Y = 0xFEDCBA9876543210ULL;
111 static_assert(test_mulx_u64(X,Y) == ((unsigned __int128)X * Y));
113 #endif
114 #endif