[Bug tree-optimization/101105] [11/12 Regression] wrong code at -O3 on x86_64-linux-gnu

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

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

https://gcc.gnu.org/g:50374fdacbd121bc4a61b073e559208ff61bee06

commit r12-1765-g50374fdacbd121bc4a61b073e559208ff61bee06
Author: Richard Biener 
Date:   Wed Jun 23 12:43:03 2021 +0200

tree-optimization/101105 - fix runtime alias test optimization

We were ignoring DR_STEP for VF == 1 which is OK only in case
the scalar order is preserved or both DR steps are the same.

2021-06-23  Richard Biener  

PR tree-optimization/101105
* tree-vect-data-refs.c (vect_prune_runtime_alias_test_list):
Only ignore steps when they are equal or scalar order is preserved.

* gcc.dg/torture/pr101105.c: New testcase.

[Bug tree-optimization/101105] [11/12 Regression] wrong code at -O3 on x86_64-linux-gnu

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

--- Comment #5 from Richard Biener  ---
Created attachment 51055
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=51055=edit
patch

So like this.

[Bug tree-optimization/101105] [11/12 Regression] wrong code at -O3 on x86_64-linux-gnu

2021-06-23 Thread rsandifo at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101105

rsandifo at gcc dot gnu.org  changed:

   What|Removed |Added

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

--- Comment #4 from rsandifo at gcc dot gnu.org  
---
Mine.

[Bug tree-optimization/101105] [11/12 Regression] wrong code at -O3 on x86_64-linux-gnu

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

--- Comment #3 from Richard Biener  ---
So what happens is that vect_compile_time_alias fails to perform the offset
adjustment for the negative step DR

#(Data Ref: 
#  bb: 3 
#  stmt: b[g_40][0] = 0;
#  ref: b[g_40][0];
#  base_object: b;
#  Access function 0: 0
#  Access function 1: {3, +, -1}_1

which is done via

  /* For negative step, we need to adjust address range by TYPE_SIZE_UNIT
 bytes, e.g., int a[3] -> a[1] range is [a+4, a+16) instead of
 [a, a+12) */
  if (tree_int_cst_compare (DR_STEP (a->dr), size_zero_node) < 0)
{
  const_length_a = (-wi::to_poly_wide (segment_length_a)).force_uhwi ();
  offset_a -= const_length_a;
}

since we zero segment_length_a because of ignore_step_p.  But that adjustment
cannot be ignored.  I suppose we need to track a separate "offset segment
length"
for this purpose?

[Bug tree-optimization/101105] [11/12 Regression] wrong code at -O3 on x86_64-linux-gnu

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

Richard Biener  changed:

   What|Removed |Added

 CC|rguenther at suse dot de   |rguenth at gcc dot 
gnu.org,
   ||rsandifo at gcc dot gnu.org
 Status|UNCONFIRMED |NEW
 Ever confirmed|0   |1
   Last reconfirmed||2021-06-17

--- Comment #2 from Richard Biener  ---
Confirmed.

short a;
int b[5][4] = {2, 2};
int d;
short e(int f) { return f == 0 || a && f == 1 ? 0 : a; }
int main() {
  int g, h;
  g = 3;
  for (; g >= 0; g--) {
h = 3;
for (; h >= 0; h--)
  b[g][h] = b[0][1] && e(1);
  }
  d = b[0][1];
  if (d != 0)
__builtin_abort ();
  return 0;
}

after if-conversion we have

   [local count: 214748368]:
  # g_40 = PHI 
  # ivtmp_2 = PHI 
  b[g_40][2] = 0;
  b[g_40][3] = 0;
  b[g_40][1] = 0;
  _42 = b[0][1];
  b[g_40][0] = 0;
  g_11 = g_40 + -1;
  ivtmp_27 = ivtmp_2 - 1;
  if (ivtmp_27 != 0)
goto ; [75.00%]
  else
goto ; [25.00%]

   [local count: 161061274]:
  goto ; [100.00%]

   [local count: 53687093]:
  # _18 = PHI <_42(3)>
  d = _18;
  if (_18 != 0)

and vect produces

   [local count: 214748368]:
  # g_40 = PHI 
  # ivtmp_2 = PHI 
  # ivtmp_48 = PHI 
  # ivtmp_32 = PHI 
  _42 = b[0][1];
  MEM  [(int *)ivtmp_48] = { 0, 0, 0, 0 };
  ivtmp_31 = ivtmp_48 + 18446744073709551600(OVF);
  g_11 = g_40 + -1;
  ivtmp_27 = ivtmp_2 - 1;
  ivtmp_26 = ivtmp_48 + 18446744073709551600(OVF);
  ivtmp_12 = ivtmp_32 + 1;
  if (ivtmp_12 < 4)
goto ; [75.00%]
  else
goto ; [25.00%]

   [local count: 161061274]:
  goto ; [100.00%]

   [local count: 53687093]:
  # _18 = PHI <_42(3)>

We have

(Data Dep: 
#(Data Ref: 
#  bb: 3 
#  stmt: b[g_40][1] = 0;
#  ref: b[g_40][1];
#  base_object: b;
#  Access function 0: 1
#  Access function 1: {3, +, -1}_1
#)
#(Data Ref: 
#  bb: 3 
#  stmt: _42 = b[0][1];
#  ref: b[0][1];
#  base_object: b;
#  Access function 0: 1
#  Access function 1: 0
#)
  access_fn_A: 1
  access_fn_B: 1

 (subscript 
  iterations_that_access_an_element_twice_in_A: [0]
  last_conflict: scev_not_known
  iterations_that_access_an_element_twice_in_B: [0]
  last_conflict: scev_not_known
  (Subscript distance: 0 ))
  access_fn_A: {3, +, -1}_1
  access_fn_B: 0

 (subscript 
  iterations_that_access_an_element_twice_in_A: [-3]
  last_conflict: 1
  iterations_that_access_an_element_twice_in_B: [0]
  last_conflict: 1
  (Subscript distance: -3 ))
  loop nest: (1 )
)

and mark the DR for a runtime alias test.  But then

t3.c:8:12: note:   === vect_prune_runtime_alias_test_list ===
t3.c:8:12: note:   can tell at compile time that b[g_40][0] and b[0][1] do not
alias
t3.c:8:12: note:   improved number of alias checks from 1 to 0

as vect_compile_time_alias gets segment_lengths of zero (huh), since

  /* Step values are irrelevant for aliasing if the number of vector
 iterations is equal to the number of scalar iterations (which can
 happen for fully-SLP loops).  */
  bool ignore_step_p = known_eq (LOOP_VINFO_VECT_FACTOR (loop_vinfo), 1U);
...

  if (ignore_step_p)
{
  segment_length_a = size_zero_node;
  segment_length_b = size_zero_node;
}

but I'm not sure if a segment length of zero will do good in any case where
the alias check is needed?  Richard - that's your code, can you have a look?

[Bug tree-optimization/101105] [11/12 Regression] wrong code at -O3 on x86_64-linux-gnu

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

Andrew Pinski  changed:

   What|Removed |Added

   Keywords||wrong-code
Version|unknown |11.0
 Target||x86_64-linux-gnu
Summary|wrong code at -O3 on|[11/12 Regression] wrong
   |x86_64-linux-gnu|code at -O3 on
   ||x86_64-linux-gnu
   Target Milestone|--- |11.2