public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/115224] New: (a ^ 1) & (a ^ ~1) is not optimized to 0 at the gimplelevel
@ 2024-05-25  4:59 pinskia at gcc dot gnu.org
  2024-05-25  4:59 ` [Bug tree-optimization/115224] " pinskia at gcc dot gnu.org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-05-25  4:59 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 115224
           Summary: (a ^ 1) & (a ^ ~1) is not optimized to 0 at the
                    gimplelevel
           Product: gcc
           Version: 15.0
            Status: UNCONFIRMED
          Keywords: missed-optimization, TREE
          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 f1(int a)
{
  return (a ^ -2) & (a ^ 1);
}
int f2(int a, int b)
{
  b = 1;
  return (a ^ b) & (a ^ ~b);
}
int f3(int a, int b)
{
  b = 1;
  int t = a ^b;
  int t1 = a ^ ~b;
  return t & t1;
}
```

These all should be the same, GCC does optimize all to 0 but f1 and f3 is only
done on the RTL level.

This can be solved by improving bitwise_inverted_equal_p to see that `(a ^
CST)` and `(a ^ (~CST))` are inverse of each other.

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

end of thread, other threads:[~2024-05-30  3:56 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-05-25  4:59 [Bug tree-optimization/115224] New: (a ^ 1) & (a ^ ~1) is not optimized to 0 at the gimplelevel pinskia at gcc dot gnu.org
2024-05-25  4:59 ` [Bug tree-optimization/115224] " pinskia at gcc dot gnu.org
2024-05-27  1:05 ` pinskia at gcc dot gnu.org
2024-05-29 15:54 ` cvs-commit at gcc dot gnu.org
2024-05-29 16:00 ` pinskia at gcc dot gnu.org
2024-05-30  3:56 ` 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).