public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/113383] New: `MAX(a,b) == 0` and `MAX(a,b) != 0` can be simplified (for unsigned types)
@ 2024-01-13 20:27 pinskia at gcc dot gnu.org
  0 siblings, 0 replies; only message in thread
From: pinskia at gcc dot gnu.org @ 2024-01-13 20:27 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 113383
           Summary: `MAX(a,b) == 0` and `MAX(a,b) != 0` can be simplified
                    (for unsigned types)
           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:
```
unsigned maxeq0(unsigned a, unsigned b)
{
        unsigned c = a > b ? a : b;
        return c == 0; // b == 0 && a == 0
}

unsigned maxeq0_1(unsigned a, unsigned b)
{
        return b == 0 && a == 0;
}

unsigned maxne0(unsigned a, unsigned b)
{
        unsigned c = a > b ? a : b;
        return c != 0; // b != 0 || a != 0
}

unsigned maxne0_1(unsigned a, unsigned b)
{
        return b != 0 || a != 0;
}

```
maxeq0 and maxeq0_1 are equivalent.
Likewise for maxne0 and maxne0_1.

LLVM is able to do this simplification.
Note this is only valid for unsigned MAX.

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2024-01-13 20:27 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-13 20:27 [Bug tree-optimization/113383] New: `MAX(a,b) == 0` and `MAX(a,b) != 0` can be simplified (for unsigned types) 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).