[Bug tree-optimization/83821] local aggregate initialization defeats strlen optimization

2019-10-16 Thread msebor at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83821

Martin Sebor  changed:

   What|Removed |Added

 Status|ASSIGNED|RESOLVED
  Known to work||10.0
 Resolution|--- |FIXED
   Target Milestone|--- |10.0
  Known to fail||7.3.0, 8.3.0, 9.2.0

--- Comment #7 from Martin Sebor  ---
Patch committed in r277080.

[Bug tree-optimization/83821] local aggregate initialization defeats strlen optimization

2019-10-16 Thread msebor at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83821

--- Comment #6 from Martin Sebor  ---
Author: msebor
Date: Wed Oct 16 19:24:36 2019
New Revision: 277080

URL: https://gcc.gnu.org/viewcvs?rev=277080&root=gcc&view=rev
Log:
PR tree-optimization/83821 - local aggregate initialization defeats strlen
optimization

gcc/ChangeLog:

PR tree-optimization/83821
* tree-ssa-strlen.c (maybe_invalidate): Add argument.  Consider
the length of a string when available.
(handle_builtin_memset) Add argument.
(handle_store, strlen_check_and_optimize_call): Same.
(check_and_optimize_stmt): Same.  Pass it to callees.

gcc/testsuite/ChangeLog:

PR tree-optimization/83821
* c-c++-common/Warray-bounds-4.c: Remove XFAIL.
* gcc.dg/strlenopt-82.c: New test.
* gcc.dg/strlenopt-83.c: Same.
* gcc.dg/strlenopt-84.c: Same.
* gcc.dg/strlenopt-85.c: Same.
* gcc.dg/strlenopt-86.c: Same.
* gcc.dg/tree-ssa/calloc-4.c: Same.
* gcc.dg/tree-ssa/calloc-5.c: Same.


Added:
trunk/gcc/testsuite/gcc.dg/strlenopt-82.c
trunk/gcc/testsuite/gcc.dg/strlenopt-83.c
trunk/gcc/testsuite/gcc.dg/strlenopt-84.c
trunk/gcc/testsuite/gcc.dg/strlenopt-85.c
trunk/gcc/testsuite/gcc.dg/strlenopt-86.c
trunk/gcc/testsuite/gcc.dg/tree-ssa/calloc-4.c
trunk/gcc/testsuite/gcc.dg/tree-ssa/calloc-5.c
Modified:
trunk/gcc/ChangeLog
trunk/gcc/testsuite/ChangeLog
trunk/gcc/testsuite/c-c++-common/Warray-bounds-4.c
trunk/gcc/tree-ssa-strlen.c

[Bug tree-optimization/83821] local aggregate initialization defeats strlen optimization

2019-10-15 Thread msebor at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83821

--- Comment #5 from Martin Sebor  ---
Updated patch for GCC 10:
https://gcc.gnu.org/ml/gcc-patches/2019-10/msg01038.html

[Bug tree-optimization/83821] local aggregate initialization defeats strlen optimization

2018-01-25 Thread msebor at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83821

