public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/113487] New: Missed optimization:simplify demanded bits on multi-use instructions like select
@ 2024-01-18 17:34 xxs_chy at outlook dot com
  2024-01-18 17:35 ` [Bug tree-optimization/113487] " pinskia at gcc dot gnu.org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: xxs_chy at outlook dot com @ 2024-01-18 17:34 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 113487
           Summary: Missed optimization:simplify demanded bits on
                    multi-use instructions like select
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: xxs_chy at outlook dot com
  Target Milestone: ---

Godbolt example: https://godbolt.org/z/EfKrTbK77

Based on common demanded bits from s&8 and s&16,
```
void src(bool c, unsigned a, unsigned b) {
    unsigned s = c ? a & 24 : b & 25;
    use(s & 8);
    use(s & 16);
}
```

can be folded to:

```
void tgt(bool c, unsigned a, unsigned b) {
    unsigned s = c ? a : b ;
    use(s & 8);
    use(s & 16);
}
```

Both LLVM and GCC missed this optimization opportunity.

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

* [Bug tree-optimization/113487] Missed optimization:simplify demanded bits on multi-use instructions like select
  2024-01-18 17:34 [Bug tree-optimization/113487] New: Missed optimization:simplify demanded bits on multi-use instructions like select xxs_chy at outlook dot com
@ 2024-01-18 17:35 ` pinskia at gcc dot gnu.org
  2024-01-18 17:38 ` pinskia at gcc dot gnu.org
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-01-18 17:35 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |missed-optimization
           Severity|normal                      |enhancement

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

* [Bug tree-optimization/113487] Missed optimization:simplify demanded bits on multi-use instructions like select
  2024-01-18 17:34 [Bug tree-optimization/113487] New: Missed optimization:simplify demanded bits on multi-use instructions like select xxs_chy at outlook dot com
  2024-01-18 17:35 ` [Bug tree-optimization/113487] " pinskia at gcc dot gnu.org
@ 2024-01-18 17:38 ` pinskia at gcc dot gnu.org
  2024-01-18 17:41 ` xxs_chy at outlook dot com
  2024-01-19  7:14 ` rguenth at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-01-18 17:38 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|                            |2024-01-18
             Status|UNCONFIRMED                 |NEW
     Ever confirmed|0                           |1

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Confirmed.

I don't know which pass this would be best implemented in though. Maybe phiopt
but I am not 100% sure there ...

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

* [Bug tree-optimization/113487] Missed optimization:simplify demanded bits on multi-use instructions like select
  2024-01-18 17:34 [Bug tree-optimization/113487] New: Missed optimization:simplify demanded bits on multi-use instructions like select xxs_chy at outlook dot com
  2024-01-18 17:35 ` [Bug tree-optimization/113487] " pinskia at gcc dot gnu.org
  2024-01-18 17:38 ` pinskia at gcc dot gnu.org
@ 2024-01-18 17:41 ` xxs_chy at outlook dot com
  2024-01-19  7:14 ` rguenth at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: xxs_chy at outlook dot com @ 2024-01-18 17:41 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from XChy <xxs_chy at outlook dot com> ---
I may miss something here... Apart from this one, it seems that GCC doesn't
simplify **one-use** instruction based on demanded bits too:
https://godbolt.org/z/67bYxd8hY

But LLVM indeed handle the one-use case.

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

* [Bug tree-optimization/113487] Missed optimization:simplify demanded bits on multi-use instructions like select
  2024-01-18 17:34 [Bug tree-optimization/113487] New: Missed optimization:simplify demanded bits on multi-use instructions like select xxs_chy at outlook dot com
                   ` (2 preceding siblings ...)
  2024-01-18 17:41 ` xxs_chy at outlook dot com
@ 2024-01-19  7:14 ` rguenth at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: rguenth at gcc dot gnu.org @ 2024-01-19  7:14 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Richard Biener <rguenth at gcc dot gnu.org> ---
Feels more like reassoc to me.  You could also view it as "bit-DCE", eliding
defs of dead bits.  Which might make it suitable for backprop (currently
doing sth similar for the sign "bit").

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

end of thread, other threads:[~2024-01-19  7:14 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-18 17:34 [Bug tree-optimization/113487] New: Missed optimization:simplify demanded bits on multi-use instructions like select xxs_chy at outlook dot com
2024-01-18 17:35 ` [Bug tree-optimization/113487] " pinskia at gcc dot gnu.org
2024-01-18 17:38 ` pinskia at gcc dot gnu.org
2024-01-18 17:41 ` xxs_chy at outlook dot com
2024-01-19  7:14 ` rguenth 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).