aboutsummaryrefslogtreecommitdiff
path: root/gcc/tree-ssa-loop-ivopts.c
diff options
context:
space:
mode:
authorKewen Lin <linkw@gcc.gnu.org>2019-06-18 05:08:02 +0000
committerKewen Lin <linkw@gcc.gnu.org>2019-06-18 05:08:02 +0000
commit74b5fcf733823b353b331c0ca30e8b71ba98c9cf (patch)
treeb9ed33a1d95fac033d35268b37e4cf0e4bcf2ca1 /gcc/tree-ssa-loop-ivopts.c
parent702eb490a864239256203b7fad53e397d3e7fa54 (diff)
downloadgcc-74b5fcf733823b353b331c0ca30e8b71ba98c9cf.zip
gcc-74b5fcf733823b353b331c0ca30e8b71ba98c9cf.tar.gz
gcc-74b5fcf733823b353b331c0ca30e8b71ba98c9cf.tar.bz2
Add predict_doloop_p target hook
Add one target hook predict_doloop_p, it return true if we can predict it is possible to use a low-overhead loop, it can help ivopts to make some better decisions. PR middle-end/80791 * target.def (predict_doloop_p): New hook. * targhooks.h (default_predict_doloop_p): New declaration. * targhooks.c (default_predict_doloop_p): New function. * doc/tm.texi.in (TARGET_PREDICT_DOLOOP_P): New hook. * doc/tm.texi: Regenerate. * config/rs6000/rs6000.c (rs6000_predict_doloop_p): New function. (TARGET_PREDICT_DOLOOP_P): New macro. * tree-ssa-loop-ivopts.c (generic_predict_doloop_p): New function. From-SVN: r272405
Diffstat (limited to 'gcc/tree-ssa-loop-ivopts.c')
-rw-r--r--gcc/tree-ssa-loop-ivopts.c57
1 files changed, 57 insertions, 0 deletions
diff --git a/gcc/tree-ssa-loop-ivopts.c b/gcc/tree-ssa-loop-ivopts.c
index 047d4a0..bbae83c 100644
--- a/gcc/tree-ssa-loop-ivopts.c
+++ b/gcc/tree-ssa-loop-ivopts.c
@@ -3734,6 +3734,63 @@ prepare_decl_rtl (tree *expr_p, int *ws, void *data)
return NULL_TREE;
}
+/* Predict whether the given loop will be transformed in the RTL
+ doloop_optimize pass. Attempt to duplicate some doloop_optimize checks.
+ This is only for target independent checks, see targetm.predict_doloop_p
+ for the target dependent ones.
+
+ Note that according to some initial investigation, some checks like costly
+ niter check and invalid stmt scanning don't have much gains among general
+ cases, so keep this as simple as possible first.
+
+ Some RTL specific checks seems unable to be checked in gimple, if any new
+ checks or easy checks _are_ missing here, please add them. */
+
+static bool ATTRIBUTE_UNUSED
+generic_predict_doloop_p (struct ivopts_data *data)
+{
+ struct loop *loop = data->current_loop;
+
+ /* Call target hook for target dependent checks. */
+ if (!targetm.predict_doloop_p (loop))
+ {
+ if (dump_file && (dump_flags & TDF_DETAILS))
+ fprintf (dump_file, "Predict doloop failure due to"
+ " target specific checks.\n");
+ return false;
+ }
+
+ /* Similar to doloop_optimize, check iteration description to know it's
+ suitable or not. Keep it as simple as possible, feel free to extend it
+ if you find any multiple exits cases matter. */
+ edge exit = single_dom_exit (loop);
+ struct tree_niter_desc *niter_desc;
+ if (!exit || !(niter_desc = niter_for_exit (data, exit)))
+ {
+ if (dump_file && (dump_flags & TDF_DETAILS))
+ fprintf (dump_file, "Predict doloop failure due to"
+ " unexpected niters.\n");
+ return false;
+ }
+
+ /* Similar to doloop_optimize, check whether iteration count too small
+ and not profitable. */
+ HOST_WIDE_INT est_niter = get_estimated_loop_iterations_int (loop);
+ if (est_niter == -1)
+ est_niter = get_likely_max_loop_iterations_int (loop);
+ if (est_niter >= 0 && est_niter < 3)
+ {
+ if (dump_file && (dump_flags & TDF_DETAILS))
+ fprintf (dump_file,
+ "Predict doloop failure due to"
+ " too few iterations (%u).\n",
+ (unsigned int) est_niter);
+ return false;
+ }
+
+ return true;
+}
+
/* Determines cost of the computation of EXPR. */
static unsigned