[Bug tree-optimization/106131] [10/11/12/13 Regression] -fstrict-aliasing breaks normal program that does not use any pointer or reference

2022-07-01 Thread cvs-commit at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106131

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

https://gcc.gnu.org/g:9701432ff79926a5dd3303be3417e0bd0c24140b

commit r13-1376-g9701432ff79926a5dd3303be3417e0bd0c24140b
Author: Richard Biener 
Date:   Thu Jun 30 10:33:40 2022 +0200

tree-optimization/106131 - wrong code with FRE rewriting

The following makes sure to not use the original TBAA type for
looking up a value across an aggregate copy when we had to offset
the read.

2022-06-30  Richard Biener  

PR tree-optimization/106131
* tree-ssa-sccvn.cc (vn_reference_lookup_3): Force alias-set
zero when offsetting the read looking through an aggregate
copy.

* g++.dg/torture/pr106131.C: New testcase.

[Bug tree-optimization/106131] [10/11/12/13 Regression] -fstrict-aliasing breaks normal program that does not use any pointer or reference

2022-06-30 Thread rguenth at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106131

--- Comment #9 from Richard Biener  ---
So the issue is in processing

  x = MEM[(const struct Pair &)_11];
  _47 = MEM[(const int &) + 4];

where we when visiting the def for 'x' continue the lookup with an
effective MEM[(const struct Pair &)_11 + 4]; but that looks for a store
of TBAA 'Pair' where we then correctly determine that _7->b = _46;
doesn't possibly alias.

A conservative fix restoring behavior before the relevant change is to
force alias set zero (no TBAA) for the offsetted lookup.

[Bug tree-optimization/106131] [10/11/12/13 Regression] -fstrict-aliasing breaks normal program that does not use any pointer or reference

2022-06-30 Thread rguenth at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106131

Richard Biener  changed:

   What|Removed |Added

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

--- Comment #8 from Richard Biener  ---
So the issue seems to be that fre1 transforms

   :
  _1 = (long unsigned int) i_13;
  _2 = _1 * 8;
  _3 = _18 + _2;
  _40 = MEM[(const struct Pair &)_18].a;
  _3->a = _40;
  _44 = MEM[(const struct Pair &)_18].b;
  _3->b = _44;
  if (i_13 == 0)
goto ; [INV]
  else
goto ; [INV]

   :
  _5 = (long unsigned int) i_13;
  _6 = _5 * 8;
  _7 = _18 + _6;
  _45 = MEM[(const struct Pair &)_18 + 16].a;
  _7->a = _45;
  _46 = MEM[(const struct Pair &)_18 + 16].b;
  _7->b = _46;

   :
  _9 = (long unsigned int) i_13;
  _10 = _9 * 8;
  _11 = _18 + _10;
  x = MEM[(const struct Pair &)_11];
  y = MEM[(const struct Pair &)_18 + 8];
  _47 = MEM[(const int &) + 4];
  _48 = MEM[(const int &) + 4];
  if (_47 < _48)
goto ; [50.00%]
  else
goto ; [50.00%]

into

...
   :
  x = MEM[(const struct Pair &)_3];
  y = MEM[(const struct Pair &)_18 + 8];
  _48 = MEM[(const int &) + 4];
  if (_44 < _48)
goto ; [50.00%]
  else
goto ; [50.00%]

CSEing the load _47 = MEM[(const int &) + 4]; to _44 crossing the
conditional clobber in BB4.

[Bug tree-optimization/106131] [10/11/12/13 Regression] -fstrict-aliasing breaks normal program that does not use any pointer or reference

2022-06-30 Thread rguenther at suse dot de via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106131

--- Comment #7 from rguenther at suse dot de  ---
On Wed, 29 Jun 2022, mpolacek at gcc dot gnu.org wrote:

> https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106131
> 
> --- Comment #5 from Marek Polacek  ---
> Started with
> 
> commit 8403c2cf5f66758fc78a01a675b0d218fded0202
> Author: Richard Biener 
> Date:   Mon Nov 24 14:07:18 2014 +

I think that just exposed it.  Btw, I've not got to the point 
understanding what actual transform makes the testcase fail (nor
spot the relevant difference in .optimized).

[Bug tree-optimization/106131] [10/11/12/13 Regression] -fstrict-aliasing breaks normal program that does not use any pointer or reference

2022-06-29 Thread 18307130172 at fudan dot edu.cn via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106131

--- Comment #6 from Xue Zhenliang <18307130172 at fudan dot edu.cn> ---
I'm trying to reducing it further. Now I've eliminated the dependency on STL:

struct Pair {
int a, b;

Pair(const Pair &) = default;
Pair(int _a, int _b) : a(_a), b(_b) {}
Pair =(const Pair ) {
a = z.a;
b = z.b;
return *this;
}
};

const int (const int , const int ) {
return a < b ? b : a;
}

int foo(Pair x, Pair y) {
return max(x.b, y.b);
}

int main() {
auto f = new Pair[3] {{0, -11}, {0, -8}, {0, 2}};
for (int i = 0; i < 1; i++) {
f[i] = f[0];
if(i == 0)
f[i] = f[2];
if (foo(f[i], f[1]) != 2)
__builtin_abort();
}
}

[Bug tree-optimization/106131] [10/11/12/13 Regression] -fstrict-aliasing breaks normal program that does not use any pointer or reference

2022-06-29 Thread mpolacek at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106131

Marek Polacek  changed:

   What|Removed |Added

   Last reconfirmed||2022-06-29
 Status|UNCONFIRMED |NEW
 Ever confirmed|0   |1

[Bug tree-optimization/106131] [10/11/12/13 Regression] -fstrict-aliasing breaks normal program that does not use any pointer or reference

2022-06-29 Thread mpolacek at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=106131

Marek Polacek  changed:

   What|Removed |Added

   Keywords|needs-bisection |
 CC||mpolacek at gcc dot gnu.org
  Component|c++ |tree-optimization
   Priority|P3  |P2