tree-optimization/114121 - wrong VN with context sensitive range info
commitc841144a94363ff26e40ab3f26b14702c32987a8
authorRichard Biener <rguenther@suse.de>
Wed, 28 Feb 2024 11:37:07 +0000 (28 12:37 +0100)
committerRichard Biener <rguenther@suse.de>
Wed, 28 Feb 2024 14:03:17 +0000 (28 15:03 +0100)
tree279fc5dcb325f9c99b17e83b484693496424d198
parent2d8cd712b17e88f2935237665799d0c72b7ce1b6
tree-optimization/114121 - wrong VN with context sensitive range info

When VN ends up exploiting range-info specifying the ao_ref offset
and max_size we have to make sure to reflect this in the hashtable
entry for the recorded expression.  The PR113831 fix handled the
case where we can encode this in the operands themselves but this
bug shows the issue is more widespread.

So instead of altering the operands the following instead records
this extra info that's possibly used, only throwing it away when
the value-numbering didn't come up with a non-VARYING value which
is an important detail to preserve CSE as opposed to constant
folding which is where all cases currently known popped up.

With this the original PR113831 fix can be reverted.

PR tree-optimization/114121
* tree-ssa-sccvn.h (vn_reference_s::offset,
vn_reference_s::max_size): New fields.
(vn_reference_insert_pieces): Adjust prototype.
* tree-ssa-pre.cc (phi_translate_1): Preserve offset/max_size.
* tree-ssa-sccvn.cc (vn_reference_eq): Compare offset and
size, allow using "don't know" state.
(vn_walk_cb_data::finish): Pass along offset/max_size.
(vn_reference_lookup_or_insert_for_pieces): Take offset and
max_size as argument and use it.
(vn_reference_lookup_3): Properly adjust offset and max_size
according to the adjusted ao_ref.
(vn_reference_lookup_pieces): Initialize offset and max_size.
(vn_reference_lookup): Likewise.
(vn_reference_lookup_call): Likewise.
(vn_reference_insert): Likewise.
(visit_reference_op_call): Likewise.
(vn_reference_insert_pieces): Take offset and max_size
as argument and use it.

* gcc.dg/torture/pr114121.c: New testcase.
gcc/testsuite/gcc.dg/torture/pr114121.c [new file with mode: 0644]
gcc/tree-ssa-pre.cc
gcc/tree-ssa-sccvn.cc
gcc/tree-ssa-sccvn.h