public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/113072] New: `(a ^ CST0) & (~a ^ CST0)` is not optimized to 0 at the gimple level
@ 2023-12-18 18:53 pinskia at gcc dot gnu.org
  2023-12-18 19:03 ` [Bug tree-optimization/113072] " pinskia at gcc dot gnu.org
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-12-18 18:53 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 113072
           Summary: `(a ^ CST0) & (~a ^ CST0)` is not optimized to 0 at
                    the gimple level
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Keywords: TREE
          Severity: enhancement
          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) { return (a ^ 4) & (~a ^ 4); }
```
This should be optimized to 0 but is missed at the gimple level.


RTL Combine catches it:
```
Trying 8, 7 -> 9:
    8: {r105:SI=r101:SI^0xfffffffffffffffb;clobber flags:CC;}
      REG_DEAD r101:SI
      REG_UNUSED flags:CC
    7: {r104:SI=r101:SI^0x4;clobber flags:CC;}
      REG_UNUSED flags:CC
    9: {r103:SI=r104:SI&r105:SI;clobber flags:CC;}
      REG_DEAD r105:SI
      REG_DEAD r104:SI
      REG_UNUSED flags:CC
Failed to match this instruction:
(parallel [
        (set (reg:SI 103)
            (const_int 0 [0]))
        (clobber (reg:CC 17 flags))
    ])
Successfully matched this instruction:
(set (reg:SI 103)
    (const_int 0 [0]))
allowing combination of insns 7, 8 and 9
original costs 4 + 4 + 4 = 12
replacement cost 4
```
via apply_distributive_law (I think) which does basically `(a ^ 4) & (a ^
(~4))` -> `(4 ^ (~4)) & (a ^ a)` which is 0 as `a ^ a` is 0.

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

end of thread, other threads:[~2024-01-01  0:33 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-12-18 18:53 [Bug tree-optimization/113072] New: `(a ^ CST0) & (~a ^ CST0)` is not optimized to 0 at the gimple level pinskia at gcc dot gnu.org
2023-12-18 19:03 ` [Bug tree-optimization/113072] " pinskia at gcc dot gnu.org
2023-12-18 19:03 ` pinskia at gcc dot gnu.org
2023-12-18 19:09 ` pinskia at gcc dot gnu.org
2023-12-18 19:10 ` pinskia at gcc dot gnu.org
2023-12-18 19:40 ` pinskia at gcc dot gnu.org
2024-01-01  0:33 ` 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).