From 3ea518f6f63e66e48f2d41cfa41e1efae653a484 Mon Sep 17 00:00:00 2001 From: Richard Sandiford Date: Sat, 13 Jan 2018 17:58:06 +0000 Subject: Protect against min_profitable_iters going negative We had: if (vec_outside_cost <= 0) min_profitable_iters = 0; else { min_profitable_iters = ((vec_outside_cost - scalar_outside_cost) * assumed_vf - vec_inside_cost * peel_iters_prologue - vec_inside_cost * peel_iters_epilogue) / ((scalar_single_iter_cost * assumed_vf) - vec_inside_cost); which can lead to negative min_profitable_iters when the *_outside_costs are the same and peel_iters_epilogue is nonzero (e.g. if we're peeling for gaps). This is tested as part of the patch that adds support for fully-predicated loops. 2018-01-13 Richard Sandiford Alan Hayward David Sherwood gcc/ * tree-vect-loop.c (vect_estimate_min_profitable_iters): Make sure min_profitable_iters doesn't go negative. Co-Authored-By: Alan Hayward Co-Authored-By: David Sherwood From-SVN: r256621 --- gcc/ChangeLog | 7 +++++++ gcc/tree-vect-loop.c | 19 ++++++++++--------- 2 files changed, 17 insertions(+), 9 deletions(-) (limited to 'gcc') diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 454af82..242ecb5 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -2,6 +2,13 @@ Alan Hayward David Sherwood + * tree-vect-loop.c (vect_estimate_min_profitable_iters): Make sure + min_profitable_iters doesn't go negative. + +2018-01-13 Richard Sandiford + Alan Hayward + David Sherwood + * doc/md.texi (vec_mask_load_lanes@var{m}@var{n}): Document. (vec_mask_store_lanes@var{m}@var{n}): Likewise. * optabs.def (vec_mask_load_lanes_optab): New optab. diff --git a/gcc/tree-vect-loop.c b/gcc/tree-vect-loop.c index 8d1e003..5d6f1ab 100644 --- a/gcc/tree-vect-loop.c +++ b/gcc/tree-vect-loop.c @@ -3663,23 +3663,24 @@ vect_estimate_min_profitable_iters (loop_vec_info loop_vinfo, if ((scalar_single_iter_cost * assumed_vf) > (int) vec_inside_cost) { - if (vec_outside_cost <= 0) + min_profitable_iters = ((vec_outside_cost - scalar_outside_cost) + * assumed_vf + - vec_inside_cost * peel_iters_prologue + - vec_inside_cost * peel_iters_epilogue); + + if (min_profitable_iters <= 0) min_profitable_iters = 0; else - { - min_profitable_iters = ((vec_outside_cost - scalar_outside_cost) - * assumed_vf - - vec_inside_cost * peel_iters_prologue - - vec_inside_cost * peel_iters_epilogue) - / ((scalar_single_iter_cost * assumed_vf) - - vec_inside_cost); + { + min_profitable_iters /= ((scalar_single_iter_cost * assumed_vf) + - vec_inside_cost); if ((scalar_single_iter_cost * assumed_vf * min_profitable_iters) <= (((int) vec_inside_cost * min_profitable_iters) + (((int) vec_outside_cost - scalar_outside_cost) * assumed_vf))) min_profitable_iters++; - } + } } /* vector version will never be profitable. */ else -- cgit v1.1