[Bug tree-optimization/108821] [11/12/13 Regression] LIM reissuing a violatile store when it cannot/should not

2023-02-16 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108821

Andrew Pinski  changed:

   What|Removed |Added

   Target Milestone|--- |11.4
 Status|UNCONFIRMED |NEW
   Keywords||wrong-code
   Last reconfirmed||2023-02-16
 Ever confirmed|0   |1
Summary|Extra volatile access with  |[11/12/13 Regression] LIM
   |-O2 -ftree-loop-im since|reissuing a violatile store
   |GCC-11  |when it cannot/should not

--- Comment #1 from Andrew Pinski  ---
Confirmed.

Re-issueing dependent store of *x.1_3 from loop 1 on exit 3 -> 4
Moving statement
gCrc_lsm.9 = gCrc;
(cost 0) out of loop 1.

[Bug tree-optimization/108821] [11/12/13 Regression] LIM reissuing a violatile store when it cannot/should not

2023-02-16 Thread sirl at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108821

Franz Sirl  changed:

   What|Removed |Added

 CC||rguenther at suse dot de

--- Comment #2 from Franz Sirl  ---
Started with commit b6ff3ddecfa93d53867afaaa078f85fc848abbbd:

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  

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.

[Bug tree-optimization/108821] [11/12/13 Regression] LIM reissuing a violatile store when it cannot/should not

2023-02-17 Thread rguenth at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108821

Richard Biener  changed:

   What|Removed |Added

 Status|NEW |ASSIGNED
   Assignee|unassigned at gcc dot gnu.org  |rguenth at gcc dot 
gnu.org
   Priority|P3  |P2

--- Comment #3 from Richard Biener  ---
Mine.

[Bug tree-optimization/108821] [11/12/13 Regression] LIM reissuing a violatile store when it cannot/should not

2023-02-17 Thread cvs-commit at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=108821

--- Comment #4 from CVS Commits  ---
The master branch has been updated by Richard Biener :

https://gcc.gnu.org/g:4c4f0f7acd6b96ee744ef598cbea5c7046a33654

commit r13-6114-g4c4f0f7acd6b96ee744ef598cbea5c7046a33654
Author: Richard Biener 
Date:   Fri Feb 17 12:36:44 2023 +0100

tree-optimization/108821 - store motion and volatiles

The following fixes store motion to not re-issue volatile stores
to preserve TBAA behavior since that will result in the number
of volatile accesses changing.

PR tree-optimization/108821
* tree-ssa-loop-im.cc (sm_seq_valid_bb): We can also not
move volatile accesses.

* gcc.dg/tree-ssa/ssa-lim-24.c: New testcase.