| 1 |
// { dg-do run } |
| 2 |
// PR tree-optimization/116120 |
| 3 |
|
| 4 |
// The optimization for `(a ? x : y) == (b ? x : y)` |
| 5 |
// missed that x and y could be the same value |
| 6 |
// This can't be done if x and y support NaNs since `NaN == NaN` is always false |
| 7 |
// And dominates the whole expression rather than supporting it. |
| 8 |
|
| 9 |
typedef int v1si __attribute((__vector_size__(1 * sizeof(int)))); |
| 10 |
typedef float v1sf __attribute((__vector_size__(1 * sizeof(float)))); |
| 11 |
|
| 12 |
v1si f1(v1si a, v1si b, v1si c, v1si d, v1sf e, v1sf f) __attribute__((noinline)); |
| 13 |
v1si f1(v1si a, v1si b, v1si c, v1si d, v1sf e, v1sf f) { |
| 14 |
v1sf X = a == b ? e : f; |
| 15 |
v1sf Y = c == d ? f : e; |
| 16 |
return (X == Y); // ~(X == Y ? -1 : 0) (x ^ Y) |
| 17 |
} |
| 18 |
|
| 19 |
int f2(int a, int b, int c, int d, float e, float f) __attribute__((noinline)); |
| 20 |
int f2(int a, int b, int c, int d, float e, float f) { |
| 21 |
float X = a == b ? e : f; |
| 22 |
float Y = c == d ? f : e; |
| 23 |
return (X == Y) ? -1 : 0; // ~(X == Y ? -1 : 0) (x ^ Y) |
| 24 |
} |
| 25 |
|
| 26 |
int main() |
| 27 |
{ |
| 28 |
v1si a = {0}; |
| 29 |
v1si b = {0}; // a == b, true |
| 30 |
v1si c = {2}; |
| 31 |
v1si d = {3}; // c == b, false |
| 32 |
v1sf e; |
| 33 |
v1sf f; |
| 34 |
|
| 35 |
/* Test signed 0s. */ |
| 36 |
e = (v1sf){0.0}; |
| 37 |
f = -e; |
| 38 |
v1si r = f1(a,b,c,d,e, f); |
| 39 |
int r1 = f2(a[0], b[0], c[0], d[0], e[0], f[0]); |
| 40 |
if (r[0] != r1) |
| 41 |
__builtin_abort(); |
| 42 |
|
| 43 |
/* Test NaNs */ |
| 44 |
#if __FLT_HAS_QUIET_NAN__ |
| 45 |
e = (v1sf){__builtin_nanf("")}; |
| 46 |
f = e; |
| 47 |
/* Test NaNs */ |
| 48 |
r = f1(a,b,c,d,e, f); |
| 49 |
r1 = f2(a[0], b[0], c[0], d[0], e[0], f[0]); |
| 50 |
if (r[0] != r1) |
| 51 |
__builtin_abort(); |
| 52 |
#endif |
| 53 |
} |