blob: 2e1ba12d9b3cab8ee7bd1c080c4c57d303871ecb [file] [log] [blame]
Craig Topper19b4a712011-12-25 15:20:31 +00001// RUN: %clang_cc1 %s -O3 -triple=x86_64-apple-darwin -target-feature +bmi -emit-llvm -o - | FileCheck %s
Craig Topper5c752082011-12-25 06:25:37 +00002
3// Don't include mm_malloc.h, it's system specific.
4#define __MM_MALLOC_H
5
6#include <x86intrin.h>
7
Craig Topper435d2682012-07-02 06:52:51 +00008unsigned short test__tzcnt_u16(unsigned short __X) {
Craig Topper19b4a712011-12-25 15:20:31 +00009 // CHECK: @llvm.cttz.i16
Craig Topper435d2682012-07-02 06:52:51 +000010 return __tzcnt_u16(__X);
Craig Topper5c752082011-12-25 06:25:37 +000011}
12
Craig Topper0b269c12011-12-25 07:27:12 +000013unsigned int test__andn_u32(unsigned int __X, unsigned int __Y) {
Craig Topper19b4a712011-12-25 15:20:31 +000014 // CHECK: [[DEST:%.*]] = xor i32 %{{.*}}, -1
15 // CHECK-NEXT: %{{.*}} = and i32 %{{.*}}, [[DEST]]
Craig Topper0b269c12011-12-25 07:27:12 +000016 return __andn_u32(__X, __Y);
17}
18
19unsigned int test__bextr_u32(unsigned int __X, unsigned int __Y) {
Craig Topper19b4a712011-12-25 15:20:31 +000020 // CHECK: @llvm.x86.bmi.bextr.32
Craig Topper0b269c12011-12-25 07:27:12 +000021 return __bextr_u32(__X, __Y);
22}
23
24unsigned int test__blsi_u32(unsigned int __X) {
Craig Topper19b4a712011-12-25 15:20:31 +000025 // CHECK: [[DEST:%.*]] = sub i32 0, [[SRC:%.*]]
26 // CHECK-NEXT: %{{.*}} = and i32 [[SRC]], [[DEST]]
Craig Topper0b269c12011-12-25 07:27:12 +000027 return __blsi_u32(__X);
28}
29
30unsigned int test__blsmsk_u32(unsigned int __X) {
Craig Topper19b4a712011-12-25 15:20:31 +000031 // CHECK: [[DEST:%.*]] = add i32 [[SRC:%.*]], -1
32 // CHECK-NEXT: %{{.*}} = xor i32 [[DEST]], [[SRC]]
Craig Topper0b269c12011-12-25 07:27:12 +000033 return __blsmsk_u32(__X);
34}
35
36unsigned int test__blsr_u32(unsigned int __X) {
Craig Topper19b4a712011-12-25 15:20:31 +000037 // CHECK: [[DEST:%.*]] = add i32 [[SRC:%.*]], -1
38 // CHECK-NEXT: %{{.*}} = and i32 [[DEST]], [[SRC]]
Craig Topper0b269c12011-12-25 07:27:12 +000039 return __blsr_u32(__X);
40}
41
Craig Topper435d2682012-07-02 06:52:51 +000042unsigned int test_tzcnt_u32(unsigned int __X) {
Craig Topper19b4a712011-12-25 15:20:31 +000043 // CHECK: @llvm.cttz.i32
Craig Topper435d2682012-07-02 06:52:51 +000044 return __tzcnt_u32(__X);
Craig Topper5c752082011-12-25 06:25:37 +000045}
46
Craig Topper0b269c12011-12-25 07:27:12 +000047unsigned long long test__andn_u64(unsigned long __X, unsigned long __Y) {
Craig Topper19b4a712011-12-25 15:20:31 +000048 // CHECK: [[DEST:%.*]] = xor i64 %{{.*}}, -1
49 // CHECK-NEXT: %{{.*}} = and i64 %{{.*}}, [[DEST]]
Craig Topper0b269c12011-12-25 07:27:12 +000050 return __andn_u64(__X, __Y);
51}
52
53unsigned long long test__bextr_u64(unsigned long __X, unsigned long __Y) {
Craig Topper19b4a712011-12-25 15:20:31 +000054 // CHECK: @llvm.x86.bmi.bextr.64
Craig Topper0b269c12011-12-25 07:27:12 +000055 return __bextr_u64(__X, __Y);
56}
57
58unsigned long long test__blsi_u64(unsigned long long __X) {
Craig Topper19b4a712011-12-25 15:20:31 +000059 // CHECK: [[DEST:%.*]] = sub i64 0, [[SRC:%.*]]
60 // CHECK-NEXT: %{{.*}} = and i64 [[SRC]], [[DEST]]
Craig Topper0b269c12011-12-25 07:27:12 +000061 return __blsi_u64(__X);
62}
63
64unsigned long long test__blsmsk_u64(unsigned long long __X) {
Craig Topper19b4a712011-12-25 15:20:31 +000065 // CHECK: [[DEST:%.*]] = add i64 [[SRC:%.*]], -1
66 // CHECK-NEXT: %{{.*}} = xor i64 [[DEST]], [[SRC]]
Craig Topper0b269c12011-12-25 07:27:12 +000067 return __blsmsk_u64(__X);
68}
69
70unsigned long long test__blsr_u64(unsigned long long __X) {
Craig Topper19b4a712011-12-25 15:20:31 +000071 // CHECK: [[DEST:%.*]] = add i64 [[SRC:%.*]], -1
72 // CHECK-NEXT: %{{.*}} = and i64 [[DEST]], [[SRC]]
Craig Topper0b269c12011-12-25 07:27:12 +000073 return __blsr_u64(__X);
74}
75
Craig Topper435d2682012-07-02 06:52:51 +000076unsigned long long test__tzcnt_u64(unsigned long long __X) {
Craig Topper19b4a712011-12-25 15:20:31 +000077 // CHECK: @llvm.cttz.i64
Craig Topper435d2682012-07-02 06:52:51 +000078 return __tzcnt_u64(__X);
Craig Topper5c752082011-12-25 06:25:37 +000079}