[Bug tree-optimization/101256] [12 Regression] Wrong code with -O3 since r12-1841-g9fe9c45ae33a2df7

2021-07-06 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101256

Andrew Pinski  changed:

   What|Removed |Added

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

--- Comment #9 from Andrew Pinski  ---
Fixed.

[Bug tree-optimization/101256] [12 Regression] Wrong code with -O3 since r12-1841-g9fe9c45ae33a2df7

2021-07-06 Thread cvs-commit at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101256

--- Comment #8 from CVS Commits  ---
The master branch has been updated by Andrew Pinski :

https://gcc.gnu.org/g:51abfb6a893c87dbf84a33009b6cd6dbd25d66f1

commit r12-2048-g51abfb6a893c87dbf84a33009b6cd6dbd25d66f1
Author: Andrew Pinski 
Date:   Tue Jun 29 14:30:34 2021 -0700

Fix 101256: Wrong code due to range incorrect from PHI-OPT

So the problem here is that replace_phi_edge_with_variable
will copy range information to a already (not newly) defined
ssa name.  This causes wrong code later on.
This fixes the problem by require the new ssa name to
be defined in the same bb as the conditional that is
about to be deleted.

OK? Bootstrapped and tested on x86_64-linux-gnu with no regressions.

Changes from v1:
* this is a simplification of what was trying to be done before.

gcc/ChangeLog:

PR tree-optimization/101256
* dbgcnt.def (phiopt_edge_range): New counter.
* tree-ssa-phiopt.c (replace_phi_edge_with_variable):
Check to make sure the new name is defined in the same
bb as the conditional before duplicating range info.
Also add debug counter.

gcc/testsuite/ChangeLog:

PR tree-optimization/101256
* g++.dg/torture/pr101256.C: New test.

[Bug tree-optimization/101256] [12 Regression] Wrong code with -O3 since r12-1841-g9fe9c45ae33a2df7

2021-07-05 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101256

Andrew Pinski  changed:

   What|Removed |Added

URL|https://gcc.gnu.org/piperma |https://gcc.gnu.org/piperma
   |il/gcc-patches/2021-July/57 |il/gcc-patches/2021-July/57
   |4412.html   |4490.html

--- Comment #7 from Andrew Pinski  ---
Updated patch:
https://gcc.gnu.org/pipermail/gcc-patches/2021-July/574490.html

[Bug tree-optimization/101256] [12 Regression] Wrong code with -O3 since r12-1841-g9fe9c45ae33a2df7

2021-07-02 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101256

--- Comment #6 from Andrew Pinski  ---
And here is a self-contained testcase:

template 
const T& max(const T& a, const T& b)
{
return (a < b) ? b : a;
}

signed char var_5 = -128;
unsigned int var_11 = 2144479212U;
unsigned long long int arr [22];

void
__attribute__((noipa))
test(signed char var_5, unsigned var_11) {
  for (short i_61 = 0; i_61 < var_5 + 149; i_61 += 1)
arr[i_61] = max((signed char)0, var_5) ? max((signed char)1, var_5) :
var_11;
}

int main() {
  for (size_t i_0 = 0; i_0 < 22; ++i_0) 
  arr [i_0] = 11834725929543695741ULL;

  test(var_5, var_11);
  if (arr [0] != 2144479212ULL && arr [0] != 11834725929543695741ULL)
__builtin_abort ();
  return 0;
}

[Bug tree-optimization/101256] [12 Regression] Wrong code with -O3 since r12-1841-g9fe9c45ae33a2df7

2021-07-02 Thread marxin at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101256

--- Comment #5 from Martin Liška  ---
And I can confirm the patch candidate fixes that.

[Bug tree-optimization/101256] [12 Regression] Wrong code with -O3 since r12-1841-g9fe9c45ae33a2df7

2021-07-02 Thread marxin at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101256

--- Comment #4 from Martin Liška  ---
I managed reducing a test-case:

$ cat driver.cpp 
#include 
#include 

template 
const T& max(const T& a, const T& b)
{
return (a < b) ? b : a;
}

signed char var_5 = -128;
unsigned int var_11 = 2144479212U;
unsigned long long int arr [22];

void
__attribute__((noipa))
test(signed char var_5, unsigned var_11) {
  for (short i_61 = 0; i_61 < var_5 + 149; i_61 += 1)
arr[i_61] = max((signed char)0, var_5) ? max((signed char)1, var_5) :
var_11;
}

int main() {
  for (size_t i_0 = 0; i_0 < 22; ++i_0) 
  arr [i_0] = 11834725929543695741ULL;

test(var_5, var_11);
assert(arr [0] == 2144479212ULL || arr [0]  == 11834725929543695741ULL);
__builtin_printf ("OK\n");
}

$ g++ driver.cpp -O2 && ./a.out 
a.out: driver.cpp:26: int main(): Assertion `arr [0] == 2144479212ULL || arr
[0] == 11834725929543695741ULL' failed.
Aborted (core dumped)
$ g++ driver.cpp && ./a.out 
OK

[Bug tree-optimization/101256] [12 Regression] Wrong code with -O3 since r12-1841-g9fe9c45ae33a2df7

2021-06-29 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101256

--- Comment #3 from Andrew Pinski  ---
Created attachment 51087
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=51087=edit
Patch which I am testing

[Bug tree-optimization/101256] [12 Regression] Wrong code with -O3 since r12-1841-g9fe9c45ae33a2df7

2021-06-29 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101256

--- Comment #2 from Andrew Pinski  ---
I have a fix but I don't have a testcase really.
What is happening is value_replacement is happening but since the ssa_name that
is being used for replace_phi_edge_with_variable is not newly defined, we are
adding the range info from something which was conditionally defined.

To be able to make sure we are doing the range for a newly defined name, we
need to pass the sequence of statements that get moved/added before
conditional.

[Bug tree-optimization/101256] [12 Regression] Wrong code with -O3 since r12-1841-g9fe9c45ae33a2df7

2021-06-29 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101256

Andrew Pinski  changed:

   What|Removed |Added

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

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

[Bug tree-optimization/101256] [12 Regression] Wrong code with -O3 since r12-1841-g9fe9c45ae33a2df7

2021-06-29 Thread rguenth at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101256

Richard Biener  changed:

   What|Removed |Added

   Target Milestone|--- |12.0

[Bug tree-optimization/101256] [12 Regression] Wrong code with -O3 since r12-1841-g9fe9c45ae33a2df7

2021-06-29 Thread marxin at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101256

Martin Liška  changed:

   What|Removed |Added

  Known to work||11.1.0
 Status|UNCONFIRMED |NEW
   Last reconfirmed||2021-06-29
  Known to fail||12.0
 Ever confirmed|0   |1