--- Comment #4 from Martin Sebor  ---
(In reply to Leslie Zhai from comment #3)

In the case of mips64 (and a number of other targets) the missing optimization
is due to pr83543.

[Bug tree-optimization/83821] local aggregate initialization defeats strlen optimization

2018-01-22 Thread lesliezhai at llvm dot org.cn
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83821

Leslie Zhai  changed:

   What|Removed |Added

 CC||lesliezhai at llvm dot org.cn

--- Comment #3 from Leslie Zhai  ---
(In reply to Martin Sebor from comment #0)
> For the test case below, GCC optimizes the strlen call in f() but fails to
> do the same in g().  It appears because the maybe_invalidate() function in
> the pass considers the initialization of/assignment to b.i as possibly
> clobbering the value of b.s, not realizing that there is no way for the two
> members to alias.
> 
> $ cat z.c && gcc -O2 -S -fdump-tree-optimized=/dev/stdout z.c 
> #define STR "0123456789"
> 
> struct A
> {
>   char s[sizeof STR];
> };
> 
> void f (void)
> {
>   struct A a = { STR };
>   if (__builtin_strlen (a.s) != sizeof STR - 1)   // folded
> __builtin_abort ();   // eliminated
> }
> 
> struct B
> {
>   char s[sizeof STR];
>   int i;
> };
> 
> void g (void)
> {
>   struct B b = { STR, 123 };
>   if (__builtin_strlen (b.s) != sizeof STR - 1)   // not folded
> __builtin_abort ();   // not eliminated
> }
> 
> 
> ;; Function f (f, funcdef_no=0, decl_uid=1952, cgraph_uid=0, symbol_order=0)
> 
> f ()
> {
>[local count: 1073741825]:
>   return;
> 
> }
> 
> 
> 
> ;; Function g (g, funcdef_no=1, decl_uid=1959, cgraph_uid=1, symbol_order=1)
> 
> g ()
> {
>   struct B b;
>   long unsigned int _1;
> 
>[local count: 1073741825]:
>   b.s = "0123456789";
>   b.i = 123;
>   _1 = __builtin_strlen (&b.s);
>   if (_1 != 10)
> goto ; [0.00%]
>   else
> goto ; [99.96%]
> 
>[count: 0]:
>   __builtin_abort ();
> 
>[local count: 1073312327]:
>   b ={v} {CLOBBER};
>   return;
> 
> }


$ /opt/mips-gnu-git/bin/mips64-linux-gnu-gcc -v
Using built-in specs.
COLLECT_GCC=/opt/mips-gnu-git/bin/mips64-linux-gnu-gcc
COLLECT_LTO_WRAPPER=/opt/mips-gnu-git/libexec/gcc/mips64-linux-gnu/8.0.1/lto-wrapper
Target: mips64-linux-gnu
Configured with: ../configure --prefix=/opt/mips-gnu-git
--build=x86_64-redhat-linux-gnu --disable-decimal-float
--disable-dependency-tracking --disable-gold --disable-libgcj --disable-libgomp
--disable-libmpx --disable-libquadmath --disable-libssp
--disable-libunwind-exceptions --disable-shared --disable-silent-rules
--disable-sjlj-exceptions --disable-threads
--with-ld=/usr/bin/mips64-linux-gnu-ld --enable-__cxa_atexit
--enable-checking=release --enable-gnu-unique-object --enable-initfini-array
--enable-languages=c,c++ --enable-linker-build-id --enable-lto --enable-nls
--enable-obsolete --enable-plugin --enable-targets=all
--host=x86_64-redhat-linux-gnu --target=mips64-linux-gnu --with-newlib
--with-plugin-ld=/usr/bin/mips64-linux-gnu-ld --with-system-libunwind
--with-system-zlib --without-headers --with-arch=mips64r2 --with-abi=64
--with-arch_32=mips32r2 --with-fp-32=xx --enable-gnu-indirect-function
Thread model: single
gcc version 8.0.1 20180123 (experimental) (GCC)


But GCC also failed to optimize the strlen call in f() after applied your patch
$ /opt/mips-gnu-git/bin/mips64-linux-gnu-gcc -O2 -S
-fdump-tree-optimized=/dev/stdout z.c   

;; Function f (f, funcdef_no=0, decl_uid=1584, cgraph_uid=0, symbol_order=0)

f ()
{
  struct A a;
  long unsigned int _1;

   [local count: 1073741825]:
  a = *.LC0;
  _1 = __builtin_strlen (&a.s);
  if (_1 != 10)
goto ; [0.00%]
  else
goto ; [99.96%]

   [count: 0]:
  __builtin_abort ();

   [local count: 1073312327]:
  a ={v} {CLOBBER};
  return;

}



;; Function g (g, funcdef_no=1, decl_uid=1591, cgraph_uid=1, symbol_order=1)

g ()
{
  struct B b;
  long unsigned int _1;

   [local count: 1073741825]:
  b = *.LC1;
  _1 = __builtin_strlen (&b.s);
  if (_1 != 10)
goto ; [0.00%]
  else
goto ; [99.96%]

   [count: 0]:
  __builtin_abort ();

   [local count: 1073312327]:
  b ={v} {CLOBBER};
  return;

}

[Bug tree-optimization/83821] local aggregate initialization defeats strlen optimization

2018-01-12 Thread msebor at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83821

Martin Sebor  changed:

   What|Removed |Added

   Keywords||patch

--- Comment #2 from Martin Sebor  ---
Patch: https://gcc.gnu.org/ml/gcc-patches/2018-01/msg01131.html

[Bug tree-optimization/83821] local aggregate initialization defeats strlen optimization

2018-01-12 Thread msebor at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83821

Martin Sebor  changed:

   What|Removed |Added

 Status|UNCONFIRMED |ASSIGNED
   Last reconfirmed||2018-01-12
   Assignee|unassigned at gcc dot gnu.org  |msebor at gcc dot 
gnu.org
 Ever confirmed|0   |1

--- Comment #1 from Martin Sebor  ---
Testing a simple patch.