xref: /llvm-project/clang/test/CodeGen/SystemZ/builtins-systemz-vector2.c (revision a65ccc1b9fe740c9f65d9cf2b627de50278aad56)
1 // REQUIRES: systemz-registered-target
2 // RUN: %clang_cc1 -target-cpu z14 -triple s390x-ibm-linux -flax-vector-conversions=none \
3 // RUN: -Wall -Wno-unused -Werror -emit-llvm %s -o - | FileCheck %s
4 
5 typedef __attribute__((vector_size(16))) signed char vec_schar;
6 typedef __attribute__((vector_size(16))) signed short vec_sshort;
7 typedef __attribute__((vector_size(16))) signed int vec_sint;
8 typedef __attribute__((vector_size(16))) signed long long vec_slong;
9 typedef __attribute__((vector_size(16))) unsigned char vec_uchar;
10 typedef __attribute__((vector_size(16))) unsigned short vec_ushort;
11 typedef __attribute__((vector_size(16))) unsigned int vec_uint;
12 typedef __attribute__((vector_size(16))) unsigned long long vec_ulong;
13 typedef __attribute__((vector_size(16))) double vec_double;
14 typedef __attribute__((vector_size(16))) float vec_float;
15 
16 volatile vec_schar vsc;
17 volatile vec_sshort vss;
18 volatile vec_sint vsi;
19 volatile vec_slong vsl;
20 volatile vec_uchar vuc;
21 volatile vec_ushort vus;
22 volatile vec_uint vui;
23 volatile vec_ulong vul;
24 volatile vec_double vd;
25 volatile vec_float vf;
26 volatile unsigned __int128 ui128;
27 
28 volatile unsigned int len;
29 const void * volatile cptr;
30 void * volatile ptr;
31 int cc;
32 
test_core(void)33 void test_core(void) {
34   vul = __builtin_s390_vbperm(vuc, vuc);
35   // CHECK: call <2 x i64> @llvm.s390.vbperm(<16 x i8> %{{.*}}, <16 x i8> %{{.*}})
36 
37   vsc = __builtin_s390_vlrlr(len, cptr);
38   // CHECK: call <16 x i8> @llvm.s390.vlrl(i32 %{{.*}}, ptr %{{.*}})
39 
40   __builtin_s390_vstrlr(vsc, len, ptr);
41   // CHECK: call void @llvm.s390.vstrl(<16 x i8> %{{.*}}, i32 %{{.*}}, ptr %{{.*}})
42 }
43 
test_integer(void)44 void test_integer(void) {
45   ui128 = __builtin_s390_vmslg(vul, vul, ui128, 0);
46   // CHECK: call i128 @llvm.s390.vmslg(<2 x i64> %{{.*}}, <2 x i64> %{{.*}}, i128 %{{.*}}, i32 0)
47   ui128 = __builtin_s390_vmslg(vul, vul, ui128, 15);
48   // CHECK: call i128 @llvm.s390.vmslg(<2 x i64> %{{.*}}, <2 x i64> %{{.*}}, i128 %{{.*}}, i32 15)
49 }
50 
test_float(void)51 void test_float(void) {
52   vd = __builtin_s390_vfmaxdb(vd, vd, 4);
53   // CHECK: call <2 x double> @llvm.maxnum.v2f64(<2 x double> %{{.*}}, <2 x double> %{{.*}})
54   vd = __builtin_s390_vfmaxdb(vd, vd, 0);
55   // CHECK: call <2 x double> @llvm.s390.vfmaxdb(<2 x double> %{{.*}}, <2 x double> %{{.*}}, i32 0)
56   vd = __builtin_s390_vfmaxdb(vd, vd, 15);
57   // CHECK: call <2 x double> @llvm.s390.vfmaxdb(<2 x double> %{{.*}}, <2 x double> %{{.*}}, i32 15)
58 
59   vd = __builtin_s390_vfmindb(vd, vd, 4);
60   // CHECK: call <2 x double> @llvm.minnum.v2f64(<2 x double> %{{.*}}, <2 x double> %{{.*}})
61   vd = __builtin_s390_vfmindb(vd, vd, 0);
62   // CHECK: call <2 x double> @llvm.s390.vfmindb(<2 x double> %{{.*}}, <2 x double> %{{.*}}, i32 0)
63   vd = __builtin_s390_vfmindb(vd, vd, 15);
64   // CHECK: call <2 x double> @llvm.s390.vfmindb(<2 x double> %{{.*}}, <2 x double> %{{.*}}, i32 15)
65 
66   vd = __builtin_s390_vfnmadb(vd, vd, vd);
67   // CHECK: [[RES:%[^ ]+]] = call <2 x double> @llvm.fma.v2f64(<2 x double> %{{.*}}, <2 x double> %{{.*}}, <2 x double> %{{.*}})
68   // CHECK: fneg <2 x double> [[RES]]
69   vd = __builtin_s390_vfnmsdb(vd, vd, vd);
70   // CHECK: [[NEG:%[^ ]+]] = fneg <2 x double> %{{.*}}
71   // CHECK: [[RES:%[^ ]+]] = call <2 x double> @llvm.fma.v2f64(<2 x double> %{{.*}}, <2 x double> %{{.*}}, <2 x double> [[NEG]])
72   // CHECK: fneg <2 x double> [[RES]]
73 
74   vsi = __builtin_s390_vfcesbs(vf, vf, &cc);
75   // CHECK: call { <4 x i32>, i32 } @llvm.s390.vfcesbs(<4 x float> %{{.*}}, <4 x float> %{{.*}})
76   vsi = __builtin_s390_vfchsbs(vf, vf, &cc);
77   // CHECK: call { <4 x i32>, i32 } @llvm.s390.vfchsbs(<4 x float> %{{.*}}, <4 x float> %{{.*}})
78   vsi = __builtin_s390_vfchesbs(vf, vf, &cc);
79   // CHECK: call { <4 x i32>, i32 } @llvm.s390.vfchesbs(<4 x float> %{{.*}}, <4 x float> %{{.*}})
80 
81   vsi = __builtin_s390_vftcisb(vf, 0, &cc);
82   // CHECK: call { <4 x i32>, i32 } @llvm.s390.vftcisb(<4 x float> %{{.*}}, i32 0)
83   vsi = __builtin_s390_vftcisb(vf, 4095, &cc);
84   // CHECK: call { <4 x i32>, i32 } @llvm.s390.vftcisb(<4 x float> %{{.*}}, i32 4095)
85 
86   vf = __builtin_s390_vfmaxsb(vf, vf, 4);
87   // CHECK: call <4 x float> @llvm.maxnum.v4f32(<4 x float> %{{.*}}, <4 x float> %{{.*}})
88   vf = __builtin_s390_vfmaxsb(vf, vf, 0);
89   // CHECK: call <4 x float> @llvm.s390.vfmaxsb(<4 x float> %{{.*}}, <4 x float> %{{.*}}, i32 0)
90   vf = __builtin_s390_vfmaxsb(vf, vf, 15);
91   // CHECK: call <4 x float> @llvm.s390.vfmaxsb(<4 x float> %{{.*}}, <4 x float> %{{.*}}, i32 15)
92 
93   vf = __builtin_s390_vfminsb(vf, vf, 4);
94   // CHECK: call <4 x float> @llvm.minnum.v4f32(<4 x float> %{{.*}}, <4 x float> %{{.*}})
95   vf = __builtin_s390_vfminsb(vf, vf, 0);
96   // CHECK: call <4 x float> @llvm.s390.vfminsb(<4 x float> %{{.*}}, <4 x float> %{{.*}}, i32 0)
97   vf = __builtin_s390_vfminsb(vf, vf, 15);
98   // CHECK: call <4 x float> @llvm.s390.vfminsb(<4 x float> %{{.*}}, <4 x float> %{{.*}}, i32 15)
99 
100   vf = __builtin_s390_vfsqsb(vf);
101   // CHECK: call <4 x float> @llvm.sqrt.v4f32(<4 x float> %{{.*}})
102 
103   vf = __builtin_s390_vfmasb(vf, vf, vf);
104   // CHECK: call <4 x float> @llvm.fma.v4f32(<4 x float> %{{.*}}, <4 x float> %{{.*}}, <4 x float> %{{.*}})
105   vf = __builtin_s390_vfmssb(vf, vf, vf);
106   // CHECK: [[NEG:%[^ ]+]] = fneg <4 x float> %{{.*}}
107   // CHECK: call <4 x float> @llvm.fma.v4f32(<4 x float> %{{.*}}, <4 x float> %{{.*}}, <4 x float> [[NEG]])
108   vf = __builtin_s390_vfnmasb(vf, vf, vf);
109   // CHECK: [[RES:%[^ ]+]] = call <4 x float> @llvm.fma.v4f32(<4 x float> %{{.*}}, <4 x float> %{{.*}}, <4 x float> %{{.*}})
110   // CHECK: fneg <4 x float> [[RES]]
111   vf = __builtin_s390_vfnmssb(vf, vf, vf);
112   // CHECK: [[NEG:%[^ ]+]] = fneg <4 x float> %{{.*}}
113   // CHECK: [[RES:%[^ ]+]] = call <4 x float> @llvm.fma.v4f32(<4 x float> %{{.*}}, <4 x float> %{{.*}}, <4 x float> [[NEG]])
114   // CHECK: fneg <4 x float> [[RES]]
115 
116   vf = __builtin_s390_vflpsb(vf);
117   // CHECK: call <4 x float> @llvm.fabs.v4f32(<4 x float> %{{.*}})
118   vf = __builtin_s390_vflnsb(vf);
119   // CHECK: [[ABS:%[^ ]+]] = call <4 x float> @llvm.fabs.v4f32(<4 x float> %{{.*}})
120   // CHECK: fneg <4 x float> [[ABS]]
121 
122   vf = __builtin_s390_vfisb(vf, 0, 0);
123   // CHECK: call <4 x float> @llvm.rint.v4f32(<4 x float> %{{.*}})
124   vf = __builtin_s390_vfisb(vf, 4, 0);
125   // CHECK: call <4 x float> @llvm.nearbyint.v4f32(<4 x float> %{{.*}})
126   vf = __builtin_s390_vfisb(vf, 4, 1);
127   // CHECK: call <4 x float> @llvm.round.v4f32(<4 x float> %{{.*}})
128   vf = __builtin_s390_vfisb(vf, 4, 5);
129   // CHECK: call <4 x float> @llvm.trunc.v4f32(<4 x float> %{{.*}})
130   vf = __builtin_s390_vfisb(vf, 4, 6);
131   // CHECK: call <4 x float> @llvm.ceil.v4f32(<4 x float> %{{.*}})
132   vf = __builtin_s390_vfisb(vf, 4, 7);
133   // CHECK: call <4 x float> @llvm.floor.v4f32(<4 x float> %{{.*}})
134   vf = __builtin_s390_vfisb(vf, 4, 4);
135   // CHECK: call <4 x float> @llvm.s390.vfisb(<4 x float> %{{.*}}, i32 4, i32 4)
136 }
137 
138