| 1 |
/* PR target/98737 */ |
| 2 |
/* { dg-do compile { target i?86-*-* x86_64-*-* powerpc*-*-* aarch64*-*-* } } */ |
| 3 |
/* { dg-options "-O2 -fdump-tree-optimized -fcompare-debug" } */ |
| 4 |
/* { dg-additional-options "-march=i686" { target ia32 } } */ |
| 5 |
/* Note the choice between __atomic_fetch_and_* and __atomic_and_*_fetch |
| 6 |
if the result is not used does not matter. so check if make sure we don't |
| 7 |
have __atomic_fetch_ with an assignment */ |
| 8 |
/* { dg-final { scan-tree-dump-not "= __atomic_fetch_" "optimized" } } */ |
| 9 |
/* { dg-final { scan-tree-dump-not "= __sync_fetch_and_" "optimized" } } */ |
| 10 |
|
| 11 |
typedef signed char schar; |
| 12 |
typedef unsigned long ulong; |
| 13 |
typedef unsigned int uint; |
| 14 |
typedef unsigned short ushort; |
| 15 |
typedef unsigned char uchar; |
| 16 |
long vlong; |
| 17 |
int vint; |
| 18 |
short vshort; |
| 19 |
schar vschar; |
| 20 |
ulong vulong; |
| 21 |
uint vuint; |
| 22 |
ushort vushort; |
| 23 |
uchar vuchar; |
| 24 |
#define A(n, t, ut, f, o, ...) \ |
| 25 |
t fn##n (t x) \ |
| 26 |
{ \ |
| 27 |
ut z = f (&v##t, x, ##__VA_ARGS__); \ |
| 28 |
t w = (t) z; \ |
| 29 |
return w o x; \ |
| 30 |
} |
| 31 |
#define B(n, f, o, ...) \ |
| 32 |
A(n##0, long, ulong, f, o, ##__VA_ARGS__) \ |
| 33 |
A(n##1, int, uint, f, o, ##__VA_ARGS__) \ |
| 34 |
A(n##2, short, ushort, f, o, ##__VA_ARGS__) \ |
| 35 |
A(n##3, schar, uchar, f, o, ##__VA_ARGS__) \ |
| 36 |
A(n##4, ulong, ulong, f, o, ##__VA_ARGS__) \ |
| 37 |
A(n##5, uint, uint, f, o, ##__VA_ARGS__) \ |
| 38 |
A(n##6, ushort, ushort, f, o, ##__VA_ARGS__) \ |
| 39 |
A(n##7, uchar, uchar, f, o, ##__VA_ARGS__) |
| 40 |
|
| 41 |
B(00, __atomic_fetch_add, +, __ATOMIC_RELAXED) |
| 42 |
B(01, __atomic_fetch_sub, -, __ATOMIC_RELAXED) |
| 43 |
B(02, __atomic_fetch_and, &, __ATOMIC_RELAXED) |
| 44 |
B(03, __atomic_fetch_xor, ^, __ATOMIC_RELAXED) |
| 45 |
B(04, __atomic_fetch_or, |, __ATOMIC_RELAXED) |
| 46 |
B(05, __sync_fetch_and_add, +) |
| 47 |
B(06, __sync_fetch_and_sub, -) |
| 48 |
B(07, __sync_fetch_and_and, &) |
| 49 |
B(08, __sync_fetch_and_xor, ^) |
| 50 |
B(09, __sync_fetch_and_or, |) |
| 51 |
|
| 52 |
#undef A |
| 53 |
#define A(n, t, ut, f, o, ...) \ |
| 54 |
t fn##n (void) \ |
| 55 |
{ \ |
| 56 |
ut z = f (&v##t, 42, ##__VA_ARGS__); \ |
| 57 |
t w = (t) z; \ |
| 58 |
return w o 42; \ |
| 59 |
} |
| 60 |
|
| 61 |
B(10, __atomic_fetch_add, +, __ATOMIC_RELAXED) |
| 62 |
B(11, __atomic_fetch_sub, -, __ATOMIC_RELAXED) |
| 63 |
B(12, __atomic_fetch_and, &, __ATOMIC_RELAXED) |
| 64 |
B(13, __atomic_fetch_xor, ^, __ATOMIC_RELAXED) |
| 65 |
B(14, __atomic_fetch_or, |, __ATOMIC_RELAXED) |
| 66 |
B(15, __sync_fetch_and_add, +) |
| 67 |
B(16, __sync_fetch_and_sub, -) |
| 68 |
B(17, __sync_fetch_and_and, &) |
| 69 |
B(18, __sync_fetch_and_xor, ^) |
| 70 |
B(19, __sync_fetch_and_or, |) |
| 71 |
|
| 72 |
#undef A |
| 73 |
#define A(n, t, ut, f, o, ...) \ |
| 74 |
t fn##n (t x) \ |
| 75 |
{ \ |
| 76 |
ut z = f (&v##t, x, ##__VA_ARGS__); \ |
| 77 |
t w = (t) z; \ |
| 78 |
t v = w o x; \ |
| 79 |
return v == 0; \ |
| 80 |
} |
| 81 |
|
| 82 |
B(20, __atomic_fetch_add, +, __ATOMIC_RELAXED) |
| 83 |
B(21, __atomic_fetch_sub, -, __ATOMIC_RELAXED) |
| 84 |
B(22, __atomic_fetch_and, &, __ATOMIC_RELAXED) |
| 85 |
B(23, __atomic_fetch_xor, ^, __ATOMIC_RELAXED) |
| 86 |
B(24, __atomic_fetch_or, |, __ATOMIC_RELAXED) |
| 87 |
B(25, __sync_fetch_and_add, +) |
| 88 |
B(26, __sync_fetch_and_sub, -) |
| 89 |
B(27, __sync_fetch_and_and, &) |
| 90 |
B(28, __sync_fetch_and_xor, ^) |
| 91 |
B(29, __sync_fetch_and_or, |) |
| 92 |
|
| 93 |
#undef A |
| 94 |
#define A(n, t, ut, f, o, ...) \ |
| 95 |
t fn##n (void) \ |
| 96 |
{ \ |
| 97 |
ut z = f (&v##t, 42, ##__VA_ARGS__); \ |
| 98 |
t w = (t) z; \ |
| 99 |
t v = w o 42; \ |
| 100 |
return v != 0; \ |
| 101 |
} |
| 102 |
|
| 103 |
B(30, __atomic_fetch_add, +, __ATOMIC_RELAXED) |
| 104 |
B(31, __atomic_fetch_sub, -, __ATOMIC_RELAXED) |
| 105 |
B(32, __atomic_fetch_and, &, __ATOMIC_RELAXED) |
| 106 |
B(33, __atomic_fetch_xor, ^, __ATOMIC_RELAXED) |
| 107 |
B(34, __atomic_fetch_or, |, __ATOMIC_RELAXED) |
| 108 |
B(35, __sync_fetch_and_add, +) |
| 109 |
B(36, __sync_fetch_and_sub, -) |
| 110 |
B(37, __sync_fetch_and_and, &) |
| 111 |
B(38, __sync_fetch_and_xor, ^) |
| 112 |
B(39, __sync_fetch_and_or, |) |
| 113 |
|
| 114 |
#undef A |
| 115 |
#define A(n, t, ut, f, o, ...) \ |
| 116 |
t fn##n (t x) \ |
| 117 |
{ \ |
| 118 |
return (t) (((t) f (&v##t, x, ##__VA_ARGS__)) \ |
| 119 |
o x) != 0; \ |
| 120 |
} |
| 121 |
|
| 122 |
B(40, __atomic_fetch_add, +, __ATOMIC_RELAXED) |
| 123 |
B(41, __atomic_fetch_sub, -, __ATOMIC_RELAXED) |
| 124 |
B(42, __atomic_fetch_and, &, __ATOMIC_RELAXED) |
| 125 |
B(43, __atomic_fetch_xor, ^, __ATOMIC_RELAXED) |
| 126 |
B(44, __atomic_fetch_or, |, __ATOMIC_RELAXED) |
| 127 |
B(45, __sync_fetch_and_add, +) |
| 128 |
B(46, __sync_fetch_and_sub, -) |
| 129 |
B(47, __sync_fetch_and_and, &) |
| 130 |
B(48, __sync_fetch_and_xor, ^) |
| 131 |
B(49, __sync_fetch_and_or, |) |
| 132 |
|
| 133 |
#undef A |
| 134 |
#define A(n, t, ut, f, o, ...) \ |
| 135 |
t fn##n (void) \ |
| 136 |
{ \ |
| 137 |
return (t) (((t) f (&v##t, 42, ##__VA_ARGS__))\ |
| 138 |
o 42) == 0; \ |
| 139 |
} |
| 140 |
|
| 141 |
B(50, __atomic_fetch_add, +, __ATOMIC_RELAXED) |
| 142 |
B(51, __atomic_fetch_sub, -, __ATOMIC_RELAXED) |
| 143 |
B(52, __atomic_fetch_and, &, __ATOMIC_RELAXED) |
| 144 |
B(53, __atomic_fetch_xor, ^, __ATOMIC_RELAXED) |
| 145 |
/* (whatever | 42) == 0 is 0, so we can't test this. */ |
| 146 |
/* B(54, __atomic_fetch_or, |, __ATOMIC_RELAXED) */ |
| 147 |
B(55, __sync_fetch_and_add, +) |
| 148 |
B(56, __sync_fetch_and_sub, -) |
| 149 |
B(57, __sync_fetch_and_and, &) |
| 150 |
B(58, __sync_fetch_and_xor, ^) |
| 151 |
/* B(59, __sync_fetch_and_or, |) */ |