public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/112271] New: Some `(a == CST) ? a OP b : CST` is not done in match
@ 2023-10-28 21:33 pinskia at gcc dot gnu.org
  2023-10-28 21:34 ` [Bug tree-optimization/112271] " pinskia at gcc dot gnu.org
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-10-28 21:33 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 112271
           Summary: Some `(a == CST) ? a OP b : CST` is not done in match
           Product: gcc
           Version: 14.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:
```
/* 
a == -1 ? a | b : -1 -> -1
*/
int f_or(int a, int b)
{
  int c = b|a;
  int d;
  if (a == -1) d = c; else d = -1;
  return d;
}
/* 
a == 0 ? a * b : 0 -> 0
*/
int f_mult(int a, int b)
{
  int c = b*a;
  int d;
  if (a == 0) d = c; else d = 0;
  return d;
}
/* 
a == 0 ? a & b : 0 -> 0
*/
int f_and(int a, int b)
{
  int c = b&a;
  int d;
  if (a == 0) d = c; else d = 0;
  return d;
}

```
These all should be done in match. They are currently handled by the ranger
code (either via dom2 or evrp). Matching it in match would allow it to be
caught earlier for -O1 and might allow for some other cases later on.

Recording this here for now so I don't forget to add them ...

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

* [Bug tree-optimization/112271] Some `(a == CST) ? a OP b : CST` is not done in match
  2023-10-28 21:33 [Bug tree-optimization/112271] New: Some `(a == CST) ? a OP b : CST` is not done in match pinskia at gcc dot gnu.org
@ 2023-10-28 21:34 ` pinskia at gcc dot gnu.org
  2023-10-28 21:45 ` pinskia at gcc dot gnu.org
  2023-10-28 21:49 ` pinskia at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-10-28 21:34 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|                            |2023-10-28
             Status|UNCONFIRMED                 |ASSIGNED
           Severity|normal                      |enhancement
     Ever confirmed|0                           |1
           Assignee|unassigned at gcc dot gnu.org      |pinskia at gcc dot gnu.org

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

* [Bug tree-optimization/112271] Some `(a == CST) ? a OP b : CST` is not done in match
  2023-10-28 21:33 [Bug tree-optimization/112271] New: Some `(a == CST) ? a OP b : CST` is not done in match pinskia at gcc dot gnu.org
  2023-10-28 21:34 ` [Bug tree-optimization/112271] " pinskia at gcc dot gnu.org
@ 2023-10-28 21:45 ` pinskia at gcc dot gnu.org
  2023-10-28 21:49 ` pinskia at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-10-28 21:45 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Actually this is basically moving absorbing_element_p to match.

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

* [Bug tree-optimization/112271] Some `(a == CST) ? a OP b : CST` is not done in match
  2023-10-28 21:33 [Bug tree-optimization/112271] New: Some `(a == CST) ? a OP b : CST` is not done in match pinskia at gcc dot gnu.org
  2023-10-28 21:34 ` [Bug tree-optimization/112271] " pinskia at gcc dot gnu.org
  2023-10-28 21:45 ` pinskia at gcc dot gnu.org
@ 2023-10-28 21:49 ` pinskia at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-10-28 21:49 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
the others:
```
int f_lshift(int a, int b)
{
  int c = b>>a;
  int d;
  if (b == 0) d = c; else d = 0;
  return d;
}
int f_div(int a, int b)
{
  a = 2; // Just needs to be non-negative
  int c = b/a;
  int d;
  if (b == 0) d = c; else d = 0;
  return d;
}
```

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

end of thread, other threads:[~2023-10-28 21:49 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-10-28 21:33 [Bug tree-optimization/112271] New: Some `(a == CST) ? a OP b : CST` is not done in match pinskia at gcc dot gnu.org
2023-10-28 21:34 ` [Bug tree-optimization/112271] " pinskia at gcc dot gnu.org
2023-10-28 21:45 ` pinskia at gcc dot gnu.org
2023-10-28 21:49 ` pinskia 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).