The following avoids prologue peeling when doing early exit
vectorization with the IV exit before the early exit. That's because
we it invalidates the invariant that the effective latch of the loop
is empty causing wrong continuation to the main loop. In particular
this is prone to break virtual SSA form.
PR tree-optimization/113371
* tree-vect-data-refs.cc (vect_enhance_data_refs_alignment):
Do not peel when LOOP_VINFO_EARLY_BREAKS_VECT_PEELED.
* tree-vect-loop-manip.cc (vect_do_peeling): Assert we do
not perform prologue peeling when LOOP_VINFO_EARLY_BREAKS_VECT_PEELED.
* gcc.dg/vect/pr113371.c: New testcase.
--- /dev/null
+/* { dg-do compile } */
+/* { dg-additional-options "-O" } */
+/* { dg-additional-options "-march=silvermont" { target { x86_64-*-* i?86-*-* } } } */
+
+long *BN_uadd_ap;
+
+void
+BN_uadd (int dif, long t1)
+{
+ long *rp;
+ while (dif)
+ {
+ dif--;
+ t1 = *BN_uadd_ap;
+ *rp++ = t1;
+ if (t1)
+ break;
+ }
+}
/* Check if we can possibly peel the loop. */
if (!vect_can_advance_ivs_p (loop_vinfo)
|| !slpeel_can_duplicate_loop_p (loop, LOOP_VINFO_IV_EXIT (loop_vinfo),
- LOOP_VINFO_IV_EXIT (loop_vinfo))
- || loop->inner)
+ loop_preheader_edge (loop))
+ || loop->inner
+ || LOOP_VINFO_EARLY_BREAKS_VECT_PEELED (loop_vinfo))
do_peeling = false;
struct _vect_peel_extended_info peel_for_known_alignment;
{
e = loop_preheader_edge (loop);
edge exit_e = LOOP_VINFO_IV_EXIT (loop_vinfo);
- gcc_checking_assert (slpeel_can_duplicate_loop_p (loop, exit_e, e));
+ gcc_checking_assert (slpeel_can_duplicate_loop_p (loop, exit_e, e)
+ && !LOOP_VINFO_EARLY_BREAKS_VECT_PEELED (loop_vinfo));
/* Peel prolog and put it on preheader edge of loop. */
edge scalar_e = LOOP_VINFO_SCALAR_IV_EXIT (loop_vinfo);