[PATCH, MPX, 2/X] Pointers Checker [19/25] Strchr
Ilya Enkovich
enkovich.gnu@gmail.com
Mon Nov 18 13:12:00 GMT 2013
Hi,
Here is a patch to replace BUILT_IN_CHKP_BNDRET with assignment when optimizing strchr.
Thanks,
Ilya
--
2013-11-13 Ilya Enkovich <ilya.enkovich@intel.com>
* tree-ssa-strlen.c: Include tree-chkp.h.
(handle_builtin_strchr): Remove retbnd call
when strchr call is removed.
diff --git a/gcc/tree-ssa-strlen.c b/gcc/tree-ssa-strlen.c
index cfd7b00..711f5d7 100644
--- a/gcc/tree-ssa-strlen.c
+++ b/gcc/tree-ssa-strlen.c
@@ -40,6 +40,7 @@ along with GCC; see the file COPYING3. If not see
#include "gimple-pretty-print.h"
#include "params.h"
#include "expr.h"
+#include "tree-chkp.h"
/* A vector indexed by SSA_NAME_VERSION. 0 means unknown, positive value
is an index into strinfo vector, negative value stands for
@@ -961,6 +962,8 @@ handle_builtin_strchr (gimple_stmt_iterator *gsi)
tree src;
gimple stmt = gsi_stmt (*gsi);
tree lhs = gimple_call_lhs (stmt);
+ gimple retbnd_stmt = NULL;
+ tree retbnd = NULL;
if (lhs == NULL_TREE)
return;
@@ -1009,6 +1012,14 @@ handle_builtin_strchr (gimple_stmt_iterator *gsi)
TREE_TYPE (rhs)))
rhs = fold_convert_loc (loc, TREE_TYPE (lhs), rhs);
}
+
+ /* Remember passed and returned bounds if any. */
+ if (gimple_call_with_bounds_p (stmt))
+ {
+ retbnd = chkp_get_call_arg_bounds (gimple_call_arg (stmt, 0));
+ retbnd_stmt = chkp_retbnd_call_by_val (lhs);
+ }
+
if (!update_call_from_tree (gsi, rhs))
gimplify_and_update_call_from_tree (gsi, rhs);
stmt = gsi_stmt (*gsi);
@@ -1018,6 +1029,18 @@ handle_builtin_strchr (gimple_stmt_iterator *gsi)
fprintf (dump_file, "into: ");
print_gimple_stmt (dump_file, stmt, 0, TDF_SLIM);
}
+
+ /* Replace retbnd call with assignment. */
+ if (retbnd_stmt)
+ {
+ gimple_stmt_iterator ret_gsi = gsi_for_stmt (retbnd_stmt);
+
+ if (!update_call_from_tree (&ret_gsi, retbnd))
+ gimplify_and_update_call_from_tree (&ret_gsi, retbnd);
+ retbnd_stmt = gsi_stmt (ret_gsi);
+ update_stmt (retbnd_stmt);
+ }
+
if (si != NULL
&& si->endptr == NULL_TREE
&& !SSA_NAME_OCCURS_IN_ABNORMAL_PHI (lhs))
More information about the Gcc-patches
mailing list