aboutsummaryrefslogtreecommitdiff
path: root/gcc/tree-ssa-strlen.c
diff options
context:
space:
mode:
authorPeter Bergner <bergner@vnet.ibm.com>2016-08-03 17:42:15 +0000
committerPeter Bergner <bergner@vnet.ibm.com>2016-08-03 17:42:15 +0000
commit3055bfa7109d64b711c72e2091646fa3caa999f2 (patch)
treee217aa2f523fcc0b9b1b82aa54e06cb20c33bb9b /gcc/tree-ssa-strlen.c
parent6dc26956185ac7fa84bf72036c4f9fc258078241 (diff)
parent9292dc98baf244da9c72b5c1c74ab87d961c381d (diff)
Merge up to 239078.ibm/gcc-4_9-branch
Upstream FSF 4.9 release branch is now closed. * REVISION: Update subversion id. git-svn-id: https://gcc.gnu.org/svn/gcc/branches/ibm/gcc-4_9-branch@239087 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/tree-ssa-strlen.c')
-rw-r--r--gcc/tree-ssa-strlen.c47
1 files changed, 45 insertions, 2 deletions
diff --git a/gcc/tree-ssa-strlen.c b/gcc/tree-ssa-strlen.c
index 8d99a31d5df..bd6cbe82e82 100644
--- a/gcc/tree-ssa-strlen.c
+++ b/gcc/tree-ssa-strlen.c
@@ -768,6 +768,49 @@ find_equal_ptrs (tree ptr, int idx)
}
}
+/* Return true if STMT is a call to a builtin function with the right
+ arguments and attributes that should be considered for optimization
+ by this pass. */
+
+static bool
+valid_builtin_call (gimple stmt)
+{
+ if (!gimple_call_builtin_p (stmt, BUILT_IN_NORMAL))
+ return false;
+
+ tree callee = gimple_call_fndecl (stmt);
+ switch (DECL_FUNCTION_CODE (callee))
+ {
+ case BUILT_IN_STRCHR:
+ case BUILT_IN_STRLEN:
+ /* The above functions should be pure. Punt if they aren't. */
+ if (gimple_vdef (stmt) || gimple_vuse (stmt) == NULL_TREE)
+ return false;
+ break;
+
+ case BUILT_IN_MEMCPY:
+ case BUILT_IN_MEMCPY_CHK:
+ case BUILT_IN_MEMPCPY:
+ case BUILT_IN_MEMPCPY_CHK:
+ case BUILT_IN_STPCPY:
+ case BUILT_IN_STPCPY_CHK:
+ case BUILT_IN_STRCAT:
+ case BUILT_IN_STRCAT_CHK:
+ case BUILT_IN_STRCPY:
+ case BUILT_IN_STRCPY_CHK:
+ /* The above functions should be neither const nor pure. Punt if they
+ aren't. */
+ if (gimple_vdef (stmt) == NULL_TREE || gimple_vuse (stmt) == NULL_TREE)
+ return false;
+ break;
+
+ default:
+ break;
+ }
+
+ return true;
+}
+
/* If the last .MEM setter statement before STMT is
memcpy (x, y, strlen (y) + 1), the only .MEM use of it is STMT
and STMT is known to overwrite x[strlen (x)], adjust the last memcpy to
@@ -842,7 +885,7 @@ adjust_last_stmt (strinfo si, gimple stmt, bool is_strcat)
return;
}
- if (!gimple_call_builtin_p (last.stmt, BUILT_IN_NORMAL))
+ if (!valid_builtin_call (last.stmt))
return;
callee = gimple_call_fndecl (last.stmt);
@@ -1827,7 +1870,7 @@ strlen_optimize_stmt (gimple_stmt_iterator *gsi)
if (is_gimple_call (stmt))
{
tree callee = gimple_call_fndecl (stmt);
- if (gimple_call_builtin_p (stmt, BUILT_IN_NORMAL))
+ if (valid_builtin_call (stmt))
switch (DECL_FUNCTION_CODE (callee))
{
case BUILT_IN_STRLEN: