Debian Codegraph @

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

raw
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 // RUN: %clang_cc1 -x c -ffreestanding %s -triple=x86_64-unknown-unknown -no-enable-noundef-analysis -emit-llvm -o - -fexperimental-new-constant-interpreter | FileCheck %s
5 // RUN: %clang_cc1 -x c++ -std=c++11 -ffreestanding %s -triple=x86_64-unknown-unknown -no-enable-noundef-analysis -emit-llvm -o - -fexperimental-new-constant-interpreter | FileCheck %s
6
7 // PR33722
8 // 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
9 // 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
10
11
12 #include <x86intrin.h>
13 #include "builtin_test_helpers.h"
14
15 int test_bit_scan_forward(int a) {
16 // CHECK-LABEL: test_bit_scan_forward
17 // CHECK: %[[call:.*]] = call i32 @llvm.cttz.i32(i32 %{{.*}}, i1 true)
18 // CHECK: ret i32 %[[call]]
19 return _bit_scan_forward(a);
20 }
21 TEST_CONSTEXPR(_bit_scan_forward(0x00000001) == 0);
22 TEST_CONSTEXPR(_bit_scan_forward(0x10000000) == 28);
23
24 int test_bit_scan_reverse(int a) {
25 // CHECK-LABEL: test_bit_scan_reverse
26 // CHECK: %[[call:.*]] = call i32 @llvm.ctlz.i32(i32 %{{.*}}, i1 true)
27 // CHECK: %[[sub:.*]] = sub nsw i32 31, %[[call]]
28 // CHECK: ret i32 %[[sub]]
29 return _bit_scan_reverse(a);
30 }
31 TEST_CONSTEXPR(_bit_scan_reverse(0x00000001) == 0);
32 TEST_CONSTEXPR(_bit_scan_reverse(0x01000000) == 24);
33
34 int test__bsfd(int X) {
35 // CHECK-LABEL: test__bsfd
36 // CHECK: %[[call:.*]] = call i32 @llvm.cttz.i32(i32 %{{.*}}, i1 true)
37 return __bsfd(X);
38 }
39 TEST_CONSTEXPR(__bsfd(0x00000008) == 3);
40 TEST_CONSTEXPR(__bsfd(0x00010008) == 3);
41
42 int test__bsfq(long long X) {
43 // CHECK-LABEL: test__bsfq
44 // CHECK: %[[call:.*]] = call i64 @llvm.cttz.i64(i64 %{{.*}}, i1 true)
45 return __bsfq(X);
46 }
47 TEST_CONSTEXPR(__bsfq(0x0000000800000000ULL) == 35);
48 TEST_CONSTEXPR(__bsfq(0x0004000000000000ULL) == 50);
49
50 int test__bsrd(int X) {
51 // CHECK-LABEL: test__bsrd
52 // CHECK: %[[call:.*]] = call i32 @llvm.ctlz.i32(i32 %{{.*}}, i1 true)
53 // CHECK: %[[sub:.*]] = sub nsw i32 31, %[[call]]
54 return __bsrd(X);
55 }
56 TEST_CONSTEXPR(__bsrd(0x00000010) == 4);
57 TEST_CONSTEXPR(__bsrd(0x00100100) == 20);
58
59 int test__bsrq(long long X) {
60 // CHECK-LABEL: test__bsrq
61 // CHECK: %[[call:.*]] = call i64 @llvm.ctlz.i64(i64 %{{.*}}, i1 true)
62 // CHECK: %[[cast:.*]] = trunc i64 %[[call]] to i32
63 // CHECK: %[[sub:.*]] = sub nsw i32 63, %[[cast]]
64 return __bsrq(X);
65 }
66 TEST_CONSTEXPR(__bsrq(0x0000100800000000ULL) == 44);
67 TEST_CONSTEXPR(__bsrq(0x0004000100000000ULL) == 50);