From 476c12802dc41b7f425075e00181a9dc5968ac69 Mon Sep 17 00:00:00 2001 From: Richard Biener Date: Fri, 22 May 2015 09:08:46 +0000 Subject: [PATCH] re PR ipa/65701 (r221530 makes 187.facerec drop with -Ofast -flto on bdver2) 2015-05-22 Richard Biener PR tree-optimization/65701 * tree-vect-data-refs.c (vect_enhance_data_refs_alignment): Move peeling cost models into one place. Peel for alignment for single loads only if an aligned load is cheaper than an unaligned load. From-SVN: r223528 --- gcc/ChangeLog | 8 ++++++++ gcc/tree-vect-data-refs.c | 42 +++++++++++++++++++++--------------------- 2 files changed, 29 insertions(+), 21 deletions(-) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index aaa6aab..ce6173c 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,11 @@ +2015-05-22 Richard Biener + + PR tree-optimization/65701 + * tree-vect-data-refs.c (vect_enhance_data_refs_alignment): + Move peeling cost models into one place. Peel for alignment + for single loads only if an aligned load is cheaper than + an unaligned load. + 2015-05-22 Marek Polacek PR c/47043 diff --git a/gcc/tree-vect-data-refs.c b/gcc/tree-vect-data-refs.c index 3b8405f..eb35d62 100644 --- a/gcc/tree-vect-data-refs.c +++ b/gcc/tree-vect-data-refs.c @@ -1541,16 +1541,6 @@ vect_enhance_data_refs_alignment (loop_vec_info loop_vinfo) || !slpeel_can_duplicate_loop_p (loop, single_exit (loop))) do_peeling = false; - /* If we don't know how many times the peeling loop will run - assume it will run VF-1 times and disable peeling if the remaining - iters are less than the vectorization factor. */ - if (do_peeling - && all_misalignments_unknown - && LOOP_VINFO_NITERS_KNOWN_P (loop_vinfo) - && (LOOP_VINFO_INT_NITERS (loop_vinfo) - < 2 * (unsigned) LOOP_VINFO_VECT_FACTOR (loop_vinfo) - 1)) - do_peeling = false; - if (do_peeling && all_misalignments_unknown && vect_supportable_dr_alignment (dr0, false)) @@ -1619,12 +1609,17 @@ vect_enhance_data_refs_alignment (loop_vec_info loop_vinfo) } /* In case there are only loads with different unknown misalignments, use - peeling only if it may help to align other accesses in the loop. */ + peeling only if it may help to align other accesses in the loop or + if it may help improving load bandwith when we'd end up using + unaligned loads. */ + tree dr0_vt = STMT_VINFO_VECTYPE (vinfo_for_stmt (DR_STMT (dr0))); if (!first_store && !STMT_VINFO_SAME_ALIGN_REFS ( vinfo_for_stmt (DR_STMT (dr0))).length () - && vect_supportable_dr_alignment (dr0, false) - != dr_unaligned_supported) + && (vect_supportable_dr_alignment (dr0, false) + != dr_unaligned_supported + || (builtin_vectorization_cost (vector_load, dr0_vt, 0) + == builtin_vectorization_cost (unaligned_load, dr0_vt, -1)))) do_peeling = false; } @@ -1641,14 +1636,6 @@ vect_enhance_data_refs_alignment (loop_vec_info loop_vinfo) &body_cost_vec); if (!dr0 || !npeel) do_peeling = false; - - /* If peeling by npeel will result in a remaining loop not iterating - enough to be vectorized then do not peel. */ - if (do_peeling - && LOOP_VINFO_NITERS_KNOWN_P (loop_vinfo) - && (LOOP_VINFO_INT_NITERS (loop_vinfo) - < LOOP_VINFO_VECT_FACTOR (loop_vinfo) + npeel)) - do_peeling = false; } if (do_peeling) @@ -1733,6 +1720,7 @@ vect_enhance_data_refs_alignment (loop_vec_info loop_vinfo) } } + /* Cost model #1 - honor --param vect-max-peeling-for-alignment. */ if (do_peeling) { unsigned max_allowed_peel @@ -1757,6 +1745,18 @@ vect_enhance_data_refs_alignment (loop_vec_info loop_vinfo) } } + /* Cost model #2 - if peeling may result in a remaining loop not + iterating enough to be vectorized then do not peel. */ + if (do_peeling + && LOOP_VINFO_NITERS_KNOWN_P (loop_vinfo)) + { + unsigned max_peel + = npeel == 0 ? LOOP_VINFO_VECT_FACTOR (loop_vinfo) - 1 : npeel; + if (LOOP_VINFO_INT_NITERS (loop_vinfo) + < LOOP_VINFO_VECT_FACTOR (loop_vinfo) + max_peel) + do_peeling = false; + } + if (do_peeling) { /* (1.2) Update the DR_MISALIGNMENT of each data reference DR_i. -- 2.7.4