| 1 |
/* { dg-do compile } */ |
| 2 |
/* { dg-options "-O1 -fdump-tree-optimized-raw -Wno-psabi" } */ |
| 3 |
|
| 4 |
typedef int v4si __attribute__((vector_size(4 * sizeof(int)))); |
| 5 |
|
| 6 |
/* Generic */ |
| 7 |
#define BIT_OPERATIONS(result_type, operand_type, suffix) \ |
| 8 |
result_type foo_generic_1##suffix(operand_type a) { \ |
| 9 |
return (a - 1) & -a; \ |
| 10 |
} \ |
| 11 |
result_type foo_generic_2##suffix(operand_type a) { \ |
| 12 |
return (a - 1) | -a; \ |
| 13 |
} \ |
| 14 |
result_type foo_generic_3##suffix(operand_type a) { \ |
| 15 |
return (a - 1) ^ -a; \ |
| 16 |
} |
| 17 |
|
| 18 |
BIT_OPERATIONS(signed char, signed char, 11) |
| 19 |
BIT_OPERATIONS(unsigned char, unsigned char, 12) |
| 20 |
|
| 21 |
BIT_OPERATIONS(signed short, signed short, 21) |
| 22 |
BIT_OPERATIONS(unsigned short, unsigned short, 22) |
| 23 |
|
| 24 |
BIT_OPERATIONS(signed int, signed int, 31) |
| 25 |
BIT_OPERATIONS(unsigned int, unsigned int, 32) |
| 26 |
|
| 27 |
BIT_OPERATIONS(signed long, signed long, 41) |
| 28 |
BIT_OPERATIONS(unsigned long, unsigned long, 42) |
| 29 |
|
| 30 |
/* Gimple */ |
| 31 |
int |
| 32 |
foo_gimple_1(int a) |
| 33 |
{ |
| 34 |
int t1 = a - 1; |
| 35 |
int t2 = -a; |
| 36 |
int t3 = t1 & t2; |
| 37 |
return t3; |
| 38 |
} |
| 39 |
|
| 40 |
short |
| 41 |
foo_gimple_2(short a) |
| 42 |
{ |
| 43 |
short t1 = a - 1; |
| 44 |
short t2 = -a; |
| 45 |
short t3 = t1 | t2; |
| 46 |
return t3; |
| 47 |
} |
| 48 |
|
| 49 |
unsigned long |
| 50 |
foo_gimple_3(unsigned long a) |
| 51 |
{ |
| 52 |
unsigned long t1 = a - 1; |
| 53 |
unsigned long t2 = -a; |
| 54 |
unsigned long t3 = t1 ^ t2; |
| 55 |
return t3; |
| 56 |
} |
| 57 |
|
| 58 |
int |
| 59 |
foo_gimple_4(int a, unsigned char b) |
| 60 |
{ |
| 61 |
/* The return expression should simplify to b + 7. */ |
| 62 |
int t1 = b; |
| 63 |
t1 |= (a - 1) | -a; |
| 64 |
t1 |= b & (a >> 3); |
| 65 |
|
| 66 |
int t2 = b + 7; |
| 67 |
t2 &= ~((b - 1) & -b); |
| 68 |
t2 &= (a - 1) ^ -a; |
| 69 |
|
| 70 |
int t3 = t1 & t2; |
| 71 |
return t3; |
| 72 |
} |
| 73 |
|
| 74 |
/* Vectors */ |
| 75 |
v4si |
| 76 |
foo_vector_1(v4si a) |
| 77 |
{ |
| 78 |
return (a - (v4si) {1, 1, 1, 1}) & -a; |
| 79 |
} |
| 80 |
|
| 81 |
v4si |
| 82 |
foo_vector_2(v4si a) |
| 83 |
{ |
| 84 |
v4si t0 = (v4si) {1, 1, 1, 1}; |
| 85 |
v4si t1 = a - t0; |
| 86 |
v4si t2 = -a; |
| 87 |
v4si t3 = t1 | t2; |
| 88 |
return t3; |
| 89 |
} |
| 90 |
|
| 91 |
v4si |
| 92 |
foo_vector_3(v4si a) |
| 93 |
{ |
| 94 |
v4si t0 = (v4si) {1, 1, 1, 1}; |
| 95 |
v4si t1 = a - t0; |
| 96 |
v4si t2 = -a; |
| 97 |
v4si t3 = t1 ^ t2; |
| 98 |
return t3; |
| 99 |
} |
| 100 |
|
| 101 |
v4si |
| 102 |
foo_vector_4(v4si a) |
| 103 |
{ |
| 104 |
v4si t0 = (v4si) {1, 1, 1, 1}; |
| 105 |
v4si t1 = (a - t0) & -a; |
| 106 |
v4si t2 = (a - t0) | -a; |
| 107 |
v4si t3 = (a - t0) ^ -a; |
| 108 |
v4si t4 = t1 - t2 + t3; |
| 109 |
return t4; |
| 110 |
} |
| 111 |
|
| 112 |
/* { dg-final { scan-tree-dump-not "bit_and_expr, " "optimized" } } */ |
| 113 |
/* { dg-final { scan-tree-dump-not "bit_ior_expr, " "optimized" } } */ |
| 114 |
/* { dg-final { scan-tree-dump-not "bit_xor_expr, " "optimized" } } */ |
| 115 |
/* { dg-final { scan-tree-dump-not "negate_expr, " "optimized" } } */ |
| 116 |
/* { dg-final { scan-tree-dump-times "plus_expr, " 1 "optimized" } } */ |
| 117 |
|