From: Martin Liska Date: Wed, 27 Dec 2017 09:30:14 +0000 (+0100) Subject: Assign result of get_string_lenth to a SSA_NAME (PR tree-optimization/83552). X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=96863f32b5d83961fc1cb073707f0cf53a475639;p=gcc.git Assign result of get_string_lenth to a SSA_NAME (PR tree-optimization/83552). 2017-12-27 Martin Liska PR tree-optimization/83552 * tree-ssa-strlen.c (fold_strstr_to_strncmp): Assign result of get_string_lenth to a SSA_NAME if not a GIMPLE value. 2017-12-27 Martin Liska PR tree-optimization/83552 * gcc.dg/pr83552.c: New test. From-SVN: r256009 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index d14bd93542d..5747358acef 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2017-12-27 Martin Liska + + PR tree-optimization/83552 + * tree-ssa-strlen.c (fold_strstr_to_strncmp): Assign result + of get_string_lenth to a SSA_NAME if not a GIMPLE value. + 2017-12-27 Tom de Vries * config/nvptx/nvptx.c (nvptx_option_override): Disable diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 14e8e3f0370..c03e6e1a440 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2017-12-27 Martin Liska + + PR tree-optimization/83552 + * gcc.dg/pr83552.c: New test. + 2017-12-26 Thomas Koenig PR fortran/83540 diff --git a/gcc/testsuite/gcc.dg/pr83552.c b/gcc/testsuite/gcc.dg/pr83552.c new file mode 100644 index 00000000000..993cdd26581 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr83552.c @@ -0,0 +1,13 @@ +/* PR tree-optimization/83364 */ +/* { dg-options "-O2" } */ + +char *b; +char d[100]; +void a (); +void +c (void) +{ + __builtin_strcat (d, "12345"); + if (__builtin_strstr (b, d) == b) + a (); +} diff --git a/gcc/tree-ssa-strlen.c b/gcc/tree-ssa-strlen.c index e812bd1e735..be6ab9f1e1b 100644 --- a/gcc/tree-ssa-strlen.c +++ b/gcc/tree-ssa-strlen.c @@ -3005,6 +3005,16 @@ fold_strstr_to_strncmp (tree rhs1, tree rhs2, gimple *stmt) { gimple_stmt_iterator gsi = gsi_for_stmt (call_stmt); tree strncmp_decl = builtin_decl_explicit (BUILT_IN_STRNCMP); + + if (!is_gimple_val (arg1_len)) + { + tree arg1_len_tmp = make_ssa_name (TREE_TYPE (arg1_len)); + gassign *arg1_stmt = gimple_build_assign (arg1_len_tmp, + arg1_len); + gsi_insert_before (&gsi, arg1_stmt, GSI_SAME_STMT); + arg1_len = arg1_len_tmp; + } + gcall *strncmp_call = gimple_build_call (strncmp_decl, 3, arg0, arg1, arg1_len); tree strncmp_lhs = make_ssa_name (integer_type_node);