Use pg_neg_s{32,64}_overflow() for some overflow checks

The files updated in this commit open-coded checks based on a minimal
value (as of "x == PG_INTnn_MIN") combined with negative calculations.
More efficient equivalents are available in int.h with
pg_neg_s32_overflow() and pg_neg_s64_overflow().

Extracted from a larger patch by the same author.  These spots have
proved to reduce the number of instructions generated after testing
across some versions of clang and gcc, with and without the
__builtin_*_overflow() functions.  Some unlikely() can be removed, but
not all, cash.c standing as an exception.  There should be no behavioral
changes.

Suggested-by: Dagfinn Ilmari MannsÃ¥ker <[email protected]>
Author: Ewan Young <[email protected]>
Reviewed-by: Michael Paquier <[email protected]>
Discussion: 
https://postgr.es/m/caon2xho4ttfiow2kklbpioejnl4th5p1qvtm4msdeu+kw1r...@mail.gmail.com

Branch
------
master

Details
-------
https://git.postgresql.org/pg/commitdiff/8e483af5515ec4ee90d17a3864f5bb764e4e9c47

Modified Files
--------------
src/backend/utils/adt/cash.c    |  9 +++++----
src/backend/utils/adt/int.c     | 11 +++++------
src/backend/utils/adt/int8.c    | 12 ++++--------
src/backend/utils/adt/numeric.c |  3 +--
4 files changed, 15 insertions(+), 20 deletions(-)

Reply via email to