[PATCH] libm: Fixing overflow handling issue for scalbnf and scalbn

Keith Packard keithp@keithp.com
Tue Jul 20 16:12:36 GMT 2021


Kito Cheng <kito.cheng@sifive.com> writes:

> cc Aldy Hernandez <aldyh@redhat.com> and Andrew MacLeod <amacleod@redhat.com>,
> they are author of new VRP analysis for GCC, just to make sure I didn't
> mis-understanding or mis-interpreting anything on GCC site.
>
> GCC 11 have better value range analysis, that give GCC more confidence
> to perform more aggressive optimization, but it cause scalbn/scalbnf get
> wrong result.

C doesn't specify what happens when signed integer values overflow;
compiler developers believe that gives them the license to do this kind
of "optimization". This patch makes the code more compliant with the C
spec.

The only way to get known overflow behavior would be to use unsigned
integers, but as this code depends on signed comparisons, that isn't
practical here.

I've added tests for this case to the picolibc test suite and verified
that your patch corrects this issue on 32-bit ARM using GCC 11.

-- 
-keith
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 832 bytes
Desc: not available
URL: <https://sourceware.org/pipermail/newlib/attachments/20210720/8fdcef4a/attachment.sig>


More information about the Newlib mailing list