sccvn: Handle bitfields in vn_reference_lookup_3 [PR93582]
authorJakub Jelinek <jakub@redhat.com>
Thu, 13 Feb 2020 09:04:11 +0000 (10:04 +0100)
committerJakub Jelinek <jakub@redhat.com>
Thu, 13 Feb 2020 09:04:11 +0000 (10:04 +0100)
commit8aba425f4ebc5e2c054776d3cdddf13f7c1918f8
treeb99f04913cac6d23c8d1bccea47a2a03a9d44c98
parent8ea884b85e338d09b14e6a54043c53ae0c1b1fe9
sccvn: Handle bitfields in vn_reference_lookup_3 [PR93582]

The following patch is first step towards fixing PR93582.
vn_reference_lookup_3 right now punts on anything that isn't byte aligned,
so to be able to lookup a constant bitfield store, one needs to use
the exact same COMPONENT_REF, otherwise it isn't found.

This patch lifts up that that restriction if the bits to be loaded are
covered by a single store of a constant (keeps the restriction so far
for the multiple store case, can tweak that incrementally, but I think
for bisection etc. it is worth to do it one step at a time).

2020-02-13  Jakub Jelinek  <jakub@redhat.com>

PR tree-optimization/93582
* fold-const.h (shift_bytes_in_array_left,
shift_bytes_in_array_right): Declare.
* fold-const.c (shift_bytes_in_array_left,
shift_bytes_in_array_right): New function, moved from
gimple-ssa-store-merging.c, no longer static.
* gimple-ssa-store-merging.c (shift_bytes_in_array): Move
to gimple-ssa-store-merging.c and rename to shift_bytes_in_array_left.
(shift_bytes_in_array_right): Move to gimple-ssa-store-merging.c.
(encode_tree_to_bitpos): Use shift_bytes_in_array_left instead of
shift_bytes_in_array.
(verify_shift_bytes_in_array): Rename to ...
(verify_shift_bytes_in_array_left): ... this.  Use
shift_bytes_in_array_left instead of shift_bytes_in_array.
(store_merging_c_tests): Call verify_shift_bytes_in_array_left
instead of verify_shift_bytes_in_array.
* tree-ssa-sccvn.c (vn_reference_lookup_3): For native_encode_expr
/ native_interpret_expr where the store covers all needed bits,
punt on PDP-endian, otherwise allow all involved offsets and sizes
not to be byte-aligned.

* gcc.dg/tree-ssa/pr93582-1.c: New test.
* gcc.dg/tree-ssa/pr93582-2.c: New test.
* gcc.dg/tree-ssa/pr93582-3.c: New test.
gcc/ChangeLog
gcc/fold-const.c
gcc/fold-const.h
gcc/gimple-ssa-store-merging.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/tree-ssa/pr93582-1.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/tree-ssa/pr93582-2.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/tree-ssa/pr93582-3.c [new file with mode: 0644]
gcc/tree-ssa-sccvn.c