tree-optimization/94988 - enhance SM some more
authorRichard Biener <rguenther@suse.de>
Fri, 8 May 2020 10:03:30 +0000 (12:03 +0200)
committerRichard Biener <rguenther@suse.de>
Mon, 11 May 2020 14:52:45 +0000 (16:52 +0200)
commitb6ff3ddecfa93d53867afaaa078f85fc848abbbd
tree1f2f4e1320b8db08dcc8c0c3c9d82a368c89a610
parent892c7427ee234c04852e90d9ce32913a429adf9d
tree-optimization/94988 - enhance SM some more

This enhances store-order preserving store motion to handle the case
of non-invariant dependent stores in the sequence of unconditionally
executed stores on exit by re-issueing them as part of the sequence
of stores on the exit.  This fixes the observed regression of
gcc.target/i386/pr64110.c which relies on store-motion of 'b'
for a loop like

  for (int i = 0; i < j; ++i)
    *b++ = x;

where for correctness we now no longer apply store-motion.  With
the patch we emit the correct

  tem = b;
  for (int i = 0; i < j; ++i)
    {
      tem = tem + 1;
      *tem = x;
    }
  b = tem;
  *tem = x;

preserving the original order of stores.  A testcase reflecting
the miscompilation done by earlier GCC is added as well.

This also fixes the reported ICE in PR95025 and adds checking code
to catch it earlier - the issue was not-supported refs propagation
leaving stray refs in the sequence.

2020-05-11  Richard Biener  <rguenther@suse.de>

PR tree-optimization/94988
PR tree-optimization/95025
* tree-ssa-loop-im.c (seq_entry): Make a struct, add from.
(sm_seq_push_down): Take extra parameter denoting where we
moved the ref to.
(execute_sm_exit): Re-issue sm_other stores in the correct
order.
(sm_seq_valid_bb): When always executed, allow sm_other to
prevail inbetween sm_ord and record their stored value.
(hoist_memory_references): Adjust refs_not_supported propagation
and prune sm_other from the end of the ordered sequences.

* gcc.dg/torture/pr94988.c: New testcase.
* gcc.dg/torture/pr95025.c: Likewise.
* gcc.dg/torture/pr95045.c: Likewise.
* g++.dg/asan/pr95025.C: New testcase.
gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/asan/pr95025.C [new file with mode: 0644]
gcc/testsuite/gcc.dg/torture/pr94988.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/torture/pr95025.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/torture/pr95045.c [new file with mode: 0644]
gcc/tree-ssa-loop-im.c