agora inbox for pgsql-committers@postgresql.org  
help / color / mirror / Atom feed
From: Michael Paquier <michael@paquier.xyz>
To: pgsql-committers@lists.postgresql.org
Subject: pgsql: Use pg_neg_s{32,64}_overflow() for some overflow checks
Date: Tue, 01 Sep 2026 05:32:44 +0000
Message-ID: <E1x1H6x-00000002zMQ-1y1K@gemulon.postgresql.org> (raw)

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 <ilmari@ilmari.org>
Author: Ewan Young <kdbase.hack@gmail.com>
Reviewed-by: Michael Paquier <michael@paquier.xyz>
Discussion: https://postgr.es/m/CAON2xHO4tTFiow2KKLbpiOEJNL4Th5p1QVTm4mSdEU+KW1rrfQ@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(-)



Message-ID: <E1x1H6x-00000002zMQ-1y1K@gemulon.postgresql.org>
Permalink:  ../E1x1H6x-00000002zMQ-1y1K@gemulon.postgresql.org/
Also on:    postgresql.org/message-id/E1x1H6x-00000002zMQ-1y1K@gemulon.postgresql.org

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-committers@postgresql.org
  Cc: michael@paquier.xyz, pgsql-committers@lists.postgresql.org
  Subject: Re: pgsql: Use pg_neg_s{32,64}_overflow() for some overflow checks
  In-Reply-To: <E1x1H6x-00000002zMQ-1y1K@gemulon.postgresql.org>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox