[Bug middle-end/71315] missing strlen optimization on a POINTER_PLUS expression

2017-02-15 Thread msebor at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71315

Martin Sebor  changed:

   What|Removed |Added

 Status|UNCONFIRMED |RESOLVED
   See Also||https://gcc.gnu.org/bugzill
   ||a/show_bug.cgi?id=79547
 Resolution|--- |FIXED

--- Comment #5 from Martin Sebor  ---
Resolving the original bug as fixed.  I've raised bug 79547 for the problem
pointed out in comment #3.

[Bug middle-end/71315] missing strlen optimization on a POINTER_PLUS expression

2016-07-20 Thread jakub at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71315

Jakub Jelinek  changed:

   What|Removed |Added

 CC||jakub at gcc dot gnu.org

--- Comment #4 from Jakub Jelinek  ---
This is alias analysis deficiency.  It considers s escaped, because [0] is
passed to a function (strlen), but __builtin_strlen really is not allowed to
save the argument into some global var that e.g. the following call to f
function could then use to modify it.

The strlen pass just uses the alias oracle to query if it needs to invalidate
remembered string lengths, in particular on the f () call.  As the alias oracle
considers s to be escaped, it returns that the f () call might change it (which
it indeed could if instead of __builtin_strlen one used some function with the
same prototype, but on which the compiler can't make any assumptions).

[Bug middle-end/71315] missing strlen optimization on a POINTER_PLUS expression

2016-07-20 Thread prathamesh3492 at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71315

prathamesh3492 at gcc dot gnu.org changed:

   What|Removed |Added

 CC||prathamesh3492 at gcc dot 
gnu.org

--- Comment #3 from prathamesh3492 at gcc dot gnu.org ---
Hi,
As of r238513, gcc folds call to strlen into constant.
void f(unsigned x)

void g()
{
  char s[] = "hello";
  f (__builtin_strlen (s + 1));
}

optimized dump shows:
;; Function g (g, funcdef_no=0, decl_uid=1753, cgraph_uid=0, symbol_order=0)

Optimizing: _1 = __builtin_strlen ([(void *) + 1B]);
into: _1 = 4;
g ()
{
  char s[6];
  long unsigned int _1;
  unsigned int _2;

  :
  s = "hello";
  _1 = 4;
  _2 = (unsigned int) _1;
  f (_2);
  s ={v} {CLOBBER};
  return;

}

However there seems to be another issue, if there are repeated
calls to strlen() with same arg, only the first call is folded.
For example consider following case:

void f (unsigned);

void g (void)
{
char s[] = "hello";
f (__builtin_strlen (s));
f (__builtin_strlen (s));
}

Only the first call to __builtin_strlen() is folded to 5,
the second one isn't.
Optimized dump shows:
;; Function g (g, funcdef_no=0, decl_uid=1753, cgraph_uid=0, symbol_order=0)

Optimizing: _1 = __builtin_strlen ();
into: _1 = 5;
g ()
{
  char s[6];
  long unsigned int _1;
  unsigned int _2;
  long unsigned int _3;
  unsigned int _4;

  :
  s = "hello";
  _1 = 5;
  _2 = (unsigned int) _1;
  f (_2);
  _3 = __builtin_strlen ();
  _4 = (unsigned int) _3;
  f (_4);
  s ={v} {CLOBBER};
  return;

}

clang seems to fold both the calls to 5.

Thanks,
Prathamesh

[Bug middle-end/71315] missing strlen optimization on a POINTER_PLUS expression

2016-05-27 Thread msebor at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71315

--- Comment #2 from Martin Sebor  ---
I pasted the wrong test case in comment #0.  The correct test case is as
follows:

void f (unsigned);

void g (void)
{
char s[] = "1234";

f (__builtin_strlen (s + 1));
f (__builtin_strlen (s + 1));
}

[Bug middle-end/71315] missing strlen optimization on a POINTER_PLUS expression

2016-05-27 Thread msebor at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=71315

Martin Sebor  changed:

   What|Removed |Added

   Keywords||missed-optimization
  Known to fail||4.5.3, 4.8.3, 4.9.3, 5.3.0,
   ||6.1.0, 7.0

--- Comment #1 from Martin Sebor  ---
This optimization was never performed (going as far back as 4.5.3).