public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/113176] New: `(n / 4) ? n / 4 : 0` is not optimized to just `n /4`
@ 2023-12-30  4:29 pinskia at gcc dot gnu.org
  2023-12-30  4:44 ` [Bug tree-optimization/113176] " pinskia at gcc dot gnu.org
  0 siblings, 1 reply; 2+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-12-30  4:29 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 113176
           Summary: `(n / 4) ? n / 4 : 0` is not optimized to just `n /4`
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Keywords: missed-optimization
          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 unopt(int n) {
    if (n / 4)
        return n / 4;
    else
        return 0;
}

int unopt1(int n) {
    return (n / 4) ? n / 4 : 0;
}

int opt(int n) {
    return n / 4;
}
```

I would have expected unopt be transformed into opt but currently it is not.

This is because GCC decides to transform `(n / 4) != 0` into `(unsigned int) n
+ 3 > 6`.

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

* [Bug tree-optimization/113176] `(n / 4) ? n / 4 : 0` is not optimized to just `n /4`
  2023-12-30  4:29 [Bug tree-optimization/113176] New: `(n / 4) ? n / 4 : 0` is not optimized to just `n /4` pinskia at gcc dot gnu.org
@ 2023-12-30  4:44 ` pinskia at gcc dot gnu.org
  0 siblings, 0 replies; 2+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-12-30  4:44 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
I should note the non-constant case is already handled:
```
int unopt(int n, int c) {
    if (n / c)
        return n / c;
    else
        return 0;
}
```
It is just the constant case that has issues.

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

end of thread, other threads:[~2023-12-30  4:44 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-12-30  4:29 [Bug tree-optimization/113176] New: `(n / 4) ? n / 4 : 0` is not optimized to just `n /4` pinskia at gcc dot gnu.org
2023-12-30  4:44 ` [Bug tree-optimization/113176] " 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).