diff mbox

[Pointer,Bounds,Checker,14/x] Passes [14/n] Optimize constant checks

Message ID 20141008192106.GN13454@msticlxl57.ims.intel.com
State New
Headers show

Commit Message

Ilya Enkovich Oct. 8, 2014, 7:21 p.m. UTC
Hi,

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

Thanks,
Ilya
--
2014-10-08  Ilya Enkovich  <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.

Comments

Jeff Law Oct. 9, 2014, 5:13 p.m. UTC | #1
On 10/08/14 13:21, Ilya Enkovich wrote:
> Hi,
>
> This patch adds a removal of checks known to always pass into checker optimization.
>
> Thanks,
> Ilya
> --
> 2014-10-08  Ilya Enkovich  <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.
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.




> +  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?

> +      /* Iterate throw all found checks in BB.  */
s/throw/through/

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


Jeff
diff mbox

Patch

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 ();