--- /dev/null
+#include "p9-vec-length.h"
+
+/* Test the case loop iteration is known. */
+
+#define N 127
+
+#define test(TYPE) \
+ extern TYPE a_##TYPE[N]; \
+ extern TYPE b_##TYPE[N]; \
+ extern TYPE c_##TYPE[N]; \
+ void __attribute__ ((noinline, noclone)) test##TYPE () \
+ { \
+ unsigned int i = 0; \
+ for (i = 0; i < N; i++) \
+ c_##TYPE[i] = a_##TYPE[i] + b_##TYPE[i]; \
+ }
+
+TEST_ALL (test)
--- /dev/null
+#include "p9-vec-length.h"
+
+/* Test the case loop iteration is unknown. */
+#define N 255
+
+#define test(TYPE) \
+ extern TYPE a_##TYPE[N]; \
+ extern TYPE b_##TYPE[N]; \
+ extern TYPE c_##TYPE[N]; \
+ void __attribute__ ((noinline, noclone)) test##TYPE (unsigned int n) \
+ { \
+ unsigned int i = 0; \
+ for (i = 0; i < n; i++) \
+ c_##TYPE[i] = a_##TYPE[i] + b_##TYPE[i]; \
+ }
+
+TEST_ALL (test)
--- /dev/null
+#include "p9-vec-length.h"
+
+/* Test the case loop iteration less than VF. */
+
+/* For char. */
+#define N_uint8_t 15
+#define N_int8_t 15
+/* For short. */
+#define N_uint16_t 6
+#define N_int16_t 6
+/* For int/float. */
+#define N_uint32_t 3
+#define N_int32_t 3
+#define N_float 3
+/* For long/double. */
+#define N_uint64_t 1
+#define N_int64_t 1
+#define N_double 1
+
+#define test(TYPE) \
+ extern TYPE a_##TYPE[N_##TYPE]; \
+ extern TYPE b_##TYPE[N_##TYPE]; \
+ extern TYPE c_##TYPE[N_##TYPE]; \
+ void __attribute__ ((noinline, noclone)) test##TYPE () \
+ { \
+ unsigned int i = 0; \
+ for (i = 0; i < N_##TYPE; i++) \
+ c_##TYPE[i] = a_##TYPE[i] + b_##TYPE[i]; \
+ }
+
+TEST_ALL (test)
--- /dev/null
+#include "p9-vec-length.h"
+
+/* Test the case that the loop which has multiple vectors (concatenated vectors)
+ but with same vector type. */
+
+#define test(TYPE) \
+ void __attribute__ ((noinline, noclone)) \
+ test_mv_##TYPE (TYPE *restrict a, TYPE *restrict b, TYPE *restrict c, \
+ int n) \
+ { \
+ for (int i = 0; i < n; ++i) \
+ { \
+ a[i] += 1; \
+ b[i * 2] += 2; \
+ b[i * 2 + 1] += 3; \
+ c[i * 4] += 4; \
+ c[i * 4 + 1] += 5; \
+ c[i * 4 + 2] += 6; \
+ c[i * 4 + 3] += 7; \
+ } \
+ }
+
+TEST_ALL (test)
+
--- /dev/null
+#include "p9-vec-length.h"
+
+/* Test the case that the loop which has multiple vectors (concatenated vectors)
+ with different types. */
+
+#define test(TYPE1, TYPE2) \
+ void __attribute__ ((noinline, noclone)) \
+ test_mv_##TYPE1##TYPE2 (TYPE1 *restrict a, TYPE2 *restrict b, int n) \
+ { \
+ for (int i = 0; i < n; ++i) \
+ { \
+ a[i * 2] += 1; \
+ a[i * 2 + 1] += 2; \
+ b[i * 2] += 3; \
+ b[i * 2 + 1] += 4; \
+ } \
+ }
+
+#define TEST_ALL2(T) \
+ T (int8_t, uint16_t) \
+ T (uint8_t, int16_t) \
+ T (int16_t, uint32_t) \
+ T (uint16_t, int32_t) \
+ T (int32_t, double) \
+ T (uint32_t, int64_t) \
+ T (float, uint64_t)
+
+TEST_ALL2 (test)
+
--- /dev/null
+#include "p9-vec-length.h"
+
+/* Test the case that the loop which has the same concatenated vectors (same
+ size per iteration) but from different types. */
+
+#define test(TYPE1, TYPE2) \
+ void __attribute__ ((noinline, noclone)) \
+ test_mv_##TYPE1##TYPE2 (TYPE1 *restrict a, TYPE2 *restrict b, int n) \
+ { \
+ for (int i = 0; i < n; i++) \
+ { \
+ a[i * 2] += 1; \
+ a[i * 2 + 1] += 2; \
+ b[i * 4] += 3; \
+ b[i * 4 + 1] += 4; \
+ b[i * 4 + 2] += 5; \
+ b[i * 4 + 3] += 6; \
+ } \
+ }
+
+#define TEST_ALL2(T) \
+ T (int16_t, uint8_t) \
+ T (uint16_t, int8_t) \
+ T (int32_t, uint16_t) \
+ T (uint32_t, int16_t) \
+ T (float, uint16_t) \
+ T (int64_t, float) \
+ T (uint64_t, int32_t) \
+ T (double, uint32_t)
+
+TEST_ALL2 (test)
+
--- /dev/null
+#include "p9-vec-length.h"
+
+/* Test the case that the loop requires to have peeled prologues for
+ alignment. */
+
+#define N 64
+#define START 1
+#define END 59
+
+#define test(TYPE) \
+ TYPE x_##TYPE[N] __attribute__((aligned(16))); \
+ void __attribute__((noinline, noclone)) test_npeel_##TYPE() { \
+ TYPE v = 0; \
+ for (unsigned int i = START; i < END; i++) { \
+ x_##TYPE[i] = v; \
+ v += 1; \
+ } \
+ }
+
+TEST_ALL (test)
--- /dev/null
+#include "p9-vec-length.h"
+
+/* Test the case that the loop requires to peel for gaps. */
+
+#define N 200
+
+#define test(TYPE) \
+ void __attribute__((noinline, noclone)) \
+ test_##TYPE(TYPE *restrict dest, TYPE *restrict src) { \
+ for (unsigned int i = 0; i < N; ++i) \
+ dest[i] += src[i * 2]; \
+ }
+
+TEST_ALL(test)
--- /dev/null
+/* { dg-do compile { target { lp64 && powerpc_p9vector_ok } } } */
+/* { dg-options "-mdejagnu-cpu=power9 -O2 -ftree-vectorize -fno-vect-cost-model -fno-unroll-loops" } */
+
+/* { dg-additional-options "--param=vect-partial-vector-usage=1" } */
+
+/* Test for that only vectorize the epilogue with vector access with length,
+ the main body still use normal vector load/store. */
+
+#include "p9-vec-length-1.h"
+
+/* { dg-final { scan-assembler-times {\mlxvx?\M} 20 } } */
+/* { dg-final { scan-assembler-times {\mstxvx?\M} 10 } } */
+/* { dg-final { scan-assembler-times {\mlxvl\M} 20 } } */
+/* { dg-final { scan-assembler-times {\mstxvl\M} 10 } } */
+
--- /dev/null
+/* { dg-do compile { target { lp64 && powerpc_p9vector_ok } } } */
+/* { dg-options "-mdejagnu-cpu=power9 -O2 -ftree-vectorize -fno-vect-cost-model -fno-unroll-loops" } */
+
+/* { dg-additional-options "--param=vect-partial-vector-usage=1" } */
+
+/* Test for that only vectorize the epilogue with vector access with length,
+ the main body still use normal vector load/store. */
+
+#include "p9-vec-length-2.h"
+
+/* { dg-final { scan-assembler-times {\mlxvx?\M} 20 } } */
+/* { dg-final { scan-assembler-times {\mstxvx?\M} 10 } } */
+/* { dg-final { scan-assembler-times {\mlxvl\M} 20 } } */
+/* { dg-final { scan-assembler-times {\mstxvl\M} 10 } } */
+
--- /dev/null
+/* { dg-do compile { target { lp64 && powerpc_p9vector_ok } } } */
+/* { dg-options "-mdejagnu-cpu=power9 -O2 -ftree-vectorize -fno-vect-cost-model -fno-unroll-loops" } */
+
+/* { dg-additional-options "--param=vect-partial-vector-usage=1" } */
+
+/* Test for that only vectorize the epilogue with vector access with length,
+ the main body still use normal vector load/store. */
+
+#include "p9-vec-length-3.h"
+
+/* { dg-final { scan-assembler-not {\mlxv\M} } } */
+/* { dg-final { scan-assembler-not {\mstxv\M} } } */
+/* { dg-final { scan-assembler-not {\mlxvx\M} } } */
+/* { dg-final { scan-assembler-not {\mstxvx\M} } } */
+/* 64bit types get completely unrolled, so only check the others. */
+/* { dg-final { scan-assembler-times {\mlxvl\M} 14 } } */
+/* { dg-final { scan-assembler-times {\mstxvl\M} 7 } } */
+
--- /dev/null
+/* { dg-do compile { target { lp64 && powerpc_p9vector_ok } } } */
+/* { dg-options "-mdejagnu-cpu=power9 -O2 -ftree-vectorize -fno-vect-cost-model -fno-unroll-loops" } */
+
+/* { dg-additional-options "--param=vect-partial-vector-usage=1" } */
+
+/* Test for that only vectorize the epilogue with vector access with length,
+ the main body still use normal vector load/store. */
+
+#include "p9-vec-length-4.h"
+
+/* { dg-final { scan-assembler-times {\mlxvx?\M} 120 } } */
+/* { dg-final { scan-assembler-times {\mstxvx?\M} 70 } } */
+/* { dg-final { scan-assembler-times {\mlxvl\M} 70 } } */
+/* { dg-final { scan-assembler-times {\mstxvl\M} 70 } } */
+
--- /dev/null
+/* { dg-do compile { target { lp64 && powerpc_p9vector_ok } } } */
+/* { dg-options "-mdejagnu-cpu=power9 -O2 -ftree-vectorize -fno-vect-cost-model -fno-unroll-loops" } */
+
+/* { dg-additional-options "--param=vect-partial-vector-usage=1" } */
+
+/* Test for that only vectorize the epilogue with vector access with length,
+ the main body still use normal vector load/store. */
+
+#include "p9-vec-length-5.h"
+
+/* { dg-final { scan-assembler-times {\mlxvx?\M} 49 } } */
+/* { dg-final { scan-assembler-times {\mstxvx?\M} 21 } } */
+/* { dg-final { scan-assembler-times {\mlxvl\M} 21 } } */
+/* { dg-final { scan-assembler-times {\mstxvl\M} 21 } } */
+
--- /dev/null
+/* { dg-do compile { target { lp64 && powerpc_p9vector_ok } } } */
+/* { dg-options "-mdejagnu-cpu=power9 -O2 -ftree-vectorize -fno-vect-cost-model -fno-unroll-loops" } */
+
+/* { dg-additional-options "--param=vect-partial-vector-usage=1" } */
+
+/* Test for that only vectorize the epilogue with vector access with length,
+ the main body still use normal vector load/store. */
+
+#include "p9-vec-length-6.h"
+
+/* { dg-final { scan-assembler-times {\mlxvx?\M} 42 } } */
+/* { dg-final { scan-assembler-times {\mstxvx?\M} 16 } } */
+/* 64bit/32bit pairs don't have the epilogues. */
+/* { dg-final { scan-assembler-times {\mlxvl\M} 10 } } */
+/* { dg-final { scan-assembler-times {\mstxvl\M} 10 } } */
+
--- /dev/null
+/* { dg-do compile { target { lp64 && powerpc_p9vector_ok } } } */
+/* { dg-options "-mdejagnu-cpu=power9 -O2 -ftree-vectorize -fno-vect-cost-model -fno-unroll-loops -ffast-math" } */
+
+/* { dg-additional-options "--param=vect-partial-vector-usage=1" } */
+
+/* Test for that only vectorize the epilogue with vector access with length,
+ the main body still use normal vector load/store. */
+
+#include "p9-vec-length-7.h"
+
+/* { dg-final { scan-assembler-times {\mstxvl\M} 10 } } */
--- /dev/null
+/* { dg-do compile { target { lp64 && powerpc_p9vector_ok } } } */
+/* { dg-options "-mdejagnu-cpu=power9 -O2 -ftree-vectorize -fno-vect-cost-model -fno-unroll-loops" } */
+
+/* { dg-additional-options "--param=vect-partial-vector-usage=1" } */
+
+/* Test for that only vectorize the epilogue with vector access with length,
+ the main body still use normal vector load/store. */
+
+#include "p9-vec-length-8.h"
+
+/* { dg-final { scan-assembler-times {\mlxvl\M} 30 } } */
+/* { dg-final { scan-assembler-times {\mstxvl\M} 10 } } */
--- /dev/null
+/* { dg-do run { target { lp64 && p9vector_hw } } } */
+/* { dg-options "-mdejagnu-cpu=power9 -O2 -ftree-vectorize -fno-vect-cost-model" } */
+
+/* { dg-additional-options "--param=vect-partial-vector-usage=1" } */
+
+/* Check whether it runs successfully if we only vectorize the epilogue
+ with vector access with length. */
+
+#include "p9-vec-length-run-1.h"
+
--- /dev/null
+/* { dg-do run { target { lp64 && p9vector_hw } } } */
+/* { dg-options "-mdejagnu-cpu=power9 -O2 -ftree-vectorize -fno-vect-cost-model" } */
+
+/* { dg-additional-options "--param=vect-partial-vector-usage=1" } */
+
+/* Check whether it runs successfully if we only vectorize the epilogue
+ with vector access with length. */
+
+#include "p9-vec-length-run-2.h"
+
--- /dev/null
+/* { dg-do run { target { lp64 && p9vector_hw } } } */
+/* { dg-options "-mdejagnu-cpu=power9 -O2 -ftree-vectorize -fno-vect-cost-model" } */
+
+/* { dg-additional-options "--param=vect-partial-vector-usage=1" } */
+
+/* Check whether it runs successfully if we only vectorize the epilogue
+ with vector access with length. */
+
+#include "p9-vec-length-run-3.h"
+
--- /dev/null
+/* { dg-do run { target { lp64 && p9vector_hw } } } */
+/* { dg-options "-mdejagnu-cpu=power9 -O2 -ftree-vectorize -fno-vect-cost-model" } */
+
+/* { dg-additional-options "--param=vect-partial-vector-usage=1" } */
+
+/* Check whether it runs successfully if we only vectorize the epilogue
+ with vector access with length. */
+
+#include "p9-vec-length-run-4.h"
+
--- /dev/null
+/* { dg-do run { target { lp64 && p9vector_hw } } } */
+/* { dg-options "-mdejagnu-cpu=power9 -O2 -ftree-vectorize -fno-vect-cost-model" } */
+
+/* { dg-additional-options "--param=vect-partial-vector-usage=1" } */
+
+/* Check whether it runs successfully if we only vectorize the epilogue
+ with vector access with length. */
+
+#include "p9-vec-length-run-5.h"
+
--- /dev/null
+/* { dg-do run { target { lp64 && p9vector_hw } } } */
+/* { dg-options "-mdejagnu-cpu=power9 -O2 -ftree-vectorize -fno-vect-cost-model" } */
+
+/* { dg-additional-options "--param=vect-partial-vector-usage=1" } */
+
+/* Check whether it runs successfully if we only vectorize the epilogue
+ with vector access with length. */
+
+#include "p9-vec-length-run-6.h"
+
--- /dev/null
+/* { dg-do run { target { lp64 && p9vector_hw } } } */
+/* { dg-options "-mdejagnu-cpu=power9 -O2 -ftree-vectorize -fno-vect-cost-model -ffast-math" } */
+
+/* { dg-additional-options "--param=vect-partial-vector-usage=1" } */
+
+/* Check whether it runs successfully if we only vectorize the epilogue
+ with vector access with length. */
+
+#include "p9-vec-length-run-7.h"
+
--- /dev/null
+/* { dg-do run { target { lp64 && p9vector_hw } } } */
+/* { dg-options "-mdejagnu-cpu=power9 -O2 -ftree-vectorize -fno-vect-cost-model" } */
+
+/* { dg-additional-options "--param=vect-partial-vector-usage=1" } */
+
+/* Check whether it runs successfully if we only vectorize the epilogue
+ with vector access with length. */
+
+#include "p9-vec-length-run-8.h"
+
--- /dev/null
+/* { dg-do compile { target { lp64 && powerpc_p9vector_ok } } } */
+/* { dg-options "-mdejagnu-cpu=power9 -O2 -ftree-vectorize -fno-vect-cost-model -fno-unroll-loops" } */
+
+/* { dg-additional-options "--param=vect-partial-vector-usage=2" } */
+
+/* Test for fully with length, the loop body uses vector access with length,
+ there should not be any epilogues. */
+
+#include "p9-vec-length-1.h"
+
+/* { dg-final { scan-assembler-not {\mlxv\M} } } */
+/* { dg-final { scan-assembler-not {\mstxv\M} } } */
+/* { dg-final { scan-assembler-not {\mlxvx\M} } } */
+/* { dg-final { scan-assembler-not {\mstxvx\M} } } */
+/* { dg-final { scan-assembler-times {\mlxvl\M} 20 } } */
+/* { dg-final { scan-assembler-times {\mstxvl\M} 10 } } */
--- /dev/null
+/* { dg-do compile { target { lp64 && powerpc_p9vector_ok } } } */
+/* { dg-options "-mdejagnu-cpu=power9 -O2 -ftree-vectorize -fno-vect-cost-model -fno-unroll-loops" } */
+
+/* { dg-additional-options "--param=vect-partial-vector-usage=2" } */
+
+/* Test for fully with length, the loop body uses vector access with length,
+ there should not be any epilogues. */
+
+#include "p9-vec-length-2.h"
+
+/* { dg-final { scan-assembler-not {\mlxv\M} } } */
+/* { dg-final { scan-assembler-not {\mstxv\M} } } */
+/* { dg-final { scan-assembler-not {\mlxvx\M} } } */
+/* { dg-final { scan-assembler-not {\mstxvx\M} } } */
+/* { dg-final { scan-assembler-times {\mlxvl\M} 20 } } */
+/* { dg-final { scan-assembler-times {\mstxvl\M} 10 } } */
--- /dev/null
+/* { dg-do compile { target { lp64 && powerpc_p9vector_ok } } } */
+/* { dg-options "-mdejagnu-cpu=power9 -O2 -ftree-vectorize -fno-vect-cost-model -fno-unroll-loops" } */
+
+/* { dg-additional-options "--param=vect-partial-vector-usage=2" } */
+
+/* Test for fully with length, the loop body uses vector access with length,
+ there should not be any epilogues. */
+
+#include "p9-vec-length-3.h"
+
+/* { dg-final { scan-assembler-not {\mlxv\M} } } */
+/* { dg-final { scan-assembler-not {\mstxv\M} } } */
+/* { dg-final { scan-assembler-not {\mlxvx\M} } } */
+/* { dg-final { scan-assembler-not {\mstxvx\M} } } */
+/* 64bit types get completely unrolled, so only check the others. */
+/* { dg-final { scan-assembler-times {\mlxvl\M} 14 } } */
+/* { dg-final { scan-assembler-times {\mstxvl\M} 7 } } */
--- /dev/null
+/* { dg-do compile { target { lp64 && powerpc_p9vector_ok } } } */
+/* { dg-options "-mdejagnu-cpu=power9 -O2 -ftree-vectorize -fno-vect-cost-model -fno-unroll-loops" } */
+
+/* { dg-additional-options "--param=vect-partial-vector-usage=2" } */
+
+/* Test for fully with length, the loop body uses vector access with length,
+ there should not be any epilogues. */
+
+#include "p9-vec-length-4.h"
+
+/* It can use normal vector load for constant vector load. */
+/* { dg-final { scan-assembler-not {\mstxv\M} } } */
+/* { dg-final { scan-assembler-not {\mlxvx\M} } } */
+/* { dg-final { scan-assembler-not {\mstxvx\M} } } */
+/* { dg-final { scan-assembler-times {\mlxvl\M} 70 } } */
+/* { dg-final { scan-assembler-times {\mstxvl\M} 70 } } */
--- /dev/null
+/* { dg-do compile { target { lp64 && powerpc_p9vector_ok } } } */
+/* { dg-options "-mdejagnu-cpu=power9 -O2 -ftree-vectorize -fno-vect-cost-model -fno-unroll-loops" } */
+
+/* { dg-additional-options "--param=vect-partial-vector-usage=2" } */
+
+/* Test for fully with length, the loop body uses vector access with length,
+ there should not be any epilogues. */
+
+#include "p9-vec-length-5.h"
+
+/* It can use normal vector load for constant vector load. */
+/* { dg-final { scan-assembler-not {\mstxv\M} } } */
+/* { dg-final { scan-assembler-not {\mlxvx\M} } } */
+/* { dg-final { scan-assembler-not {\mstxvx\M} } } */
+/* { dg-final { scan-assembler-times {\mlxvl\M} 21 } } */
+/* { dg-final { scan-assembler-times {\mstxvl\M} 21 } } */
--- /dev/null
+/* { dg-do compile { target { lp64 && powerpc_p9vector_ok } } } */
+/* { dg-options "-mdejagnu-cpu=power9 -O2 -ftree-vectorize -fno-vect-cost-model -fno-unroll-loops" } */
+
+/* { dg-additional-options "--param=vect-partial-vector-usage=2" } */
+
+/* Test for fully with length, the loop body uses vector access with length,
+ there should not be any epilogues. */
+
+#include "p9-vec-length-6.h"
+
+/* It can use normal vector load for constant vector load. */
+/* { dg-final { scan-assembler-not {\mstxv\M} } } */
+/* { dg-final { scan-assembler-not {\mlxvx\M} } } */
+/* { dg-final { scan-assembler-not {\mstxvx\M} } } */
+/* { dg-final { scan-assembler-times {\mlxvl\M} 16 } } */
+/* { dg-final { scan-assembler-times {\mstxvl\M} 16 } } */
--- /dev/null
+/* { dg-do compile { target { lp64 && powerpc_p9vector_ok } } } */
+/* { dg-options "-mdejagnu-cpu=power9 -O2 -ftree-vectorize -fno-vect-cost-model -fno-unroll-loops -ffast-math" } */
+
+/* { dg-additional-options "--param=vect-partial-vector-usage=2" } */
+
+/* Test for fully with length, the loop body uses vector access with length,
+ there should not be any epilogues. */
+
+#include "p9-vec-length-7.h"
+
+/* Each type has one stxvl excepting for int8 and uint8, that have two due to
+ rtl pass bbro duplicating the block which has one stxvl. */
+/* { dg-final { scan-assembler-times {\mstxvl\M} 12 } } */
--- /dev/null
+/* { dg-do compile { target { lp64 && powerpc_p9vector_ok } } } */
+/* { dg-options "-mdejagnu-cpu=power9 -O2 -ftree-vectorize -fno-vect-cost-model -fno-unroll-loops" } */
+
+/* { dg-additional-options "--param=vect-partial-vector-usage=2" } */
+
+/* Test for fully with length, the loop body uses vector access with length,
+ there should not be any epilogues. */
+
+#include "p9-vec-length-8.h"
+
+/* { dg-final { scan-assembler-times {\mlxvl\M} 30 } } */
+/* { dg-final { scan-assembler-times {\mstxvl\M} 10 } } */
--- /dev/null
+/* { dg-do run { target { lp64 && p9vector_hw } } } */
+/* { dg-options "-mdejagnu-cpu=power9 -O2 -ftree-vectorize -fno-vect-cost-model" } */
+
+/* { dg-additional-options "--param=vect-partial-vector-usage=2" } */
+
+/* Check whether it runs successfully if we vectorize the loop fully
+ with vector access with length. */
+
+#include "p9-vec-length-run-1.h"
+
--- /dev/null
+/* { dg-do run { target { lp64 && p9vector_hw } } } */
+/* { dg-options "-mdejagnu-cpu=power9 -O2 -ftree-vectorize -fno-vect-cost-model" } */
+
+/* { dg-additional-options "--param=vect-partial-vector-usage=2" } */
+
+/* Check whether it runs successfully if we vectorize the loop fully
+ with vector access with length. */
+
+#include "p9-vec-length-run-2.h"
+
--- /dev/null
+/* { dg-do run { target { lp64 && p9vector_hw } } } */
+/* { dg-options "-mdejagnu-cpu=power9 -O2 -ftree-vectorize -fno-vect-cost-model" } */
+
+/* { dg-additional-options "--param=vect-partial-vector-usage=2" } */
+
+/* Check whether it runs successfully if we vectorize the loop fully
+ with vector access with length. */
+
+#include "p9-vec-length-run-3.h"
+
--- /dev/null
+/* { dg-do run { target { lp64 && p9vector_hw } } } */
+/* { dg-options "-mdejagnu-cpu=power9 -O2 -ftree-vectorize -fno-vect-cost-model" } */
+
+/* { dg-additional-options "--param=vect-partial-vector-usage=2" } */
+
+/* Check whether it runs successfully if we vectorize the loop fully
+ with vector access with length. */
+
+#include "p9-vec-length-run-4.h"
+
--- /dev/null
+/* { dg-do run { target { lp64 && p9vector_hw } } } */
+/* { dg-options "-mdejagnu-cpu=power9 -O2 -ftree-vectorize -fno-vect-cost-model" } */
+
+/* { dg-additional-options "--param=vect-partial-vector-usage=2" } */
+
+/* Check whether it runs successfully if we vectorize the loop fully
+ with vector access with length. */
+
+#include "p9-vec-length-run-5.h"
+
--- /dev/null
+/* { dg-do run { target { lp64 && p9vector_hw } } } */
+/* { dg-options "-mdejagnu-cpu=power9 -O2 -ftree-vectorize -fno-vect-cost-model" } */
+
+/* { dg-additional-options "--param=vect-partial-vector-usage=2" } */
+
+/* Check whether it runs successfully if we vectorize the loop fully
+ with vector access with length. */
+
+#include "p9-vec-length-run-6.h"
+
--- /dev/null
+/* { dg-do run { target { lp64 && p9vector_hw } } } */
+/* { dg-options "-mdejagnu-cpu=power9 -O2 -ftree-vectorize -fno-vect-cost-model -ffast-math" } */
+
+/* { dg-additional-options "--param=vect-partial-vector-usage=2" } */
+
+/* Check whether it runs successfully if we vectorize the loop fully
+ with vector access with length. */
+
+#include "p9-vec-length-run-7.h"
+
--- /dev/null
+/* { dg-do run { target { lp64 && p9vector_hw } } } */
+/* { dg-options "-mdejagnu-cpu=power9 -O2 -ftree-vectorize -fno-vect-cost-model" } */
+
+/* { dg-additional-options "--param=vect-partial-vector-usage=2" } */
+
+/* Check whether it runs successfully if we vectorize the loop fully
+ with vector access with length. */
+
+#include "p9-vec-length-run-8.h"
+
--- /dev/null
+#include "p9-vec-length-1.h"
+
+#define decl(TYPE) \
+ TYPE a_##TYPE[N]; \
+ TYPE b_##TYPE[N]; \
+ TYPE c_##TYPE[N];
+
+#define run(TYPE) \
+ { \
+ unsigned int i = 0; \
+ for (i = 0; i < N; i++) \
+ { \
+ a_##TYPE[i] = i * 2 + 1; \
+ b_##TYPE[i] = i % 2 - 2; \
+ } \
+ test##TYPE (); \
+ for (i = 0; i < N; i++) \
+ { \
+ TYPE a1 = i * 2 + 1; \
+ TYPE b1 = i % 2 - 2; \
+ TYPE exp_c = a1 + b1; \
+ if (c_##TYPE[i] != exp_c) \
+ __builtin_abort (); \
+ } \
+ }
+
+TEST_ALL (decl)
+
+int
+main (void)
+{
+ TEST_ALL (run)
+ return 0;
+}
--- /dev/null
+#include "p9-vec-length-2.h"
+
+#define decl(TYPE) \
+ TYPE a_##TYPE[N]; \
+ TYPE b_##TYPE[N]; \
+ TYPE c_##TYPE[N];
+
+#define N1 195
+
+#define run(TYPE) \
+ { \
+ unsigned int i = 0; \
+ for (i = 0; i < N; i++) \
+ { \
+ a_##TYPE[i] = i * 2 + 1; \
+ b_##TYPE[i] = i % 2 - 2; \
+ } \
+ test##TYPE (N1); \
+ for (i = 0; i < N1; i++) \
+ { \
+ TYPE a1 = i * 2 + 1; \
+ TYPE b1 = i % 2 - 2; \
+ TYPE exp_c = a1 + b1; \
+ if (c_##TYPE[i] != exp_c) \
+ __builtin_abort (); \
+ } \
+ }
+
+TEST_ALL (decl)
+
+int
+main (void)
+{
+ TEST_ALL (run)
+ return 0;
+}
--- /dev/null
+#include "p9-vec-length-3.h"
+
+#define decl(TYPE) \
+ TYPE a_##TYPE[N_##TYPE]; \
+ TYPE b_##TYPE[N_##TYPE]; \
+ TYPE c_##TYPE[N_##TYPE];
+
+#define run(TYPE) \
+ { \
+ unsigned int i = 0; \
+ for (i = 0; i < N_##TYPE; i++) \
+ { \
+ a_##TYPE[i] = i * 2 + 1; \
+ b_##TYPE[i] = i % 2 - 2; \
+ } \
+ test##TYPE (); \
+ for (i = 0; i < N_##TYPE; i++) \
+ { \
+ TYPE a1 = i * 2 + 1; \
+ TYPE b1 = i % 2 - 2; \
+ TYPE exp_c = a1 + b1; \
+ if (c_##TYPE[i] != exp_c) \
+ __builtin_abort (); \
+ } \
+ }
+
+TEST_ALL (decl)
+
+int
+main (void)
+{
+ TEST_ALL (run)
+ return 0;
+}
--- /dev/null
+#include "p9-vec-length-4.h"
+
+/* Check more to ensure vector access with out of bound. */
+#define N 144
+/* Array size used for test function actually. */
+#define NF 123
+
+#define run(TYPE) \
+ { \
+ unsigned int i = 0; \
+ TYPE a[N], b[N * 2], c[N * 4]; \
+ for (i = 0; i < N; i++) \
+ { \
+ a[i] = i + i % 2; \
+ b[i * 2] = i * 2 + i % 3; \
+ b[i * 2 + 1] = i * 3 + i % 4; \
+ c[i * 4] = i * 4 + i % 5; \
+ c[i * 4 + 1] = i * 5 + i % 6; \
+ c[i * 4 + 2] = i * 6 + i % 7; \
+ c[i * 4 + 3] = i * 7 + i % 8; \
+ } \
+ test_mv_##TYPE (a, b, c, NF); \
+ for (i = 0; i < N; i++) \
+ { \
+ TYPE a1 = i + i % 2; \
+ TYPE b1 = i * 2 + i % 3; \
+ TYPE b2 = i * 3 + i % 4; \
+ TYPE c1 = i * 4 + i % 5; \
+ TYPE c2 = i * 5 + i % 6; \
+ TYPE c3 = i * 6 + i % 7; \
+ TYPE c4 = i * 7 + i % 8; \
+ \
+ TYPE exp_a = a1; \
+ TYPE exp_b1 = b1; \
+ TYPE exp_b2 = b2; \
+ TYPE exp_c1 = c1; \
+ TYPE exp_c2 = c2; \
+ TYPE exp_c3 = c3; \
+ TYPE exp_c4 = c4; \
+ if (i < NF) \
+ { \
+ exp_a += 1; \
+ exp_b1 += 2; \
+ exp_b2 += 3; \
+ exp_c1 += 4; \
+ exp_c2 += 5; \
+ exp_c3 += 6; \
+ exp_c4 += 7; \
+ } \
+ if (a[i] != exp_a || b[i * 2] != exp_b1 || b[i * 2 + 1] != exp_b2 \
+ || c[i * 4] != exp_c1 || c[i * 4 + 1] != exp_c2 \
+ || c[i * 4 + 2] != exp_c3 || c[i * 4 + 3] != exp_c4) \
+ __builtin_abort (); \
+ } \
+ }
+
+int
+main (void)
+{
+ TEST_ALL (run)
+ return 0;
+}
--- /dev/null
+#include "p9-vec-length-5.h"
+
+/* Check more to ensure vector access with out of bound. */
+#define N 155
+/* Array size used for test function actually. */
+#define NF 127
+
+#define run(TYPE1, TYPE2) \
+ { \
+ unsigned int i = 0; \
+ TYPE1 a[N * 2]; \
+ TYPE2 b[N * 2]; \
+ for (i = 0; i < N; i++) \
+ { \
+ a[i * 2] = i * 2 + i % 3; \
+ a[i * 2 + 1] = i * 3 + i % 4; \
+ b[i * 2] = i * 7 + i / 5; \
+ b[i * 2 + 1] = i * 8 + i / 6; \
+ } \
+ test_mv_##TYPE1##TYPE2 (a, b, NF); \
+ for (i = 0; i < N; i++) \
+ { \
+ TYPE1 exp_a1 = i * 2 + i % 3; \
+ TYPE1 exp_a2 = i * 3 + i % 4; \
+ TYPE2 exp_b1 = i * 7 + i / 5; \
+ TYPE2 exp_b2 = i * 8 + i / 6; \
+ if (i < NF) \
+ { \
+ exp_a1 += 1; \
+ exp_a2 += 2; \
+ exp_b1 += 3; \
+ exp_b2 += 4; \
+ } \
+ if (a[i * 2] != exp_a1 || a[i * 2 + 1] != exp_a2 || b[i * 2] != exp_b1 \
+ || b[i * 2 + 1] != exp_b2) \
+ __builtin_abort (); \
+ } \
+ }
+
+int
+main (void)
+{
+ TEST_ALL2 (run)
+ return 0;
+}
--- /dev/null
+#include "p9-vec-length-6.h"
+
+/* Check more to ensure vector access with out of bound. */
+#define N 275
+/* Array size used for test function actually. */
+#define NF 255
+
+#define run(TYPE1, TYPE2) \
+ { \
+ unsigned int i = 0; \
+ TYPE1 a[N * 2]; \
+ TYPE2 b[N * 4]; \
+ for (i = 0; i < N; i++) \
+ { \
+ a[i * 2] = i * 2 + i % 3; \
+ a[i * 2 + 1] = i * 3 + i % 4; \
+ b[i * 4] = i * 4 + i / 5; \
+ b[i * 4 + 1] = i * 5 + i / 6; \
+ b[i * 4 + 2] = i * 6 + i / 7; \
+ b[i * 4 + 3] = i * 7 + i / 8; \
+ } \
+ test_mv_##TYPE1##TYPE2 (a, b, NF); \
+ for (i = 0; i < N; i++) \
+ { \
+ TYPE1 exp_a1 = i * 2 + i % 3; \
+ TYPE1 exp_a2 = i * 3 + i % 4; \
+ TYPE2 exp_b1 = i * 4 + i / 5; \
+ TYPE2 exp_b2 = i * 5 + i / 6; \
+ TYPE2 exp_b3 = i * 6 + i / 7; \
+ TYPE2 exp_b4 = i * 7 + i / 8; \
+ if (i < NF) \
+ { \
+ exp_a1 += 1; \
+ exp_a2 += 2; \
+ exp_b1 += 3; \
+ exp_b2 += 4; \
+ exp_b3 += 5; \
+ exp_b4 += 6; \
+ } \
+ if (a[i * 2] != exp_a1 || a[i * 2 + 1] != exp_a2 || b[i * 4] != exp_b1 \
+ || b[i * 4 + 1] != exp_b2 || b[i * 4 + 2] != exp_b3 \
+ || b[i * 4 + 3] != exp_b4) \
+ __builtin_abort (); \
+ } \
+ }
+
+int
+main (void)
+{
+ TEST_ALL2 (run)
+ return 0;
+}
--- /dev/null
+#include "p9-vec-length-7.h"
+
+#define run(TYPE) \
+ { \
+ unsigned int i = 0; \
+ test_npeel_##TYPE(); \
+ for (int i = 0; i < N; ++i) { \
+ if (x_##TYPE[i] != (i < START || i >= END ? 0 : (i - START))) \
+ __builtin_abort(); \
+ } \
+ }
+
+int main() {
+ TEST_ALL(run)
+ return 0;
+}
--- /dev/null
+#include "p9-vec-length-8.h"
+
+#define run(TYPE) \
+ { \
+ unsigned int i = 0; \
+ \
+ TYPE out_##TYPE[N]; \
+ TYPE in_##TYPE[N * 2]; \
+ for (int i = 0; i < N; ++i) { \
+ out_##TYPE[i] = i * 7 / 2; \
+ } \
+ for (int i = 0; i < N * 2; ++i) { \
+ in_##TYPE[i] = i * 9 / 2; \
+ } \
+ \
+ test_##TYPE(out_##TYPE, in_##TYPE); \
+ for (int i = 0; i < N; ++i) { \
+ TYPE expected = i * 7 / 2 + in_##TYPE[i * 2]; \
+ if (out_##TYPE[i] != expected) \
+ __builtin_abort(); \
+ } \
+ }
+
+int main(void) {
+ TEST_ALL(run)
+ return 0;
+}
--- /dev/null
+#include <stdint.h>
+
+#define TEST_ALL(T) \
+ T (int8_t) \
+ T (uint8_t) \
+ T (int16_t) \
+ T (uint16_t) \
+ T (int32_t) \
+ T (uint32_t) \
+ T (int64_t) \
+ T (uint64_t) \
+ T (float) \
+ T (double)
+