tree-optimization/104162 - CSE of &MEM[ptr].a[i] and ptr + CST
authorRichard Biener <rguenther@suse.de>
Wed, 26 Jan 2022 14:34:54 +0000 (15:34 +0100)
committerRichard Biener <rguenther@suse.de>
Thu, 5 May 2022 12:41:27 +0000 (14:41 +0200)
commitee1cb43bc76de800efa0ade687b0cd28e62a5f82
treed65098810337ddcdeb91b4dfbfd31c103879810d
parent92fff39f06449f907d8781a5dcaad0e8b9743480
tree-optimization/104162 - CSE of &MEM[ptr].a[i] and ptr + CST

This adds the capability to value-numbering of treating complex
address expressions where the offset becomes invariant as equal
to a POINTER_PLUS_EXPR.  This restores CSE that is now prevented
by early lowering of &MEM[ptr + CST] to a POINTER_PLUS_EXPR.

Unfortunately this regresses gcc.dg/asan/pr99673.c again, so
the testcase is adjusted accordingly.

2022-01-26  Richard Biener  <rguenther@suse.de>

PR tree-optimization/104162
* tree-ssa-sccvn.cc (vn_reference_lookup): Handle
&MEM[_1 + 5].a[i] like a POINTER_PLUS_EXPR if the offset
becomes invariant.
(vn_reference_insert): Likewise.

* gcc.dg/tree-ssa/ssa-fre-99.c: New testcase.
* gcc.dg/asan/pr99673.c: Adjust.
gcc/testsuite/gcc.dg/asan/pr99673.c
gcc/testsuite/gcc.dg/tree-ssa/ssa-fre-99.c [new file with mode: 0644]
gcc/tree-ssa-sccvn.cc