https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113130

            Bug ID: 113130
           Summary: `abs(a) == b` could be expanded as `(a == b || a ==
                    -b)`
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Keywords: missed-optimization
          Severity: enhancement
          Priority: P3
         Component: middle-end
          Assignee: unassigned at gcc dot gnu.org
          Reporter: pinskia at gcc dot gnu.org
  Target Milestone: ---

Take:
```
int f(int a, int c)
{
 // c = 1;
  int b = a > 0 ? a : -a;
  return b == c;
}

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

These 2 functions should produce the same assembly code.
This is especially true for when c is a 1 or 2.

Note for gimple, it might make sense to `ABS_EXPR <a> == c` as the conconal
form as it is only 2 gimple statements rather than 3.

Note `<`, `>`, `>=`, `<=`, and `!=` should be handled too.

Reply via email to