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

rguenth at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Thu Jun 17 07:06:15 GMT 2021


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101105

Richard Biener <rguenth at gcc dot gnu.org> 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 <rguenth at gcc dot gnu.org> ---
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

  <bb 3> [local count: 214748368]:
  # g_40 = PHI <g_11(7), 3(2)>
  # ivtmp_2 = PHI <ivtmp_27(7), 4(2)>
  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 <bb 7>; [75.00%]
  else
    goto <bb 4>; [25.00%]

  <bb 7> [local count: 161061274]:
  goto <bb 3>; [100.00%]

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

and vect produces

  <bb 3> [local count: 214748368]:
  # g_40 = PHI <g_11(7), 3(2)>
  # ivtmp_2 = PHI <ivtmp_27(7), 4(2)>
  # ivtmp_48 = PHI <ivtmp_26(7), _19(2)>
  # ivtmp_32 = PHI <ivtmp_12(7), 0(2)>
  _42 = b[0][1];
  MEM <vector(4) int> [(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 <bb 7>; [75.00%]
  else
    goto <bb 4>; [25.00%]

  <bb 7> [local count: 161061274]:
  goto <bb 3>; [100.00%]

  <bb 4> [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?


More information about the Gcc-bugs mailing list