public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/115636] New: Missing optimzation: fold ` (w << (unsigned int)((flag ? a : b) - 32768))` to ` flag ? w << (unsigned int)(a - 32768) : 0 `
@ 2024-06-25  9:58 zhiwuyazhe154 at gmail dot com
  2024-06-25 22:02 ` [Bug tree-optimization/115636] " pinskia at gcc dot gnu.org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: zhiwuyazhe154 at gmail dot com @ 2024-06-25  9:58 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 115636
           Summary: Missing optimzation: fold ` (w << (unsigned int)((flag
                    ? a : b) - 32768))` to ` flag ? w << (unsigned int)(a
                    - 32768) : 0 `
           Product: gcc
           Version: 15.0
            Status: UNCONFIRMED
          Keywords: missed-optimization
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: zhiwuyazhe154 at gmail dot com
  Target Milestone: ---

godbolt example: https://godbolt.org/z/W5hr6G8oK

code example: 
```cpp
short b, n;
void func(signed char w, signed char flag, unsigned long long int a) {
    n = 0 >= (w << (unsigned int)((flag ? a : b) - 32768));
}
```

In this case, when flag != 0, no matter what the value of b is, the value of
(unsigned int)(b - 32768) is much greater than 8, which means that w will be
shifted left more than 8 times. According to the behavior of gcc, the value of
w will be assigned to 0, that is, as long as flag != 0, then w will be 0,
regardless of the value of b.

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

end of thread, other threads:[~2024-06-26 23:11 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-06-25  9:58 [Bug tree-optimization/115636] New: Missing optimzation: fold ` (w << (unsigned int)((flag ? a : b) - 32768))` to ` flag ? w << (unsigned int)(a - 32768) : 0 ` zhiwuyazhe154 at gmail dot com
2024-06-25 22:02 ` [Bug tree-optimization/115636] " pinskia at gcc dot gnu.org
2024-06-25 22:08 ` pinskia at gcc dot gnu.org
2024-06-26  3:18 ` pinskia at gcc dot gnu.org
2024-06-26 23:11 ` 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).