| 1 |
// RUN: %clang_cc1 -x c -ffreestanding %s -triple=x86_64-unknown-unknown -no-enable-noundef-analysis -emit-llvm -o - | FileCheck %s |
| 2 |
// RUN: %clang_cc1 -x c++ -std=c++11 -ffreestanding %s -triple=x86_64-unknown-unknown -no-enable-noundef-analysis -emit-llvm -o - | FileCheck %s |
| 3 |
|
| 4 |
// PR33722 |
| 5 |
// RUN: %clang_cc1 -x c -ffreestanding %s -triple x86_64-unknown-unknown -fms-extensions -fms-compatibility-version=19.00 -no-enable-noundef-analysis -emit-llvm -o - | FileCheck %s |
| 6 |
// RUN: %clang_cc1 -x c++ -ffreestanding %s -triple x86_64-unknown-unknown -fms-extensions -fms-compatibility-version=19.00 -no-enable-noundef-analysis -emit-llvm -o - | FileCheck %s |
| 7 |
|
| 8 |
#include <x86intrin.h> |
| 9 |
|
| 10 |
int test_bit_scan_forward(int a) { |
| 11 |
// CHECK-LABEL: test_bit_scan_forward |
| 12 |
// CHECK: %[[call:.*]] = call i32 @llvm.cttz.i32(i32 %{{.*}}, i1 true) |
| 13 |
// CHECK: ret i32 %[[call]] |
| 14 |
return _bit_scan_forward(a); |
| 15 |
} |
| 16 |
|
| 17 |
int test_bit_scan_reverse(int a) { |
| 18 |
// CHECK-LABEL: test_bit_scan_reverse |
| 19 |
// CHECK: %[[call:.*]] = call i32 @llvm.ctlz.i32(i32 %{{.*}}, i1 true) |
| 20 |
// CHECK: %[[sub:.*]] = sub nsw i32 31, %[[call]] |
| 21 |
// CHECK: ret i32 %[[sub]] |
| 22 |
return _bit_scan_reverse(a); |
| 23 |
} |
| 24 |
|
| 25 |
int test__bsfd(int X) { |
| 26 |
// CHECK-LABEL: test__bsfd |
| 27 |
// CHECK: %[[call:.*]] = call i32 @llvm.cttz.i32(i32 %{{.*}}, i1 true) |
| 28 |
return __bsfd(X); |
| 29 |
} |
| 30 |
|
| 31 |
int test__bsfq(long long X) { |
| 32 |
// CHECK-LABEL: test__bsfq |
| 33 |
// CHECK: %[[call:.*]] = call i64 @llvm.cttz.i64(i64 %{{.*}}, i1 true) |
| 34 |
return __bsfq(X); |
| 35 |
} |
| 36 |
|
| 37 |
int test__bsrd(int X) { |
| 38 |
// CHECK-LABEL: test__bsrd |
| 39 |
// CHECK: %[[call:.*]] = call i32 @llvm.ctlz.i32(i32 %{{.*}}, i1 true) |
| 40 |
// CHECK: %[[sub:.*]] = sub nsw i32 31, %[[call]] |
| 41 |
return __bsrd(X); |
| 42 |
} |
| 43 |
|
| 44 |
int test__bsrq(long long X) { |
| 45 |
// CHECK-LABEL: test__bsrq |
| 46 |
// CHECK: %[[call:.*]] = call i64 @llvm.ctlz.i64(i64 %{{.*}}, i1 true) |
| 47 |
// CHECK: %[[cast:.*]] = trunc i64 %[[call]] to i32 |
| 48 |
// CHECK: %[[sub:.*]] = sub nsw i32 63, %[[cast]] |
| 49 |
return __bsrq(X); |
| 50 |
} |
| 51 |
|
| 52 |
// Test constexpr handling. |
| 53 |
#if defined(__cplusplus) && (__cplusplus >= 201103L) |
| 54 |
|
| 55 |
char bsf_0[_bit_scan_forward(0x00000001) == 0 ? 1 : -1]; |
| 56 |
char bsf_1[_bit_scan_forward(0x10000000) == 28 ? 1 : -1]; |
| 57 |
|
| 58 |
char bsr_0[_bit_scan_reverse(0x00000001) == 0 ? 1 : -1]; |
| 59 |
char bsr_1[_bit_scan_reverse(0x01000000) == 24 ? 1 : -1]; |
| 60 |
|
| 61 |
char bsfd_0[__bsfd(0x00000008) == 3 ? 1 : -1]; |
| 62 |
char bsfd_1[__bsfd(0x00010008) == 3 ? 1 : -1]; |
| 63 |
|
| 64 |
char bsrd_0[__bsrd(0x00000010) == 4 ? 1 : -1]; |
| 65 |
char bsrd_1[__bsrd(0x00100100) == 20 ? 1 : -1]; |
| 66 |
|
| 67 |
char bsfq_0[__bsfq(0x0000000800000000ULL) == 35 ? 1 : -1]; |
| 68 |
char bsfq_1[__bsfq(0x0004000000000000ULL) == 50 ? 1 : -1]; |
| 69 |
|
| 70 |
char bsrq_0[__bsrq(0x0000100800000000ULL) == 44 ? 1 : -1]; |
| 71 |
char bsrq_1[__bsrq(0x0004000100000000ULL) == 50 ? 1 : -1]; |
| 72 |
|
| 73 |
#endif |