[Bug tree-optimization/86955] strlen of a known string in member array plus offset not folded

2021-11-23 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86955

Andrew Pinski  changed:

   What|Removed |Added

   Severity|normal  |enhancement
   Last reconfirmed|2019-06-07 00:00:00 |2021-11-23

--- Comment #3 from Andrew Pinski  ---
(In reply to Martin Sebor from comment #1)
> The reason is that the strlen pass sees the following:
Note we get now (after r12-5465-g911b633803):
  _1 = _4(D)->a;
  __builtin_memcpy (_1, "123", 4);
  _2 = p_4(D) + 2;
  _3 = __builtin_strlen (_2);


But strlen pass still does not understand p_4(D)+4 is the same as _4(D)->a[1]

[Bug tree-optimization/86955] strlen of a known string in member array plus offset not folded

2019-06-07 Thread msebor at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86955

Martin Sebor  changed:

   What|Removed |Added

 Status|UNCONFIRMED |NEW
   Last reconfirmed||2019-06-07
 Ever confirmed|0   |1
  Known to fail||10.0, 5.1.0, 6.4.0, 7.3.0,
   ||8.2.0, 9.1.0

--- Comment #2 from Martin Sebor  ---
Confirming.  The following is also not folded.  

  struct S { char n, a[8]; };

  void f4 (struct S *s)
  {
__builtin_strcpy (s->a, "123");
if (__builtin_strlen (>a[1]) != 2)
  __builtin_abort ();
  }

The pass sees that the strlen argument _2 is defined to _4(D)->a[1], and it
has a record of of the length of _4(D)->a, so it should be able to compute
the length.  It doesn't because the get_stridx() only handles POINTER_PLUS_EXPR
and not ARRAY_REF or COMPONENT_REF.  Handling that shouldn't be difficult.

;; Function f4 (f4, funcdef_no=0, decl_uid=1909, cgraph_uid=1, symbol_order=0)

f4 (struct S * s)
{
  char[8] * _1;
  char * _2;
  long unsigned int _3;

   [local count: 1073741824]:
  _1 = _4(D)->a;
  __builtin_memcpy (_1, "123", 4);
  _2 = _4(D)->a[1];
  _3 = __builtin_strlen (_2);
  if (_3 != 2)
goto ; [0.00%]
  else
goto ; [100.00%]

   [count: 0]:
  __builtin_abort ();

   [local count: 1073741824]:
  return;

}

[Bug tree-optimization/86955] strlen of a known string in member array plus offset not folded

2018-08-14 Thread msebor at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=86955

Martin Sebor  changed:

   What|Removed |Added

   Keywords||missed-optimization
 Blocks||83819

--- Comment #1 from Martin Sebor  ---
The reason is that the strlen pass sees the following:

  _1 = _4(D)->a;
  __builtin_memcpy (_1, "123", 4);
  _2 = [(void *)p_4(D) + 2B];
  _3 = __builtin_strlen (_2);

and it doesn't understand that [(void *)p_4(D) + 2B] actually refers to
p_4(D)->a.


Referenced Bugs:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83819
[Bug 83819] [meta-bug] missing strlen optimizations