https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116997
--- Comment #5 from avieira at gcc dot gnu.org --- I checked it locally and Pinski's recommended change does seem to fix the codegen for this case. I end up with: MEM <vector(2) unsigned int> [(void *)Ptr.0_1] = { 7, 6291456 }; I am regression testing the change now on aarch64_be-none-elf. @Stefan maybe you can test it on your z13 ? The change in question is: --- a/gcc/fold-const.cc +++ b/gcc/fold-const.cc @@ -13712,6 +13712,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)));