[Bug middle-end/113130] `abs(a) == b` could be expanded as `(a == b || a == -b)`

2023-12-28 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113130

--- Comment #2 from Andrew Pinski  ---
Oh right but the following testcase it should be valid to do and not worry
about INT_MIN either:
```
int f(int a, unsigned short c)
{
 // c = 1;
  int b = a > 0 ? a : -a;
  return b == c;
}

int f1(int a, unsigned short c)
{
 // c = 1;
  return a == -c || a == c;
}
```

[Bug middle-end/113130] `abs(a) == b` could be expanded as `(a == b || a == -b)`

2023-12-28 Thread jsm28 at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113130

--- Comment #1 from Joseph S. Myers  ---
Note that the first example (and the suggested one with ABS_EXPR) has undefined
behavior for a == INT_MIN, while the second has undefined behavior for c ==
INT_MIN (and is also not equivalent to the first for negative c).