tree-optimization/111137 - dependence checking for SLP
commit845ee9c7107956845e487cb123fa581d9c70ea1b
authorRichard Biener <rguenther@suse.de>
Fri, 25 Aug 2023 11:37:30 +0000 (25 13:37 +0200)
committerRichard Biener <rguenther@suse.de>
Fri, 25 Aug 2023 12:37:37 +0000 (25 14:37 +0200)
tree48e096ae11fd7b83e679eabb8ba449c98ddbb504
parent470da3b27e6dbeb3286b09dcb1c1b810ac75b276
tree-optimization/111137 - dependence checking for SLP

The following fixes a mistake with SLP dependence checking.  When
checking whether we can hoist loads to the first load place we
special-case stores of the same instance considering them sunk
to the last store place.  But we fail to consider that stores from
other SLP instances are sunk in a similar way.  This leads us to
miss the dependence between (A) and (B) in

  b[0][1] = 0;             (A)
...
  _6 = b[_5 /* 0 */][0];   (B')
  _7 = _6 ^ 1;
  b[_5 /* 0 */][0] = _7;
  b[0][2] = 0;             (A')
  _10 = b[_5 /* 0 */][1];  (B)
  _11 = _10 ^ 1;
  b[_5 /* 0 */][1] = _11;

where the zeroing stores are sunk to (A') and the loads hoisted
to (B').  The following fixes this, treating grouped stores from
other instances similar to stores from our own instance.  The
difference is - and this is more conservative than necessary - that
we don't know which stores of a group are in which SLP instance
(though I believe either all of the grouped stores will be in
a single SLP instance or in none at the moment), so we don't
know which stores are sunk where.  We simply assume they are
all sunk to the last store we run into.  Likewise we do not take
into account that an SLP instance might be cancelled (or a grouped
store not actually belong to any instance).

PR tree-optimization/111137
* tree-vect-data-refs.cc (vect_slp_analyze_load_dependences):
Properly handle grouped stores from other SLP instances.

* gcc.dg/torture/pr111137.c: New testcase.
gcc/testsuite/gcc.dg/torture/pr111137.c [new file with mode: 0644]
gcc/tree-vect-data-refs.cc