public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/111431] New: a & (a == 0) is not optimized to 0
@ 2023-09-16  2:41 pinskia at gcc dot gnu.org
  2023-09-16  2:42 ` [Bug tree-optimization/111431] " pinskia at gcc dot gnu.org
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-09-16  2:41 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 111431
           Summary: a & (a == 0) is not optimized to 0
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Keywords: missed-optimization, xfail
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: pinskia at gcc dot gnu.org
  Target Milestone: ---

Take:
```
int
foo (int a)
{
  int b = !a;
  return (a & b);
}
```
The general rule is:
(a == CST) & a
transform into:
(CST & 1) ? (a == CST) : 0

So
(simplify
 (bit_and:c (convert@2 (eq @0 INTEGER_CST@1)) @0)
 (if ((wi::to_wide (@1) & 1) != 0)
  @2
  { build_zero_cst (type); }))

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

end of thread, other threads:[~2023-09-18 16:17 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-09-16  2:41 [Bug tree-optimization/111431] New: a & (a == 0) is not optimized to 0 pinskia at gcc dot gnu.org
2023-09-16  2:42 ` [Bug tree-optimization/111431] " pinskia at gcc dot gnu.org
2023-09-16  2:53 ` pinskia at gcc dot gnu.org
2023-09-16  3:27 ` pinskia at gcc dot gnu.org
2023-09-16  3:33 ` pinskia at gcc dot gnu.org
2023-09-16  3:39 ` pinskia at gcc dot gnu.org
2023-09-16 16:00 ` pinskia at gcc dot gnu.org
2023-09-18 16:13 ` cvs-commit at gcc dot gnu.org
2023-09-18 16:17 ` 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).