[Bug tree-optimization/102744] [12 regression] -O2 vectorization causes Wzero-length-array-bounds-2.c to fail on arc-elf

2021-10-14 Thread msebor at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102744

Martin Sebor  changed:

   What|Removed |Added

 CC||liuhongt at gcc dot gnu.org
   Last reconfirmed||2021-10-14
 Status|UNCONFIRMED |NEW
 Blocks||102706
   Target Milestone|--- |12.0
   Keywords||diagnostic
 Ever confirmed|0   |1

--- Comment #1 from Martin Sebor  ---
Here's the relevant part of the test with line numbers:

68  char cbuf1[1 * sizeof (struct C)];
69  char cbuf2[2 * sizeof (struct C)] = { };
70  
71  void test_C_global_buf (void)
72  {
73struct C *p = (struct C*)&cbuf1;
   ...
84p = (struct C*)&cbuf2;
   ...
90p->b2.a[ 0].i = 0;
91p->b2.a[ 1].i = 0;
92p->b2.a[ 2].i = 0; // { dg-warning "\\\[-Warray-bounds" }
93p->b2.a[ 3].i = 0; // { dg-warning "\\\[-Warray-bounds" }
94sink (p);

ad the output is below.  We get the two -Warray-bounds instances as expected;
they are issued before vectorization.  Then we get an additional
-Wstringop-overflow for the valid store on line 90 from the strlen pass thanks
to the four stores having been vectorized.  So the problem is basically the
same as in one of the other reports.  I hesistate to mark this a dupe only
because it will need its own suppression (CC'ing Hongtao as a heads up).

As an aside, these regressions will no doubt make the warnings pretty confusing
to users.  We (i.e., I) should try to come up with a fix before GCC 12 goes out
the door.  I don't expect to have the time to to get to it before stage 1 ends.

/src/gcc/master/gcc/testsuite/gcc.dg/Wzero-length-array-bounds-2.c:92:10:
warning: array subscript 2 is above array bounds of 'struct A[0]'
[-Warray-bounds]
   92 |   p->b2.a[ 2].i = 0; // { dg-warning "\\\[-Warray-bounds" }
  |   ~~~^~~~
/src/gcc/master/gcc/testsuite/gcc.dg/Wzero-length-array-bounds-2.c:10:28: note:
while referencing 'a'
   10 | struct B { int j; struct A a[0]; };
  |^
/src/gcc/master/gcc/testsuite/gcc.dg/Wzero-length-array-bounds-2.c:93:10:
warning: array subscript 3 is above array bounds of 'struct A[0]'
[-Warray-bounds]
   93 |   p->b2.a[ 3].i = 0; // { dg-warning "\\\[-Warray-bounds" }
  |   ~~~^~~~
/src/gcc/master/gcc/testsuite/gcc.dg/Wzero-length-array-bounds-2.c:10:28: note:
while referencing 'a'
   10 | struct B { int j; struct A a[0]; };
  |^
/src/gcc/master/gcc/testsuite/gcc.dg/Wzero-length-array-bounds-2.c:90:17:
warning: writing 8 bytes into a region of size 0 [-Wstringop-overflow=]
   90 |   p->b2.a[ 0].i = 0;
  |   ~~^~~
/src/gcc/master/gcc/testsuite/gcc.dg/Wzero-length-array-bounds-2.c:69:6: note:
at offset 16 into destination object 'cbuf2' of size 16
   69 | char cbuf2[2 * sizeof (struct C)] = { };
  |  ^


Referenced Bugs:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102706
[Bug 102706] [12 regression] -O2 vectorization causes regression in
Warray-bounds-48.c on many targets

[Bug tree-optimization/102744] [12 regression] -O2 vectorization causes Wzero-length-array-bounds-2.c to fail on arc-elf

2021-10-14 Thread crazylht at gmail dot com via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102744

--- Comment #2 from Hongtao.liu  ---
(In reply to Martin Sebor from comment #1)
> Here's the relevant part of the test with line numbers:
> 
> 68char cbuf1[1 * sizeof (struct C)];
> 69char cbuf2[2 * sizeof (struct C)] = { };
> 70
> 71void test_C_global_buf (void)
> 72{
> 73  struct C *p = (struct C*)&cbuf1;
>...
> 84  p = (struct C*)&cbuf2;
>...
> 90  p->b2.a[ 0].i = 0;
> 91  p->b2.a[ 1].i = 0;
> 92  p->b2.a[ 2].i = 0; // { dg-warning "\\\[-Warray-bounds" }
> 93  p->b2.a[ 3].i = 0; // { dg-warning "\\\[-Warray-bounds" }
> 94  sink (p);
> 
> ad the output is below.  We get the two -Warray-bounds instances as
> expected; they are issued before vectorization.  Then we get an additional
> -Wstringop-overflow for the valid store on line 90 from the strlen pass
> thanks to the four stores having been vectorized.  So the problem is
What i got is 2 store vectorized which cause extra -Wstringop-overflow=
For x86 which have 4 stores vectorized, there's no extra warning.
Should be behavior of extra warning for 2 store vectorized but not 4 store
vectorized be expected

Here is dump for arc-elf
void test_C_global_buf ()
{
  int * vectp.23;
  vector(2) int * vectp_cbuf2.22;
  int * vectp.21;
  vector(2) int * vectp_cbuf2.20;
  int * vectp.19;
  vector(2) int * vectp_cbuf1.18;
  int * vectp.17;
  vector(2) int * vectp_cbuf1.16;
  int * _22;

   [local count: 1073741824]:
  MEM  [(int *)&cbuf1] = { 0, 0 };
  MEM[(struct C *)&cbuf1].b1.a[1].i = 0;
  sink (&cbuf1);
  MEM  [(int *)&cbuf1 + 8B] = { 0, 0 };
  sink (&cbuf1);
  MEM  [(int *)&cbuf2] = { 0, 0 };
  MEM[(struct C *)&cbuf2].b1.a[1].i = 0;
  sink (&cbuf2);
  MEM  [(int *)&cbuf2 + 8B] = { 0, 0 };
  _22 = &MEM[(struct C *)&cbuf2].b2.a[0].i + 8;
  MEM  [(int *)_22] = { 0, 0 };
  sink (&cbuf2);
  return;


And dump for x86

void test_C_global_buf ()
{
  int * vectp.33;
  vector(4) int * vectp_cbuf2.32;
  int * vectp.31;
  vector(2) int * vectp_cbuf2.30;
  int * vectp.29;
  vector(2) int * vectp_cbuf1.28;
  int * vectp.27;
  vector(2) int * vectp_cbuf1.26;

   [local count: 1073741824]:
  MEM  [(int *)&cbuf1] = { 0, 0 };
  MEM[(struct C *)&cbuf1].b1.a[1].i = 0;
  sink (&cbuf1);
  MEM  [(int *)&cbuf1 + 8B] = { 0, 0 };
  sink (&cbuf1);
  MEM  [(int *)&cbuf2] = { 0, 0 };
  MEM[(struct C *)&cbuf2].b1.a[1].i = 0;
  sink (&cbuf2);
  MEM  [(int *)&cbuf2 + 8B] = { 0, 0, 0, 0 };
  sink (&cbuf2);
  return;

}

[Bug tree-optimization/102744] [12 regression] -O2 vectorization causes Wzero-length-array-bounds-2.c to fail on arc-elf

2021-10-19 Thread cvs-commit at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102744

--- Comment #3 from CVS Commits  ---
The master branch has been updated by hongtao Liu :

https://gcc.gnu.org/g:3c8d8c0be95e99dc0cba7f6fad2429243582119f

commit r12-4523-g3c8d8c0be95e99dc0cba7f6fad2429243582119f
Author: liuhongt 
Date:   Thu Oct 14 09:31:03 2021 +0800

Adjust testcase for O2 vectorization.

As discussed in [1], this patch add xfail/target selector to those
testcases, also make a copy of them so that they can be tested w/o
vectorization.

Newly added xfail/target selectors are used to check the vectorization
capability of continuous byte/double bytes storage, these scenarios
are exactly the part of the testcases that regressed after O2
vectorization.

[1] https://gcc.gnu.org/pipermail/gcc-patches/2021-October/581456.html.

2021-10-19  Hongtao Liu  
Kewen Lin  

gcc/ChangeLog

* doc/sourcebuild.texi (Effective-Target Keywords): Document
vect_slp_v2qi_store, vect_slp_v4qi_store, vect_slp_v8qi_store,
vect_slp_v16qi_store, vect_slp_v2hi_store,
vect_slp_v4hi_store, vect_slp_v2si_store, vect_slp_v4si_store.

gcc/testsuite/ChangeLog

PR middle-end/102722
PR middle-end/102697
PR middle-end/102462
PR middle-end/102706
PR middle-end/102744
* c-c++-common/Wstringop-overflow-2.c: Adjust testcase with new
xfail/target selector.
* gcc.dg/Warray-bounds-51.c: Ditto.
* gcc.dg/Warray-parameter-3.c: Ditto.
* gcc.dg/Wstringop-overflow-14.c: Ditto.
* gcc.dg/Wstringop-overflow-21.c: Ditto.
* gcc.dg/Wstringop-overflow-68.c: Ditto.
* gcc.dg/Wstringop-overflow-76.c: Ditto.
* gcc.dg/Warray-bounds-48.c: Ditto.
* gcc.dg/Wzero-length-array-bounds-2.c: Ditto.
* lib/target-supports.exp (check_vect_slp_aligned_store_usage):
New function.
(check_effective_target_vect_slp_v2qi_store): Ditto.
(check_effective_target_vect_slp_v4qi_store): Ditto.
(check_effective_target_vect_slp_v8qi_store): Ditto.
(check_effective_target_vect_slp_v16qi_store): Ditto.
(check_effective_target_vect_slp_v2hi_store): Ditto.
(check_effective_target_vect_slp_v4hi_store): Ditto.
(check_effective_target_vect_slp_v2si_store): Ditto.
(check_effective_target_vect_slp_v4si_store): Ditto.
* c-c++-common/Wstringop-overflow-2-novec.c: New test.
* gcc.dg/Warray-bounds-51-novec.c: New test.
* gcc.dg/Warray-bounds-48-novec.c: New test.
* gcc.dg/Warray-parameter-3-novec.c: New test.
* gcc.dg/Wstringop-overflow-14-novec.c: New test.
* gcc.dg/Wstringop-overflow-21-novec.c: New test.
* gcc.dg/Wstringop-overflow-76-novec.c: New test.
* gcc.dg/Wzero-length-array-bounds-2-novec.c: New test.

[Bug tree-optimization/102744] [12 regression] -O2 vectorization causes Wzero-length-array-bounds-2.c to fail on arc-elf

2022-01-19 Thread rguenth at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102744

Richard Biener  changed:

   What|Removed |Added

 Resolution|--- |FIXED
 Status|NEW |RESOLVED

--- Comment #4 from Richard Biener  ---
The testsuite fail has been resolved.  The general issue with vectorization or
store-merging vs. those diagnostics remains but was always present with
vectorization enabled.