public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/114539] New: `__builtin_add_overflow(unsigned, b, &r); r  < b` where b is a CST is not optimized to using the overflow
@ 2024-04-01  2:45 pinskia at gcc dot gnu.org
  2024-04-01  2:47 ` [Bug tree-optimization/114539] " pinskia at gcc dot gnu.org
  0 siblings, 1 reply; 2+ messages in thread
From: pinskia at gcc dot gnu.org @ 2024-04-01  2:45 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 114539
           Summary: `__builtin_add_overflow(unsigned, b, &r); r  < b`
                    where b is a CST is not optimized to using the
                    overflow
           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:
```
bool f(unsigned v, unsigned tt)
{
 unsigned r;
 unsigned t = __builtin_add_overflow(v, tt, &r);
 return (r < tt) == t;
}


bool f1(unsigned v, unsigned tt)
{
 tt = 3;
 unsigned r;
 unsigned t = __builtin_add_overflow(v, tt, &r);
 return (r < tt) == t;
}
```

f is able to be optimized to 1 but f1 is not due to the `r < 3` being Canonical
form being `r <= 2` (or in the case of 1, `r == 0`).

I found this while looking into PR 114538 if we change things slightly.

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

end of thread, other threads:[~2024-04-01  2:47 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-04-01  2:45 [Bug tree-optimization/114539] New: `__builtin_add_overflow(unsigned, b, &r); r < b` where b is a CST is not optimized to using the overflow pinskia at gcc dot gnu.org
2024-04-01  2:47 ` [Bug tree-optimization/114539] " 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).