Commit 65f2d1ee by Prathamesh Kulkarni Committed by Prathamesh Kulkarni

re PR tree-optimization/83501 (strlen(a) not folded after strcpy(a, "..."))

2018-01-03  Prathamesh Kulkarni  <prathamesh.kulkarni@linaro.org>

	PR tree-optimization/83501
	* tree-ssa-strlen.c (get_string_cst): New.
	(handle_char_store): Call get_string_cst.

testsuite/
	* gcc.dg/tree-ssa/pr83501.c: New test.

From-SVN: r256180
parent ce473498
2018-01-03 Prathamesh Kulkarni <prathamesh.kulkarni@linaro.org>
PR tree-optimization/83501
* tree-ssa-strlen.c (get_string_cst): New.
(handle_char_store): Call get_string_cst.
2018-01-03 Martin Liska <mliska@suse.cz> 2018-01-03 Martin Liska <mliska@suse.cz>
PR tree-optimization/83593 PR tree-optimization/83593
......
2018-01-03 Prathamesh Kulkarni <prathamesh.kulkarni@linaro.org>
PR tree-optimization/83501
* gcc.dg/tree-ssa/pr83501-1.c: New test.
2018-01-03 Nathan Sidwell <nathan@acm.org> 2018-01-03 Nathan Sidwell <nathan@acm.org>
PR c++/83667 PR c++/83667
......
/* { dg-do compile } */
/* { dg-options "-O2 -fdump-tree-strlen" } */
char a[4];
void f (void)
{
__builtin_strcpy (a, "abc");
if (__builtin_strlen (a) != 3)
__builtin_abort ();
}
/* { dg-final { scan-tree-dump-not "__builtin_strlen" "strlen" } } */
...@@ -2772,6 +2772,21 @@ handle_pointer_plus (gimple_stmt_iterator *gsi) ...@@ -2772,6 +2772,21 @@ handle_pointer_plus (gimple_stmt_iterator *gsi)
} }
} }
/* Check if RHS is string_cst possibly wrapped by mem_ref. */
static tree
get_string_cst (tree rhs)
{
if (TREE_CODE (rhs) == MEM_REF
&& integer_zerop (TREE_OPERAND (rhs, 1)))
{
rhs = TREE_OPERAND (rhs, 0);
if (TREE_CODE (rhs) == ADDR_EXPR)
rhs = TREE_OPERAND (rhs, 0);
}
return (TREE_CODE (rhs) == STRING_CST) ? rhs : NULL_TREE;
}
/* Handle a single character store. */ /* Handle a single character store. */
static bool static bool
...@@ -2927,11 +2942,11 @@ handle_char_store (gimple_stmt_iterator *gsi) ...@@ -2927,11 +2942,11 @@ handle_char_store (gimple_stmt_iterator *gsi)
} }
} }
else if (idx == 0 else if (idx == 0
&& TREE_CODE (gimple_assign_rhs1 (stmt)) == STRING_CST && (rhs = get_string_cst (gimple_assign_rhs1 (stmt)))
&& ssaname == NULL_TREE && ssaname == NULL_TREE
&& TREE_CODE (TREE_TYPE (lhs)) == ARRAY_TYPE) && TREE_CODE (TREE_TYPE (lhs)) == ARRAY_TYPE)
{ {
size_t l = strlen (TREE_STRING_POINTER (gimple_assign_rhs1 (stmt))); size_t l = strlen (TREE_STRING_POINTER (rhs));
HOST_WIDE_INT a = int_size_in_bytes (TREE_TYPE (lhs)); HOST_WIDE_INT a = int_size_in_bytes (TREE_TYPE (lhs));
if (a > 0 && (unsigned HOST_WIDE_INT) a > l) if (a > 0 && (unsigned HOST_WIDE_INT) a > l)
{ {
......
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