Discussion:
[PATCH, Pointer Bounds Checker 14/x] Passes [14/n] Optimize constant checks
Ilya Enkovich
2014-10-08 19:21:06 UTC
Permalink
Hi,

This patch adds a removal of checks known to always pass into checker optimization.

Thanks,
Ilya
--
2014-10-08 Ilya Enkovich <***@intel.com>

* tree-chkp.c (chkp_remove_check_if_pass): New.
(chkp_remove_constant_checks): New.
(chkp_opt_execute): Run constant check removal
algorithm.


diff --git a/gcc/tree-chkp.c b/gcc/tree-chkp.c
index c9b616b..ade546b 100644
--- a/gcc/tree-chkp.c
+++ b/gcc/tree-chkp.c
@@ -4828,6 +4828,46 @@ chkp_get_check_result (struct check_info *ci, tree bounds)
return res;
}

+/* Try to compare bounds value and address value
+ used in the check CI. If we can prove that check
+ always pass then remove it. */
+void
+chkp_remove_check_if_pass (struct check_info *ci)
+{
+ int result = 0;
+
+ if (dump_file && (dump_flags & TDF_DETAILS))
+ {
+ fprintf (dump_file, "Trying to remove check: ");
+ print_gimple_stmt (dump_file, ci->stmt, 0, 0);
+ }
+
+ result = chkp_get_check_result (ci, ci->bounds);
+
+ if (result == 1)
+ {
+ gimple_stmt_iterator i = gsi_for_stmt (ci->stmt);
+
+ if (dump_file && (dump_flags & TDF_DETAILS))
+ fprintf (dump_file, " action: delete check (always pass)\n");
+
+ gsi_remove (&i, true);
+ unlink_stmt_vdef (ci->stmt);
+ release_defs (ci->stmt);
+ ci->stmt = NULL;
+ }
+ else if (result == -1)
+ {
+ if (dump_file && (dump_flags & TDF_DETAILS))
+ fprintf (dump_file, " action: keep check (always fail)\n");
+ }
+ else if (result == 0)
+ {
+ if (dump_file && (dump_flags & TDF_DETAILS))
+ fprintf (dump_file, " action: keep check (cannot compute result)\n");
+ }
+}
+
/* For bounds used in CI check if bounds are produced by
intersection and we may use outer bounds instead. If
transformation is possible then fix check statement and
@@ -4911,6 +4951,27 @@ chkp_remove_excess_intersections (void)
}
}

+/* Try to remove all checks which are known to alwyas pass. */
+void
+chkp_remove_constant_checks (void)
+{
+ basic_block bb;
+
+ if (dump_file && (dump_flags & TDF_DETAILS))
+ fprintf (dump_file, "Searching for redundant checks...\n");
+
+ FOR_EACH_BB_FN (bb, cfun)
+ {
+ struct bb_checks *bbc = &check_infos[bb->index];
+ unsigned int no;
+
+ /* Iterate throw all found checks in BB. */
+ for (no = 0; no < bbc->checks.length (); no++)
+ if (bbc->checks[no].stmt)
+ chkp_remove_check_if_pass (&bbc->checks[no]);
+ }
+}
+
/* Return fast version of string function FNCODE. */
tree
chkp_get_nobnd_fndecl (enum built_in_function fncode)
@@ -5194,6 +5255,8 @@ chkp_opt_execute (void)

chkp_remove_excess_intersections ();

+ chkp_remove_constant_checks ();
+
chkp_release_check_info ();

chkp_opt_fini ();
Jeff Law
2014-10-09 17:13:35 UTC
Permalink
Post by Ilya Enkovich
Hi,
This patch adds a removal of checks known to always pass into checker optimization.
Thanks,
Ilya
--
* tree-chkp.c (chkp_remove_check_if_pass): New.
(chkp_remove_constant_checks): New.
(chkp_opt_execute): Run constant check removal
algorithm.
So again, I'd like to see all the optimization stuff pulled into its own
file and and basic tests that we can use for smoke testing now and in
the future.
Post by Ilya Enkovich
+ else if (result == -1)
+ {
+ if (dump_file && (dump_flags & TDF_DETAILS))
+ fprintf (dump_file, " action: keep check (always fail)\n");
+ }
ISTM this case should generate a compile-time warning. We've just
determined statically that this test is always going to fail, right?
Post by Ilya Enkovich
+ /* Iterate throw all found checks in BB. */
s/throw/through/

With the changes above, this will be OK for the trunk.


Jeff

Continue reading on narkive:
Loading...