1 /* Check if conditional vector instructions are simplified
2    into shift operations.  */
3 /* { dg-do compile { target { s390*-*-* } } } */
4 /* { dg-options "-O3 -march=z13 -mzarch" } */
5 
6 /* { dg-final { scan-assembler-times "vesraf\t%v.?,%v.?,31" 6 } } */
7 /* { dg-final { scan-assembler-times "vesrah\t%v.?,%v.?,15" 6 } } */
8 /* { dg-final { scan-assembler-times "vesrab\t%v.?,%v.?,7" 6 } } */
9 /* { dg-final { scan-assembler-not "vzero\t*" } } */
10 /* { dg-final { scan-assembler-times "vesrlf\t%v.?,%v.?,31" 4 } } */
11 /* { dg-final { scan-assembler-times "vesrlh\t%v.?,%v.?,15" 4 } } */
12 /* { dg-final { scan-assembler-times "vesrlb\t%v.?,%v.?,7" 4 } } */
13 
14 /* Make it expand to two vector operations.  */
15 #define ITER(X) (2 * (16 / sizeof (X[1])))
16 
17 void
vesraf_div(int * x)18 vesraf_div (int *x)
19 {
20   int i;
21   int *xx = __builtin_assume_aligned (x, 8);
22 
23   /* Should expand to (xx + (xx < 0 ? 1 : 0)) >> 1
24      which in turn should get simplified to (xx + (xx >> 31)) >> 1.  */
25   for (i = 0; i < ITER (xx); i++)
26     xx[i] = xx[i] / 2;
27 }
28 
29 void
vesrah_div(short * x)30 vesrah_div (short *x)
31 {
32   int i;
33   short *xx = __builtin_assume_aligned (x, 8);
34 
35   for (i = 0; i < ITER (xx); i++)
36     xx[i] = xx[i] / 2;
37 }
38 
39 
40 void
vesrab_div(signed char * x)41 vesrab_div (signed char *x)
42 {
43   int i;
44   signed char *xx = __builtin_assume_aligned (x, 8);
45 
46   for (i = 0; i < ITER (xx); i++)
47     xx[i] = xx[i] / 2;
48 }
49 
50 
51 
52 int
vesraf_lt(int * x)53 vesraf_lt (int *x)
54 {
55   int i;
56   int *xx = __builtin_assume_aligned (x, 8);
57 
58   for (i = 0; i < ITER (xx); i++)
59     xx[i] = xx[i] < 0 ? -1 : 0;
60 }
61 
62 int
vesrah_lt(short * x)63 vesrah_lt (short *x)
64 {
65   int i;
66   short *xx = __builtin_assume_aligned (x, 8);
67 
68   for (i = 0; i < ITER (xx); i++)
69     xx[i] = xx[i] < 0 ? -1 : 0;
70 }
71 
72 int
vesrab_lt(signed char * x)73 vesrab_lt (signed char *x)
74 {
75   int i;
76   signed char *xx = __builtin_assume_aligned (x, 8);
77 
78   for (i = 0; i < ITER (xx); i++)
79     xx[i] = xx[i] < 0 ? -1 : 0;
80 }
81 
82 
83 
84 int
vesraf_ge(int * x)85 vesraf_ge (int *x)
86 {
87   int i;
88   int *xx = __builtin_assume_aligned (x, 8);
89 
90   for (i = 0; i < ITER (xx); i++)
91     xx[i] = xx[i] >= 0 ? 0 : -1;
92 }
93 
94 int
vesrah_ge(short * x)95 vesrah_ge (short *x)
96 {
97   int i;
98   short *xx = __builtin_assume_aligned (x, 8);
99 
100   for (i = 0; i < ITER (xx); i++)
101     xx[i] = xx[i] >= 0 ? 0 : -1;
102 }
103 
104 int
vesrab_ge(signed char * x)105 vesrab_ge (signed char *x)
106 {
107   int i;
108   signed char *xx = __builtin_assume_aligned (x, 8);
109 
110   for (i = 0; i < ITER (xx); i++)
111     xx[i] = xx[i] >= 0 ? 0 : -1;
112 }
113 
114 
115 
116 int
vesrlf_lt(int * x)117 vesrlf_lt (int *x)
118 {
119   int i;
120   int *xx = __builtin_assume_aligned (x, 8);
121 
122   for (i = 0; i < ITER (xx); i++)
123     xx[i] = xx[i] < 0 ? 1 : 0;
124 }
125 
126 int
vesrlh_lt(short * x)127 vesrlh_lt (short *x)
128 {
129   int i;
130   short *xx = __builtin_assume_aligned (x, 8);
131 
132   for (i = 0; i < ITER (xx); i++)
133     xx[i] = xx[i] < 0 ? 1 : 0;
134 }
135 
136 int
vesrlb_lt(signed char * x)137 vesrlb_lt (signed char *x)
138 {
139   int i;
140   signed char *xx = __builtin_assume_aligned (x, 8);
141 
142   for (i = 0; i < ITER (xx); i++)
143     xx[i] = xx[i] < 0 ? 1 : 0;
144 }
145 
146 
147 
148 int
vesrlf_ge(int * x)149 vesrlf_ge (int *x)
150 {
151   int i;
152   int *xx = __builtin_assume_aligned (x, 8);
153 
154   for (i = 0; i < ITER (xx); i++)
155     xx[i] = xx[i] >= 0 ? 0 : 1;
156 }
157 
158 int
vesrlh_ge(short * x)159 vesrlh_ge (short *x)
160 {
161   int i;
162   short *xx = __builtin_assume_aligned (x, 8);
163 
164   for (i = 0; i < ITER (xx); i++)
165     xx[i] = xx[i] >= 0 ? 0 : 1;
166 }
167 
168 int
vesrlb_ge(signed char * x)169 vesrlb_ge (signed char *x)
170 {
171   int i;
172   signed char *xx = __builtin_assume_aligned (x, 8);
173 
174   for (i = 0; i < ITER (xx); i++)
175     xx[i] = xx[i] >= 0 ? 0 : 1;
176 }
177