[Bug tree-optimization/81365] [7/8 Regression] GCC miscompiles swap

2017-07-18 Thread jakub at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81365

Jakub Jelinek  changed:

   What|Removed |Added

 Status|ASSIGNED|RESOLVED
 Resolution|--- |FIXED

--- Comment #8 from Jakub Jelinek  ---
Fixed for 7.2+.

[Bug tree-optimization/81365] [7/8 Regression] GCC miscompiles swap

2017-07-17 Thread jakub at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81365

--- Comment #7 from Jakub Jelinek  ---
Author: jakub
Date: Mon Jul 17 19:42:37 2017
New Revision: 250288

URL: https://gcc.gnu.org/viewcvs?rev=250288&root=gcc&view=rev
Log:
PR tree-optimization/81365
* tree-ssa-phiprop.c (propagate_with_phi): When considering hoisting
aggregate moves onto bb predecessor edges, make sure there are no
loads that could alias the lhs in between the start of bb and the
loads from *phi.

* g++.dg/torture/pr81365.C: New test.

Added:
branches/gcc-7-branch/gcc/testsuite/g++.dg/torture/pr81365.C
Modified:
branches/gcc-7-branch/gcc/ChangeLog
branches/gcc-7-branch/gcc/testsuite/ChangeLog
branches/gcc-7-branch/gcc/tree-ssa-phiprop.c

[Bug tree-optimization/81365] [7/8 Regression] GCC miscompiles swap

2017-07-17 Thread jakub at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81365

--- Comment #6 from Jakub Jelinek  ---
Author: jakub
Date: Mon Jul 17 09:10:23 2017
New Revision: 250261

URL: https://gcc.gnu.org/viewcvs?rev=250261&root=gcc&view=rev
Log:
PR tree-optimization/81365
* tree-ssa-phiprop.c (propagate_with_phi): When considering hoisting
aggregate moves onto bb predecessor edges, make sure there are no
loads that could alias the lhs in between the start of bb and the
loads from *phi.

* g++.dg/torture/pr81365.C: New test.

Added:
trunk/gcc/testsuite/g++.dg/torture/pr81365.C
Modified:
trunk/gcc/ChangeLog
trunk/gcc/testsuite/ChangeLog
trunk/gcc/tree-ssa-phiprop.c

[Bug tree-optimization/81365] [7/8 Regression] GCC miscompiles swap

2017-07-11 Thread jakub at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81365

Jakub Jelinek  changed:

   What|Removed |Added

 Status|NEW |ASSIGNED
   Assignee|unassigned at gcc dot gnu.org  |jakub at gcc dot gnu.org

--- Comment #5 from Jakub Jelinek  ---
Created attachment 41714
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=41714&action=edit
gcc8-pr81365.patch

Untested fix.

[Bug tree-optimization/81365] [7/8 Regression] GCC miscompiles swap

2017-07-11 Thread jakub at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81365

Jakub Jelinek  changed:

   What|Removed |Added

 CC||jakub at gcc dot gnu.org

--- Comment #4 from Jakub Jelinek  ---
The optimization and thus the bug too has been introduced in r235208, i.e.
PR70171.
The check Andrew mentions has been added in r236079, i.e. PR71039.  But it
actually does something completely different than the check we need here, it
makes sure that any SSA_NAMEs used in the lhs that we move earlier is available
there already.

What we need here is something different.
We already have:
  /* Check if we can move the loads.  The def stmt of the virtual use
 needs to be in a different basic block dominating bb.  When the
 def is an edge-inserted one we know it dominates us.  */
  vuse = gimple_vuse (use_stmt);
  def_stmt = SSA_NAME_DEF_STMT (vuse);
  if (!SSA_NAME_IS_DEFAULT_DEF (vuse)
  && (gimple_bb (def_stmt) == bb
  || (gimple_bb (def_stmt)
  && !dominated_by_p (CDI_DOMINATORS,
  bb, gimple_bb (def_stmt)
goto next;
which makes sure we don't miscompile
int h(int k, int i1, int j1)
{
  int *f1;
  if(k)
   f1 = &i1;
  else
   f1 = &j1;
  i1 = 7;
  return *f1;
}
where the use_stmt has an earlier store that might modify it.  That is
sufficient for the reg type case, but for the aggregate, where we actually move
the aggregate store earlier - onto the edges - we also have to ensure that
either there no memory loads between the PHI and use_stmt, or that the can't
alias the lhs.

[Bug tree-optimization/81365] [7/8 Regression] GCC miscompiles swap

2017-07-11 Thread marxin at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81365

Martin Liška  changed:

   What|Removed |Added

 CC||marxin at gcc dot gnu.org

--- Comment #3 from Martin Liška  ---
Introduced by unrelated commit which added early jump threading (r240221).

[Bug tree-optimization/81365] [7/8 Regression] GCC miscompiles swap

2017-07-09 Thread pinskia at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=81365

Andrew Pinski  changed:

   What|Removed |Added

   Target Milestone|--- |7.2

--- Comment #2 from Andrew Pinski  ---
  /* As we replicate the lhs on each incoming edge all
 used SSA names have to be available there.  */
  if (! for_each_index (gimple_assign_lhs_ptr (use_stmt),
chk_uses,
get_immediate_dominator (CDI_DOMINATORS,
 gimple_bb (phi
goto next;

This is supposed to check correctly but it does not ...