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

--- Comment #8 from GCC Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Roger Sayle <sa...@gcc.gnu.org>:

https://gcc.gnu.org/g:d8b05aef77443e1d3d8f3f5d2c56ac49a503fee3

commit r15-1584-gd8b05aef77443e1d3d8f3f5d2c56ac49a503fee3
Author: Roger Sayle <ro...@nextmovesoftware.com>
Date:   Mon Jun 24 15:34:03 2024 +0100

    PR tree-optimization/113673: Avoid load merging when potentially trapping.

    This patch fixes PR tree-optimization/113673, a P2 ice-on-valid regression
    caused by load merging of (ptr[0]<<8)+ptr[1] when -ftrapv has been
    specified.  When the operator is | or ^ this is safe, but for addition
    of signed integer types, a trap may be generated/required, so merging this
    idiom into a single non-trapping instruction is inappropriate, confusing
    the compiler by transforming a basic block with an exception edge into one
    without.

    This revision implements Richard Biener's feedback to add an early check
    for stmt_can_throw_internal (cfun, stmt) to prevent transforming in the
    presence of any statement that could trap, not just overflow on addition.
    The one other tweak included in this patch is to mark the local function
    find_bswap_or_nop_load as static ensuring that it isn't called from outside
    this file, and guaranteeing that it is dominated by stmt_can_throw_internal
    checking.

    2024-06-24  Roger Sayle  <ro...@nextmovesoftware.com>
                Richard Biener  <rguent...@suse.de>

    gcc/ChangeLog
            PR tree-optimization/113673
            * gimple-ssa-store-merging.cc (find_bswap_or_nop_load): Make
static.
            (find_bswap_or_nop_1): Avoid transformations (load merging) when
            stmt_can_throw_internal indicates that a statement can trap.

    gcc/testsuite/ChangeLog
            PR tree-optimization/113673
            * g++.dg/pr113673.C: New test case.

Reply via email to