1 // RUN: %clang_cc1 -ffreestanding -fms-extensions -fms-compatibility -fms-compatibility-version=17.00 \ 2 // RUN: -triple i686--windows -Oz -emit-llvm %s -o - \ 3 // RUN: | FileCheck %s -check-prefix CHECK -check-prefix CHECK-I386 4 // RUN: %clang_cc1 -ffreestanding -fms-extensions -fms-compatibility -fms-compatibility-version=17.00 \ 5 // RUN: -triple thumbv7--windows -Oz -emit-llvm %s -o - \ 6 // RUN: | FileCheck %s 7 // RUN: %clang_cc1 -ffreestanding -fms-extensions -fms-compatibility -fms-compatibility-version=17.00 \ 8 // RUN: -triple x86_64--windows -Oz -emit-llvm %s -o - \ 9 // RUN: | FileCheck %s --check-prefix=CHECK --check-prefix=CHECK-X64 10 11 // intrin.h needs size_t, but -ffreestanding prevents us from getting it from 12 // stddef.h. Work around it with this typedef. 13 typedef __SIZE_TYPE__ size_t; 14 15 #include <intrin.h> 16 17 void *test_InterlockedExchangePointer(void * volatile *Target, void *Value) { 18 return _InterlockedExchangePointer(Target, Value); 19 } 20 21 // CHECK: define{{.*}}i8* @test_InterlockedExchangePointer(i8** {{[a-z_ ]*}}%Target, i8* {{[a-z_ ]*}}%Value){{.*}}{ 22 // CHECK: %[[TARGET:[0-9]+]] = bitcast i8** %Target to [[iPTR:i[0-9]+]]* 23 // CHECK: %[[VALUE:[0-9]+]] = ptrtoint i8* %Value to [[iPTR]] 24 // CHECK: %[[EXCHANGE:[0-9]+]] = atomicrmw xchg [[iPTR]]* %[[TARGET]], [[iPTR]] %[[VALUE]] seq_cst 25 // CHECK: %[[RESULT:[0-9]+]] = inttoptr [[iPTR]] %[[EXCHANGE]] to i8* 26 // CHECK: ret i8* %[[RESULT]] 27 // CHECK: } 28 29 void *test_InterlockedCompareExchangePointer(void * volatile *Destination, 30 void *Exchange, void *Comparand) { 31 return _InterlockedCompareExchangePointer(Destination, Exchange, Comparand); 32 } 33 34 // CHECK: define{{.*}}i8* @test_InterlockedCompareExchangePointer(i8** {{[a-z_ ]*}}%Destination, i8* {{[a-z_ ]*}}%Exchange, i8* {{[a-z_ ]*}}%Comparand){{.*}}{ 35 // CHECK: %[[DEST:[0-9]+]] = bitcast i8** %Destination to [[iPTR]]* 36 // CHECK: %[[EXCHANGE:[0-9]+]] = ptrtoint i8* %Exchange to [[iPTR]] 37 // CHECK: %[[COMPARAND:[0-9]+]] = ptrtoint i8* %Comparand to [[iPTR]] 38 // CHECK: %[[XCHG:[0-9]+]] = cmpxchg volatile [[iPTR]]* %[[DEST:[0-9]+]], [[iPTR]] %[[COMPARAND:[0-9]+]], [[iPTR]] %[[EXCHANGE:[0-9]+]] seq_cst seq_cst 39 // CHECK: %[[EXTRACT:[0-9]+]] = extractvalue { [[iPTR]], i1 } %[[XCHG]], 0 40 // CHECK: %[[RESULT:[0-9]+]] = inttoptr [[iPTR]] %[[EXTRACT]] to i8* 41 // CHECK: ret i8* %[[RESULT:[0-9]+]] 42 // CHECK: } 43 44 long test_InterlockedExchange(long *Target, long Value) { 45 return _InterlockedExchange(Target, Value); 46 } 47 48 // CHECK: define{{.*}}i32 @test_InterlockedExchange(i32* {{[a-z_ ]*}}%Target, i32 %Value){{.*}}{ 49 // CHECK: %[[EXCHANGE:[0-9]+]] = atomicrmw xchg i32* %Target, i32 %Value seq_cst 50 // CHECK: ret i32 %[[EXCHANGE:[0-9]+]] 51 // CHECK: } 52 53 #if defined(__i386__) 54 long test__readfsdword(unsigned long Offset) { 55 return __readfsdword(Offset); 56 } 57 58 // CHECK-I386: define i32 @test__readfsdword(i32 %Offset){{.*}}{ 59 // CHECK-I386: [[PTR:%[0-9]+]] = inttoptr i32 %Offset to i32 addrspace(257)* 60 // CHECK-I386: [[VALUE:%[0-9]+]] = load volatile i32, i32 addrspace(257)* [[PTR]], align 4 61 // CHECK-I386: ret i32 [[VALUE:%[0-9]+]] 62 // CHECK-I386: } 63 #endif 64 65 #if defined(__x86_64__) 66 unsigned __int64 test__umulh(unsigned __int64 a, unsigned __int64 b) { 67 return __umulh(a, b); 68 } 69 // CHECK-X64-LABEL: define i64 @test__umulh(i64 %a, i64 %b) 70 // CHECK-X64: = mul nuw i128 % 71 72 #endif 73 74