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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2020-02-26
                 CC|                            |pinskia at gcc dot gnu.org
     Ever confirmed|0                           |1

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
My bet is there missing the following somewhere:
+         if (BYTES_BIG_ENDIAN)
+           bitpos = TYPE_PRECISION (type) - bitpos - bitsize;

I have not looked where though.  I do know BIT_INSERT_EXPR is broken with that
respect.
The following patch fixes that:
commit 7490f8e4f52d38d1ae265bec50ab518e86a53d19
Author: Andrew Pinski <apin...@marvell.com>
Date:   Tue Dec 17 03:54:46 2019 +0000

    Fix big-endian constant folding of BIT_INSERT_EXPR

    Big-endian has a different idea of what bit order
    should be compared to little-endian.  This fixes
    it by correcting the shift/mask to be in the correct
    order.

    Change-Id: I3e4ba3c27d62a20affd08100083cee5f921edc7d
    Signed-off-by: Andrew Pinski <apin...@marvell.com>

diff --git a/gcc/fold-const.c b/gcc/fold-const.c
index aefa91666e2..f515d776c57 100644
--- a/gcc/fold-const.c
+++ b/gcc/fold-const.c
@@ -12506,6 +12506,8 @@ fold_ternary_loc (location_t loc, enum tree_code code,
tree type,
        {
          unsigned HOST_WIDE_INT bitpos = tree_to_uhwi (op2);
          unsigned bitsize = TYPE_PRECISION (TREE_TYPE (arg1));
+         if (BYTES_BIG_ENDIAN)
+           bitpos = TYPE_PRECISION (type) - bitpos - bitsize;
          wide_int tem = (wi::to_wide (arg0)
                          & wi::shifted_mask (bitpos, bitsize, true,
                                              TYPE_PRECISION (type)));

Reply via email to