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

Uroš Bizjak <ubizjak at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
     Ever confirmed|0                           |1
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2025-12-29
          Component|target                      |middle-end

--- Comment #2 from Uroš Bizjak <ubizjak at gmail dot com> ---
(In reply to Kang-Che Sung from comment #0)
> This is more of an optimization feature request than a bug, but I believe
> these patterns for "subtract and overflow check" are common, and GCC missing
> these could be annoying (at least to me).
There is nothing that target-dependent code can do here. Middle-end does not
detect 
.SUB_OVERFLOW that would generate optimal code.

This variant is detected as .SUB_OVERFLOW:

--cut here--
unsigned foo (unsigned x, unsigned y)
{
  unsigned d = x - y;

  if (d > x)
    return 0x123;

  return d;
}
--cut here--

... but these ones are not:

--cut here--
unsigned bar (unsigned x, unsigned y)
{
  unsigned d = x - y;

  if (x - y > x)
    return 0x123;

  return d;
}

unsigned baz (unsigned x, unsigned y)
{
  unsigned d = x - y;

  if (x < y)
    return 0x123;

  return d;
}
--cut here--

Confirmed as middle-end PR.

Reply via email to