public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/107888] New: [12/13 Regression] Missed min/max transformation in phiopt due to VRP
@ 2022-11-27 19:28 pinskia at gcc dot gnu.org
  2022-11-28  7:57 ` [Bug tree-optimization/107888] " rguenth at gcc dot gnu.org
                   ` (10 more replies)
  0 siblings, 11 replies; 12+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-11-27 19:28 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 107888
           Summary: [12/13 Regression] Missed min/max transformation in
                    phiopt due to VRP
           Product: gcc
           Version: 13.0
            Status: UNCONFIRMED
          Keywords: missed-optimization
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: pinskia at gcc dot gnu.org
  Target Milestone: ---

Take:
```
#define bool _Bool
int maxbool(bool ab, bool bb)
{
  int a = ab;
  int b = bb;
  int c;
  if (a > b)
    c = a;
  else
    c = b;
  return c;
}
```

We miss that c is max of a and b because VRP decides to change the phi.
We get out of VRP:
```
  if (a_3 > b_5)
    goto <bb 4>; [INV]
  else
    goto <bb 3>; [INV]

  <bb 3> :

  <bb 4> :
  # c_1 = PHI <1(2), b_5(3)>
```

What VRP is doing is correct just is harder to optimize to a max (and then a |
).

In the above case we could optimize `bool0 ? 1 : bool1` to `bool0 | bool1` But
then we end up with PR 107887 too.

You can also end up with the above issue where you know the only overlap
between the two arguments is [5,6] :
```
int max(int ab, int bb)
{
  if (ab < 5)  __builtin_trap();
  if (bb > 6)  __builtin_trap();
  int a = ab;
  int b = bb;
  int c;
  if (a >= b)
    c = a;
  else
    c = b;
  return c;
}
```
Which we cannot optimize based on zero/one any more. (note this version of max
has been an issue since at least GCC 4.1, I suspect since VRP was added).

^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2023-05-16  3:50 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-27 19:28 [Bug tree-optimization/107888] New: [12/13 Regression] Missed min/max transformation in phiopt due to VRP pinskia at gcc dot gnu.org
2022-11-28  7:57 ` [Bug tree-optimization/107888] " rguenth at gcc dot gnu.org
2022-11-28 17:26 ` pinskia at gcc dot gnu.org
2022-12-21 13:35 ` rguenth at gcc dot gnu.org
2023-05-06  0:38 ` [Bug tree-optimization/107888] [12/13/14 " pinskia at gcc dot gnu.org
2023-05-08  5:35 ` pinskia at gcc dot gnu.org
2023-05-08 12:26 ` rguenth at gcc dot gnu.org
2023-05-09 10:14 ` pinskia at gcc dot gnu.org
2023-05-09 10:19 ` pinskia at gcc dot gnu.org
2023-05-10 18:11 ` pinskia at gcc dot gnu.org
2023-05-10 19:10 ` pinskia at gcc dot gnu.org
2023-05-16  3:50 ` cvs-commit at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).