1 // REQUIRES: powerpc-registered-target
2 // RUN: %clang_cc1 -O2 -target-cpu pwr8 -triple=powerpc-unknown-aix \
3 // RUN:  -emit-llvm %s -o - | FileCheck %s
4 // RUN: %clang_cc1 -O2 -target-cpu pwr8 -triple=powerpc64-unknown-aix \
5 // RUN:  -emit-llvm %s -o - | FileCheck %s
6 // RUN: %clang_cc1 -O2 -target-cpu pwr8 -triple=powerpc64le-unknown-linux-gnu \
7 // RUN:  -emit-llvm %s -o - | FileCheck %s
8 // RUN: %clang_cc1 -O2 -target-cpu pwr8 -triple=powerpc64-unknown-linux-gnu \
9 // RUN:  -emit-llvm %s -o - | FileCheck %s
10 // RAUN: not %clang_cc1 -O2 -target-cpu pwr7 -triple=powerpc-unknown-aix \
11 // RAUN:  -emit-llvm %s -o - 2>&1 | FileCheck %s \
12 // RAUN:  --check-prefix=CHECK-NON-PWR8-ERR
13 
test_lwarx(volatile int * a)14 int test_lwarx(volatile int* a) {
15   // CHECK-LABEL: @test_lwarx
16   // CHECK: %0 = tail call i32 asm sideeffect "lwarx $0, ${1:y}", "=r,*Z,~{memory}"(i32* %a)
17   return __lwarx(a);
18 }
19 
test_lharx(volatile short * a)20 short test_lharx(volatile short *a) {
21   // CHECK-LABEL: @test_lharx
22   // CHECK: %0 = tail call i16 asm sideeffect "lharx $0, ${1:y}", "=r,*Z,~{memory}"(i16* %a)
23   // CHECK-NON-PWR8-ERR:  error: this builtin is only valid on POWER8 or later CPUs
24   return __lharx(a);
25 }
26 
test_lbarx(volatile unsigned char * a)27 char test_lbarx(volatile unsigned char *a) {
28   // CHECK-LABEL: @test_lbarx
29   // CHECK: %0 = tail call i8 asm sideeffect "lbarx $0, ${1:y}", "=r,*Z,~{memory}"(i8* %a)
30   // CHECK-NON-PWR8-ERR:  error: this builtin is only valid on POWER8 or later CPUs
31   return __lbarx(a);
32 }
33 
test_stwcx(volatile int * a,int val)34 int test_stwcx(volatile int* a, int val) {
35   // CHECK-LABEL: @test_stwcx
36   // CHECK: %0 = bitcast i32* %a to i8*
37   // CHECK: %1 = tail call i32 @llvm.ppc.stwcx(i8* %0, i32 %val)
38   return __stwcx(a, val);
39 }
40 
test_sthcx(volatile short * a,short val)41 int test_sthcx(volatile short *a, short val) {
42   // CHECK-LABEL: @test_sthcx
43   // CHECK: %0 = bitcast i16* %a to i8*
44   // CHECK: %1 = sext i16 %val to i32
45   // CHECK: %2 = tail call i32 @llvm.ppc.sthcx(i8* %0, i32 %1)
46   // CHECK-NON-PWR8-ERR:  error: this builtin is only valid on POWER8 or later CPUs
47   return __sthcx(a, val);
48 }
49