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

From: Michael Paquier <michael(at)paquier(dot)xyz>
To: pgsql-committers(at)lists(dot)postgresql(dot)org
Subject: pgsql: Use pg_neg_s{32,64}_overflow() for some overflow checks
Date: 2026-09-01 05:32:44
Message-ID: E1x1H6x-00000002zMQ-1y1K@gemulon.postgresql.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-committers

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(at)ilmari(dot)org>
Author: Ewan Young <kdbase(dot)hack(at)gmail(dot)com>
Reviewed-by: Michael Paquier <michael(at)paquier(dot)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(-)

Browse pgsql-committers by date

  From Date Subject
Next Message Daniel Gustafsson 2026-09-01 08:19:55 pgsql: Handle PG_INT32_MIN negation overflow in right()
Previous Message Fujii Masao 2026-09-01 03:56:12 pgsql: doc: reformat GRAPH_TABLE examples