On Wed, 12 Mar 2014, Jakub Jelinek wrote: > On Tue, Mar 11, 2014 at 04:16:13PM -0700, Cong Hou wrote: > > This patch is fixing PR60505 in which the vectorizer may produce > > unnecessary epilogues. > > > > Bootstrapped and tested on a x86_64 machine. > > > > OK for trunk? > > That looks wrong. Consider the case where the loop isn't versioned, > if you disable generation of the epilogue loop, you end up only with > a vector loop. > > Say: > unsigned char ovec[16] __attribute__((aligned (16))) = { 0 }; > void > foo (char *__restrict in, char *__restrict out, int num) > { > int i; > > in = __builtin_assume_aligned (in, 16); > out = __builtin_assume_aligned (out, 16); > for (i = 0; i < num; ++i) > out[i] = (ovec[i] = in[i]); > out[num] = ovec[num / 2]; > } > -O2 -ftree-vectorize. Now, consider if this function is called > with num != 16 (num > 16 is of course invalid, but num 0 to 15 is > valid and your patch will cause a wrong-code in this case)
Indeed - we also "share" the epilogue loop for the cost model check. See where we set its maximum number of iterations. Richard.