re PR tree-optimization/79547 (duplicate strlen calls with same argument not folded)
authorRichard Biener <rguenther@suse.de>
Fri, 21 Apr 2017 12:47:02 +0000 (12:47 +0000)
committerRichard Biener <rguenth@gcc.gnu.org>
Fri, 21 Apr 2017 12:47:02 +0000 (12:47 +0000)
2017-04-21  Richard Biener  <rguenther@suse.de>

PR tree-optimization/79547
* tree-ssa-structalias.c (find_func_aliases_for_builtin_call):
Handle strlen, strcmp, strncmp, strcasecmp, strncasecmp, memcmp,
bcmp, strspn, strcspn, __builtin_object_size and __builtin_constant_p
without any constraints.

* gcc.dg/tree-ssa/strlen-2.c: New testcase.

From-SVN: r247062

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

index 359273ef092765a28f8894fdf0dc37d51ea2c6b6..30b22d6e55dd0c6479809892e872eb97bf31ef5a 100644 (file)
@@ -1,3 +1,11 @@
+2017-04-21  Richard Biener  <rguenther@suse.de>
+
+       PR tree-optimization/79547
+       * tree-ssa-structalias.c (find_func_aliases_for_builtin_call):
+       Handle strlen, strcmp, strncmp, strcasecmp, strncasecmp, memcmp,
+       bcmp, strspn, strcspn, __builtin_object_size and __builtin_constant_p
+       without any constraints.
+
 2017-04-21  Richard Biener  <rguenther@suse.de>
 
        PR tree-optimization/78847
index 414f27972bf773b50d1caa0eae9c006cf30d1fe5..84d1074c8d4f90172a44ce57afe1bac52714851c 100644 (file)
@@ -1,3 +1,8 @@
+2017-04-21  Richard Biener  <rguenther@suse.de>
+
+       PR tree-optimization/79547
+       * gcc.dg/tree-ssa/strlen-2.c: New testcase.
+
 2017-04-21  Richard Biener  <rguenther@suse.de>
 
        PR tree-optimization/78847
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/strlen-2.c b/gcc/testsuite/gcc.dg/tree-ssa/strlen-2.c
new file mode 100644 (file)
index 0000000..1bca06f
--- /dev/null
@@ -0,0 +1,15 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-strlen" } */
+
+void f (unsigned);
+
+void f3 (void)
+{
+  char s[] = "1234";
+
+  f (__builtin_strlen (s));
+  f (__builtin_strlen (s));
+  f (__builtin_strlen (s));
+}
+
+/* { dg-final { scan-tree-dump-times "strlen" 0 "strlen" } } */
index 77736f51153320f7dccc7a65097bd26918cd8317..7b1bf10e1cfaeedf3e27209383cdf8f44ce268c7 100644 (file)
@@ -4474,6 +4474,40 @@ find_func_aliases_for_builtin_call (struct function *fn, gcall *t)
            process_all_all_constraints (lhsc, rhsc);
          }
        return true;
+      /* Pure functions that return something not based on any object and
+         that use the memory pointed to by their arguments (but not
+        transitively).  */
+      case BUILT_IN_STRCMP:
+      case BUILT_IN_STRNCMP:
+      case BUILT_IN_STRCASECMP:
+      case BUILT_IN_STRNCASECMP:
+      case BUILT_IN_MEMCMP:
+      case BUILT_IN_BCMP:
+      case BUILT_IN_STRSPN:
+      case BUILT_IN_STRCSPN:
+       {
+         varinfo_t uses = get_call_use_vi (t);
+         make_any_offset_constraints (uses);
+         make_constraint_to (uses->id, gimple_call_arg (t, 0));
+         make_constraint_to (uses->id, gimple_call_arg (t, 1));
+         /* No constraints are necessary for the return value.  */
+         return true;
+       }
+      case BUILT_IN_STRLEN:
+       {
+         varinfo_t uses = get_call_use_vi (t);
+         make_any_offset_constraints (uses);
+         make_constraint_to (uses->id, gimple_call_arg (t, 0));
+         /* No constraints are necessary for the return value.  */
+         return true;
+       }
+      case BUILT_IN_OBJECT_SIZE:
+      case BUILT_IN_CONSTANT_P:
+       {
+         /* No constraints are necessary for the return value or the
+            arguments.  */
+         return true;
+       }
       /* Trampolines are special - they set up passing the static
         frame.  */
       case BUILT_IN_INIT_TRAMPOLINE: