Assign result of get_string_lenth to a SSA_NAME (PR tree-optimization/83552).
authorMartin Liska <mliska@suse.cz>
Wed, 27 Dec 2017 09:30:14 +0000 (10:30 +0100)
committerMartin Liska <marxin@gcc.gnu.org>
Wed, 27 Dec 2017 09:30:14 +0000 (09:30 +0000)
2017-12-27  Martin Liska  <mliska@suse.cz>

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  <mliska@suse.cz>

PR tree-optimization/83552
* gcc.dg/pr83552.c: New test.

From-SVN: r256009

gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/pr83552.c [new file with mode: 0644]
gcc/tree-ssa-strlen.c

index d14bd93542d7740e1970acb8d87df1b479cba75b..5747358acef5133500a6f10866ddd21fbd800071 100644 (file)
@@ -1,3 +1,9 @@
+2017-12-27  Martin Liska  <mliska@suse.cz>
+
+       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  <tom@codesourcery.com>
 
        * config/nvptx/nvptx.c (nvptx_option_override): Disable
index 14e8e3f03701608a117788c8b2a837db6b3eb9d4..c03e6e1a4401a320f90b7f0268cddbf76bf2af48 100644 (file)
@@ -1,3 +1,8 @@
+2017-12-27  Martin Liska  <mliska@suse.cz>
+
+       PR tree-optimization/83552
+       * gcc.dg/pr83552.c: New test.
+
 2017-12-26  Thomas Koenig  <tkoenig@gcc.gnu.org>
 
        PR fortran/83540
diff --git a/gcc/testsuite/gcc.dg/pr83552.c b/gcc/testsuite/gcc.dg/pr83552.c
new file mode 100644 (file)
index 0000000..993cdd2
--- /dev/null
@@ -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 ();
+}
index e812bd1e73501d4969543e8d53f6ea41186433c1..be6ab9f1e1b93021319e78320a328e7c25d3da55 100644 (file)
@@ -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);