xref: /llvm-project/clang/test/CodeGen/LoongArch/intrinsic-la32-error.c (revision c4c3efa161edf7313d1aeda07cd82fab90c3717c)
1 // RUN: %clang_cc1 -triple loongarch32 -emit-llvm -verify %s -o /dev/null
2 // RUN: not %clang_cc1 -triple loongarch32 -DFEATURE_CHECK -emit-llvm %s -o /dev/null 2>&1 \
3 // RUN:   | FileCheck %s
4 
5 #include <larchintrin.h>
6 
7 #ifdef FEATURE_CHECK
test_feature(long * v_l,unsigned long * v_ul,int * v_i,unsigned ui,char c,short s)8 void test_feature(long *v_l, unsigned long *v_ul, int *v_i, unsigned ui, char c, short s) {
9 // CHECK: error: '__builtin_loongarch_cacop_d' needs target feature 64bit
10   __builtin_loongarch_cacop_d(1, v_ul[0], 1024);
11 
12 // CHECK: error: '__builtin_loongarch_crc_w_b_w' needs target feature 64bit
13   v_i[0] = __builtin_loongarch_crc_w_b_w(c, v_i[0]);
14 // CHECK: error: '__builtin_loongarch_crc_w_h_w' needs target feature 64bit
15   v_i[1] =  __builtin_loongarch_crc_w_h_w(c, v_i[0]);
16 // CHECK: error: '__builtin_loongarch_crc_w_w_w' needs target feature 64bit
17   v_i[2] = __builtin_loongarch_crc_w_w_w(c, v_i[0]);
18 // CHECK: error: '__builtin_loongarch_crc_w_d_w' needs target feature 64bit
19   v_i[3] = __builtin_loongarch_crc_w_d_w(c, v_i[0]);
20 
21 // CHECK: error: '__builtin_loongarch_crcc_w_b_w' needs target feature 64bit
22   v_i[4] = __builtin_loongarch_crcc_w_b_w(c, v_i[0]);
23 // CHECK: error: '__builtin_loongarch_crcc_w_h_w' needs target feature 64bit
24   v_i[5] = __builtin_loongarch_crcc_w_h_w(s, v_i[0]);
25 // CHECK: error: '__builtin_loongarch_crcc_w_w_w' needs target feature 64bit
26   v_i[6] = __builtin_loongarch_crcc_w_w_w(v_i[0], v_i[1]);
27 // CHECK: error: '__builtin_loongarch_crcc_w_d_w' needs target feature 64bit
28   v_i[7] = __builtin_loongarch_crcc_w_d_w(v_l[0], v_i[0]);
29 
30 // CHECK: error: '__builtin_loongarch_csrrd_d' needs target feature 64bit
31   v_ul[0] = __builtin_loongarch_csrrd_d(1);
32 // CHECK: error: '__builtin_loongarch_csrwr_d' needs target feature 64bit
33   v_ul[1] = __builtin_loongarch_csrwr_d(v_ul[0], 1);
34 // CHECK: error: '__builtin_loongarch_csrxchg_d' needs target feature 64bit
35   v_ul[2] = __builtin_loongarch_csrxchg_d(v_ul[0], v_ul[1], 1);
36 
37 
38 // CHECK: error: '__builtin_loongarch_iocsrrd_d' needs target feature 64bit
39   v_ul[3] = __builtin_loongarch_iocsrrd_d(ui);
40 // CHECK: error: '__builtin_loongarch_iocsrwr_d' needs target feature 64bit
41   __builtin_loongarch_iocsrwr_d(v_ul[0], ui);
42 
43 // CHECK: error: '__builtin_loongarch_asrtle_d' needs target feature 64bit
44   __builtin_loongarch_asrtle_d(v_l[0], v_l[1]);
45 // CHECK: error: '__builtin_loongarch_asrtgt_d' needs target feature 64bit
46   __builtin_loongarch_asrtgt_d(v_l[0], v_l[1]);
47 
48 // CHECK: error: '__builtin_loongarch_lddir_d' needs target feature 64bit
49   v_ul[4] = __builtin_loongarch_lddir_d(v_l[0], 1);
50 // CHECK: error: '__builtin_loongarch_ldpte_d' needs target feature 64bit
51   __builtin_loongarch_ldpte_d(v_l[0], 1);
52 }
53 #endif
54 
cacop_d(unsigned long int a)55 void cacop_d(unsigned long int a) {
56   __builtin_loongarch_cacop_w(-1, a, 1024); // expected-error {{argument value -1 is outside the valid range [0, 31]}}
57   __builtin_loongarch_cacop_w(32, a, 1024); // expected-error {{argument value 32 is outside the valid range [0, 31]}}
58   __builtin_loongarch_cacop_w(1, a, -4096); // expected-error {{argument value -4096 is outside the valid range [-2048, 2047]}}
59   __builtin_loongarch_cacop_w(1, a, 4096); // expected-error {{argument value 4096 is outside the valid range [-2048, 2047]}}
60 }
61 
dbar(int a)62 void dbar(int a) {
63   __builtin_loongarch_dbar(32768); // expected-error {{argument value 32768 is outside the valid range [0, 32767]}}
64   __builtin_loongarch_dbar(-1); // expected-error {{argument value 4294967295 is outside the valid range [0, 32767]}}
65   __builtin_loongarch_dbar(a); // expected-error {{argument to '__builtin_loongarch_dbar' must be a constant integer}}
66 }
67 
ibar(int a)68 void ibar(int a) {
69   __builtin_loongarch_ibar(32769); // expected-error {{argument value 32769 is outside the valid range [0, 32767]}}
70   __builtin_loongarch_ibar(-1); // expected-error {{argument value 4294967295 is outside the valid range [0, 32767]}}
71   __builtin_loongarch_ibar(a); // expected-error {{argument to '__builtin_loongarch_ibar' must be a constant integer}}
72 }
73 
loongarch_break(int a)74 void loongarch_break(int a) {
75   __builtin_loongarch_break(32769); // expected-error {{argument value 32769 is outside the valid range [0, 32767]}}
76   __builtin_loongarch_break(-1); // expected-error {{argument value 4294967295 is outside the valid range [0, 32767]}}
77   __builtin_loongarch_break(a); // expected-error {{argument to '__builtin_loongarch_break' must be a constant integer}}
78 }
79 
movfcsr2gr_out_of_lo_range(int a)80 int movfcsr2gr_out_of_lo_range(int a) {
81   int b =  __builtin_loongarch_movfcsr2gr(-1); // expected-error {{argument value 4294967295 is outside the valid range [0, 3]}}
82   int c = __builtin_loongarch_movfcsr2gr(32); // expected-error {{argument value 32 is outside the valid range [0, 3]}}
83   int d = __builtin_loongarch_movfcsr2gr(a); // expected-error {{argument to '__builtin_loongarch_movfcsr2gr' must be a constant integer}}
84   return 0;
85 }
86 
movgr2fcsr(int a,int b)87 void movgr2fcsr(int a, int b) {
88   __builtin_loongarch_movgr2fcsr(-1, b); // expected-error {{argument value 4294967295 is outside the valid range [0, 3]}}
89   __builtin_loongarch_movgr2fcsr(32, b); // expected-error {{argument value 32 is outside the valid range [0, 3]}}
90   __builtin_loongarch_movgr2fcsr(a, b); // expected-error {{argument to '__builtin_loongarch_movgr2fcsr' must be a constant integer}}
91 }
92 
syscall(int a)93 void syscall(int a) {
94   __builtin_loongarch_syscall(32769); // expected-error {{argument value 32769 is outside the valid range [0, 32767]}}
95   __builtin_loongarch_syscall(-1); // expected-error {{argument value 4294967295 is outside the valid range [0, 32767]}}
96   __builtin_loongarch_syscall(a); // expected-error {{argument to '__builtin_loongarch_syscall' must be a constant integer}}
97 }
98 
csrrd_w(int a)99 void csrrd_w(int a) {
100     __builtin_loongarch_csrrd_w(16384); // expected-error {{argument value 16384 is outside the valid range [0, 16383]}}
101     __builtin_loongarch_csrrd_w(-1); // expected-error {{argument value 4294967295 is outside the valid range [0, 16383]}}
102     __builtin_loongarch_csrrd_w(a); // expected-error {{argument to '__builtin_loongarch_csrrd_w' must be a constant integer}}
103 }
104 
csrwr_w(unsigned int a)105 void csrwr_w(unsigned int a) {
106     __builtin_loongarch_csrwr_w(a, 16384); // expected-error {{argument value 16384 is outside the valid range [0, 16383]}}
107     __builtin_loongarch_csrwr_w(a, -1); // expected-error {{argument value 4294967295 is outside the valid range [0, 16383]}}
108     __builtin_loongarch_csrwr_w(a, a); // expected-error {{argument to '__builtin_loongarch_csrwr_w' must be a constant integer}}
109 }
110 
csrxchg_w(unsigned int a,unsigned int b)111 void csrxchg_w(unsigned int a, unsigned int b) {
112     __builtin_loongarch_csrxchg_w(a, b, 16384); // expected-error {{argument value 16384 is outside the valid range [0, 16383]}}
113     __builtin_loongarch_csrxchg_w(a, b, -1); // expected-error {{argument value 4294967295 is outside the valid range [0, 16383]}}
114     __builtin_loongarch_csrxchg_w(a, b, b); // expected-error {{argument to '__builtin_loongarch_csrxchg_w' must be a constant integer}}
115 }
116 
rdtime_d()117 void rdtime_d() {
118   __rdtime_d(); // expected-error {{call to undeclared function '__rdtime_d'}}
119 }
120