Commit ad2a970f by Jakub Jelinek Committed by Jakub Jelinek

re PR tree-optimization/83444 (missing strlen optimization on a member array of a local struct)

	PR tree-optimization/83444
	* tree-ssa-strlen.c (strlen_check_and_optimize_stmt): For the
	character load case, if get_stridx on MEM_REF's operand doesn't
	look usable, retry with get_addr_stridx.

	* gcc.dg/strlenopt-38.c: New test.

From-SVN: r255835
parent 4c9aa2cf
2017-12-19 Jakub Jelinek <jakub@redhat.com>
PR tree-optimization/83444
* tree-ssa-strlen.c (strlen_check_and_optimize_stmt): For the
character load case, if get_stridx on MEM_REF's operand doesn't
look usable, retry with get_addr_stridx.
2017-12-19 Alexandre Oliva <aoliva@redhat.com>
PR debug/83422
......@@ -5,6 +5,9 @@
2017-12-19 Jakub Jelinek <jakub@redhat.com>
PR tree-optimization/83444
* gcc.dg/strlenopt-38.c: New test.
PR testsuite/83454
* gcc.dg/tree-ssa/cswtch-4.c: Require nonpic effective target.
* gcc.dg/tree-ssa/cswtch-5.c: Likewise.
......
......@@ -36,3 +36,14 @@ baz (void)
if (s.b[0] != 0)
abort ();
}
void
boo (void)
{
struct S s;
strcpy (s.b, "012");
strcpy (s.c, "");
strcpy (s.b, s.c);
if (strlen (s.b) != 0)
abort ();
}
......@@ -3155,14 +3155,27 @@ strlen_check_and_optimize_stmt (gimple_stmt_iterator *gsi)
{
tree off = integer_zero_node;
unsigned HOST_WIDE_INT coff = 0;
int idx = -1;
int idx = 0;
tree rhs1 = gimple_assign_rhs1 (stmt);
if (code == MEM_REF)
{
idx = get_stridx (TREE_OPERAND (rhs1, 0));
off = TREE_OPERAND (rhs1, 1);
if (idx > 0)
{
strinfo *si = get_strinfo (idx);
if (si
&& si->nonzero_chars
&& TREE_CODE (si->nonzero_chars) == INTEGER_CST
&& (wi::to_widest (si->nonzero_chars)
>= wi::to_widest (off)))
off = TREE_OPERAND (rhs1, 1);
else
/* This case is not useful. See if get_addr_stridx
returns something usable. */
idx = 0;
}
}
else
if (idx <= 0)
idx = get_addr_stridx (rhs1, NULL_TREE, &coff);
if (idx > 0)
{
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment