Bug 102744 - [12 regression] -O2 vectorization causes Wzero-length-array-bounds-2.c to fail on arc-elf
Summary: [12 regression] -O2 vectorization causes Wzero-length-array-bounds-2.c to fai...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: tree-optimization (show other bugs)
Version: 12.0
: P3 normal
Target Milestone: 12.0
Assignee: Not yet assigned to anyone
URL:
Keywords: diagnostic
Depends on:
Blocks: 102706
  Show dependency treegraph
 
Reported: 2021-10-14 13:48 UTC by Jeffrey A. Law
Modified: 2022-01-19 08:52 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2021-10-14 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jeffrey A. Law 2021-10-14 13:48:47 UTC
Starting with the patch to vectorize at -O2, gcc.dg/Wzero-length-array-bounds-2.c has started failing on arc-elf.  We're getting an additional diagnostic:

/home/jlaw/test/gcc/gcc/testsuite/gcc.dg/Wzero-length-array-bounds-2.c:90:17: warning: writing 8 bytes into a region of size 0 [-Wstringop-overflow=]

This may well be the same underlying issue as the other problems we're chasing in this space, if that turns out to be the case, just mark this is a duplicate.  I haven't debugged it in any notable way.  It should reproduce with just a cross compiler.
Comment 1 Martin Sebor 2021-10-14 16:55:13 UTC
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	{
    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 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)] = { };
      |      ^~~~~
Comment 2 Hongtao.liu 2021-10-15 01:31:18 UTC
(In reply to Martin Sebor from comment #1)
> 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	{
>     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;

  <bb 2> [local count: 1073741824]:
  MEM <vector(2) int> [(int *)&cbuf1] = { 0, 0 };
  MEM[(struct C *)&cbuf1].b1.a[1].i = 0;
  sink (&cbuf1);
  MEM <vector(2) int> [(int *)&cbuf1 + 8B] = { 0, 0 };
  sink (&cbuf1);
  MEM <vector(2) int> [(int *)&cbuf2] = { 0, 0 };
  MEM[(struct C *)&cbuf2].b1.a[1].i = 0;
  sink (&cbuf2);
  MEM <vector(2) int> [(int *)&cbuf2 + 8B] = { 0, 0 };
  _22 = &MEM[(struct C *)&cbuf2].b2.a[0].i + 8;
  MEM <vector(2) int> [(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;

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

}
Comment 3 GCC Commits 2021-10-20 02:13:36 UTC
The master branch has been updated by hongtao Liu <liuhongt@gcc.gnu.org>:

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

commit r12-4523-g3c8d8c0be95e99dc0cba7f6fad2429243582119f
Author: liuhongt <hongtao.liu@intel.com>
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  <hongtao.liu@intel.com>
                Kewen Lin  <linkw@linux.ibm.com>
    
    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.
Comment 4 Richard Biener 2022-01-19 08:52:56 UTC
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.