[Bug target/86891] [9 Regression] __builtin_sub_overflow incorrect for unsigned types

wilco at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Thu Jan 3 19:34:00 GMT 2019


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

--- Comment #5 from Wilco <wilco at gcc dot gnu.org> ---
(In reply to Richard Earnshaw from comment #4)
> Yes, the extension should be zero-extend, not sign extend.  The plus
> operation is correct, however, since decrementing the first operand could
> lead to underflow if it was zero.  So the correct rtl would be 
> 
>   (compare ((zero_x(a)) (plus (zero_x(b) (ltu(cc, 0)))))
>   (minus (...))

Agreed. The issue is more widespread though, signed underflow doesn't work
either,
and subv<mode>4 simply uses gen_sub<mode>3_compare1 which does do a normal
compare, so the RTL does not compute the overflow flag eventhough the actual
compare does.

It seems like a bug when it does constant fold this RTL given it should have
been folded before expand. Using UNSPEC for these complex flag uses may be best
to be safe.


More information about the Gcc-bugs mailing list