store-merging: Fix up >= 64 bit insertion [PR111015]
authorJakub Jelinek <jakub@redhat.com>
Wed, 30 Aug 2023 08:47:21 +0000 (10:47 +0200)
committerJakub Jelinek <jakub@redhat.com>
Wed, 30 Aug 2023 09:43:40 +0000 (11:43 +0200)
commitd04993b217f42b8e60b7a6d66647966b1e41302d
tree23ffb1e3ec801c783fac31dc5f66c4d67490e27f
parent158b279764c9cbf95e52d93f5454e2bb41656576
store-merging: Fix up >= 64 bit insertion [PR111015]

The following testcase shows that we mishandle bit insertion for
info->bitsize >= 64.  The problem is in using unsigned HOST_WIDE_INT
shift + subtraction + build_int_cst to compute mask, the shift invokes
UB at compile time for info->bitsize 64 and larger and e.g. on the testcase
with info->bitsize happens to compute mask of 0x3f rather than
0x3f'ffffffff'ffffffff.

The patch fixes that by using wide_int wi::mask + wide_int_to_tree, so it
handles masks in any precision (up to WIDE_INT_MAX_PRECISION ;) ).

2023-08-30  Jakub Jelinek  <jakub@redhat.com>

PR tree-optimization/111015
* gimple-ssa-store-merging.cc
(imm_store_chain_info::output_merged_store): Use wi::mask and
wide_int_to_tree instead of unsigned HOST_WIDE_INT shift and
build_int_cst to build BIT_AND_EXPR mask.

* gcc.dg/pr111015.c: New test.

(cherry picked from commit 49a3b35c4068091900b657cd36e5cffd41ef0c47)
gcc/gimple-ssa-store-merging.cc
gcc/testsuite/gcc.dg/pr111015.c [new file with mode: 0644]
This page took 0.07064 seconds and 6 git commands to generate.