public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/101676] New: ^ not changed to | if the non-zero don't overlap
@ 2021-07-29 13:11 pinskia at gcc dot gnu.org
  2021-07-30  6:12 ` [Bug tree-optimization/101676] " rguenth at gcc dot gnu.org
  2023-08-28 20:21 ` pinskia at gcc dot gnu.org
  0 siblings, 2 replies; 3+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-07-29 13:11 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 101676
           Summary: ^ not changed to | if the non-zero don't overlap
           Product: gcc
           Version: 12.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:
int f(int a, int b)
{
    if (a & ~8) __builtin_unreachable();
    if (b & 8) __builtin_unreachable();
    return a ^ b;
}
----- CUT -----
The xor here can converted into ior as a and b non-zero bits don't overlap.
Note clang does this optimization.

But clang does not do the following (which we should be able to do too).
Take:
int f(int a, int b)
{
    if (a & 8) __builtin_unreachable();
    if (b & ~1) __builtin_unreachable();
    return (a) ^ (b<<3);
}
This should be able to turn into a bit insert of b into a.
Right now both GCC (and really clang) turn this on aarch64:
        eor     w0, w0, w1, lsl 3 ;;;clang uses orr

Both can handle the following though:
int f(int a, int b)
{
 //   if (a & 8) __builtin_unreachable();
  //  if (b & ~1) __builtin_unreachable();
    return (a&~8) ^ ((b&1)<<3);
}
Unless you uncomment out the condtionals :).

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

* [Bug tree-optimization/101676] ^ not changed to | if the non-zero don't overlap
  2021-07-29 13:11 [Bug tree-optimization/101676] New: ^ not changed to | if the non-zero don't overlap pinskia at gcc dot gnu.org
@ 2021-07-30  6:12 ` rguenth at gcc dot gnu.org
  2023-08-28 20:21 ` pinskia at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: rguenth at gcc dot gnu.org @ 2021-07-30  6:12 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Richard Biener <rguenth at gcc dot gnu.org> ---
why is | better than ^?

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

* [Bug tree-optimization/101676] ^ not changed to | if the non-zero don't overlap
  2021-07-29 13:11 [Bug tree-optimization/101676] New: ^ not changed to | if the non-zero don't overlap pinskia at gcc dot gnu.org
  2021-07-30  6:12 ` [Bug tree-optimization/101676] " rguenth at gcc dot gnu.org
@ 2023-08-28 20:21 ` pinskia at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-08-28 20:21 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to Richard Biener from comment #1)
> why is | better than ^?

Just to reply to this. The reasoning from simplify-rtx.cc:
      /* If we are XORing two things that have no bits in common,
         convert them into an IOR.  This helps to detect rotation encoded
         using those methods and possibly other simplifications.  */

Which was added with r0-24478-g79e8185c9ccfcb .

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

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

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-29 13:11 [Bug tree-optimization/101676] New: ^ not changed to | if the non-zero don't overlap pinskia at gcc dot gnu.org
2021-07-30  6:12 ` [Bug tree-optimization/101676] " rguenth at gcc dot gnu.org
2023-08-28 20:21 ` 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).