This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[patch][autovect]Add option ftree-vect-loop-version
- From: Keith Besaw <kbesaw at us dot ibm dot com>
- To: gcc-patches at gcc dot gnu dot org
- Cc: Dorit Naishlos <DORIT at il dot ibm dot com>
- Date: Fri, 18 Mar 2005 01:14:31 -0600
- Subject: [patch][autovect]Add option ftree-vect-loop-version
This patch adds the ftree-vect-loop-version option.
Data alignment and data dependencies that cannot be determined at
compile-time may inhibit vectorization. One way around this is to
generate
a vectorized version along with the original scalar version of a loop and
add
runtime alignment or dependence checks that determine which loop is
actually
executed. Because this can cause code bloat this patch adds a new option
so that loop versioning for vectorization can be turned off.
The default is to perform loop versioning when the ftree-vectorize option
is specified.
fno-tree-vect-loop-version is used to turn off vectorizing by loop
versioning.
tested on ppc
OK for autovec branch?
Thanks, Keith
Changelog entry:
2005-03-11 Keith Besaw <kbesaw@us.ibm.com>
* common.opt: add the ftree-vect-loop-version option
and the flag flag_tree_vect_loop_version initialized to 1.
* tree-vect-analyze.c (vect_enhance_data_refs_alignment):
Add checks of flag_tree_vect_loop_version.
* invoke.texi: Add documentation for
ftree-vect-loop-version.
Index: common.opt
===================================================================
RCS file: /cvsroot/gcc/gcc/gcc/common.opt,v
retrieving revision 1.59.4.5
diff -c -3 -p -r1.59.4.5 common.opt
*** common.opt 16 Feb 2005 13:55:31 -0000 1.59.4.5
--- common.opt 17 Mar 2005 23:35:57 -0000
*************** ftree-vectorize
*** 924,929 ****
--- 924,933 ----
Common Report Var(flag_tree_vectorize)
Enable loop vectorization on trees
+ ftree-vect-loop-version
+ Common Report Var(flag_tree_vect_loop_version) Init(1)
+ Enable loop versioning when doing loop vectorization on trees
+
ftree-vectorizer-verbose=
Common RejectNegative Joined
-ftree-vectorizer-verbose=<number> Set the verbosity level of the
vectorizer
Index: tree-vect-analyze.c
===================================================================
RCS file: /cvsroot/gcc/gcc/gcc/tree-vect-analyze.c,v
retrieving revision 2.4.4.6
diff -c -3 -p -r2.4.4.6 tree-vect-analyze.c
*** tree-vect-analyze.c 13 Mar 2005 10:43:22 -0000 2.4.4.6
--- tree-vect-analyze.c 17 Mar 2005 23:35:57 -0000
*************** vect_enhance_data_refs_alignment (loop_v
*** 1048,1114 ****
/* (2) Versioning to force alignment. */
/* Try versioning if:
! 1) there is at least one unsupported misaligned data ref with an
unknown
misalignment, and
! 2) all misaligned data refs with a known misalignment are
supported, and
! 3) the number of runtime alignment checks is within reason. */
! do_versioning = true;
! datarefs = loop_datarefs;
! for (i = 0; i < VARRAY_ACTIVE_SIZE (datarefs); i++)
{
! struct data_reference *dr = VARRAY_GENERIC_PTR (datarefs, i);
! if (aligned_access_p (dr))
! continue;
! supportable_dr_alignment = vect_supportable_dr_alignment (dr);
! if (!supportable_dr_alignment)
! {
! tree stmt;
! int mask;
! tree vectype;
!
! if (known_alignment_for_access_p (dr)
! || VARRAY_ACTIVE_SIZE (LOOP_VINFO_MAY_MISALIGN_STMTS
(loop_vinfo))
! >= MAX_RUNTIME_ALIGNMENT_CHECKS)
! {
! do_versioning = false;
! break;
! }
! stmt = DR_STMT (dr);
! vectype = STMT_VINFO_VECTYPE (vinfo_for_stmt (stmt));
! gcc_assert (vectype);
!
! /* The rightmost bits of an aligned address must be zeros.
! Construct the mask needed for this test. For example,
! GET_MODE_SIZE for the vector mode V4SI is 16 bytes so the
! mask must be 15 = 0xf. */
! mask = GET_MODE_SIZE (TYPE_MODE (vectype)) - 1;
!
! /* FORNOW: using the same mask to test all potentially unaligned
! references in the loop. The vectorizer currently supports a
! single vector size, see the reference to
! GET_MODE_NUNITS (TYPE_MODE (vectype)) where the vectorization
! factor is computed. */
! gcc_assert (!LOOP_VINFO_PTR_MASK (loop_vinfo)
! || LOOP_VINFO_PTR_MASK (loop_vinfo) == mask);
! LOOP_VINFO_PTR_MASK (loop_vinfo) = mask;
! VARRAY_PUSH_TREE (LOOP_VINFO_MAY_MISALIGN_STMTS (loop_vinfo),
! DR_STMT (dr));
! }
! if (!do_versioning)
! {
! varray_clear (LOOP_VINFO_MAY_MISALIGN_STMTS (loop_vinfo));
! break;
}
- }
! /* Versioning requires at least one candidate misaligned data
reference. */
! if (VARRAY_ACTIVE_SIZE (LOOP_VINFO_MAY_MISALIGN_STMTS (loop_vinfo)) ==
0)
! do_versioning = false;
if (do_versioning)
{
--- 1048,1116 ----
/* (2) Versioning to force alignment. */
/* Try versioning if:
! 1) flag_tree_vect_loop_version is TRUE
! 2) there is at least one unsupported misaligned data ref with an
unknown
misalignment, and
! 3) all misaligned data refs with a known misalignment are
supported, and
! 4) the number of runtime alignment checks is within reason. */
!
! do_versioning = flag_tree_vect_loop_version;
!
! if (do_versioning)
{
! datarefs = loop_datarefs;
! for (i = 0; i < VARRAY_ACTIVE_SIZE (datarefs); i++)
! {
! struct data_reference *dr = VARRAY_GENERIC_PTR (datarefs, i);
! if (aligned_access_p (dr))
! continue;
! supportable_dr_alignment = vect_supportable_dr_alignment (dr);
! if (!supportable_dr_alignment)
! {
! tree stmt;
! int mask;
! tree vectype;
!
! if (known_alignment_for_access_p (dr)
! || VARRAY_ACTIVE_SIZE (LOOP_VINFO_MAY_MISALIGN_STMTS
(loop_vinfo))
! >= MAX_RUNTIME_ALIGNMENT_CHECKS)
! {
! do_versioning = false;
! break;
! }
! stmt = DR_STMT (dr);
! vectype = STMT_VINFO_VECTYPE (vinfo_for_stmt (stmt));
! gcc_assert (vectype);
! /* The rightmost bits of an aligned address must be zeros.
! Construct the mask needed for this test. For example,
! GET_MODE_SIZE for the vector mode V4SI is 16 bytes so
the
! mask must be 15 = 0xf. */
! mask = GET_MODE_SIZE (TYPE_MODE (vectype)) - 1;
!
! /* FORNOW: using the same mask to test all potentially
unaligned
! references in the loop. The vectorizer currently
supports a
! single vector size, see the reference to
! GET_MODE_NUNITS (TYPE_MODE (vectype)) where the
vectorization
! factor is computed. */
! gcc_assert (!LOOP_VINFO_PTR_MASK (loop_vinfo)
! || LOOP_VINFO_PTR_MASK (loop_vinfo) == mask);
! LOOP_VINFO_PTR_MASK (loop_vinfo) = mask;
! VARRAY_PUSH_TREE (LOOP_VINFO_MAY_MISALIGN_STMTS
(loop_vinfo),
! DR_STMT (dr));
! }
}
! /* Versioning requires at least one candidate misaligned data
reference. */
! if (VARRAY_ACTIVE_SIZE (LOOP_VINFO_MAY_MISALIGN_STMTS
(loop_vinfo)) == 0)
! do_versioning = false;
! else if (!do_versioning)
! varray_clear (LOOP_VINFO_MAY_MISALIGN_STMTS (loop_vinfo));
! }
if (do_versioning)
{
*************** vect_enhance_data_refs_alignment (loop_v
*** 1124,1130 ****
stmt_vec_info stmt_info = vinfo_for_stmt (stmt);
struct data_reference *dr = STMT_VINFO_DATA_REF (stmt_info);
DR_MISALIGNMENT (dr) = 0;
! if (vect_print_dump_info (REPORT_UNVECTORIZED_LOOPS,
LOOP_LOC (loop_vinfo)))
fprintf (vect_dump, "Alignment of access forced using
versioning.");
}
--- 1126,1132 ----
stmt_vec_info stmt_info = vinfo_for_stmt (stmt);
struct data_reference *dr = STMT_VINFO_DATA_REF (stmt_info);
DR_MISALIGNMENT (dr) = 0;
! if (vect_print_dump_info (REPORT_ALIGNMENT,
LOOP_LOC (loop_vinfo)))
fprintf (vect_dump, "Alignment of access forced using
versioning.");
}
Index: doc/invoke.texi
===================================================================
RCS file: /cvsroot/gcc/gcc/gcc/doc/invoke.texi,v
retrieving revision 1.557.2.4
diff -c -3 -p -r1.557.2.4 invoke.texi
*** doc/invoke.texi 16 Feb 2005 13:55:38 -0000 1.557.2.4
--- doc/invoke.texi 17 Mar 2005 23:35:59 -0000
*************** Objective-C and Objective-C++ Dialects}.
*** 321,327 ****
-ftree-pre -ftree-ccp -ftree-dce -ftree-loop-optimize @gol
-ftree-loop-linear -ftree-loop-im -ftree-loop-ivcanon -fivopts @gol
-ftree-dominator-opts -ftree-dse -ftree-copyrename @gol
! -ftree-ch -ftree-sra -ftree-ter -ftree-lrs -ftree-fre -ftree-vectorize
@gol
-ftree-elim-checks @gol
--param @var{name}=@var{value}
-O -O0 -O1 -O2 -O3 -Os}
--- 321,328 ----
-ftree-pre -ftree-ccp -ftree-dce -ftree-loop-optimize @gol
-ftree-loop-linear -ftree-loop-im -ftree-loop-ivcanon -fivopts @gol
-ftree-dominator-opts -ftree-dse -ftree-copyrename @gol
! -ftree-ch -ftree-sra -ftree-ter -ftree-lrs -ftree-fre @gol
! -ftree-vectorize -ftree-vect-loop-version @gol
-ftree-elim-checks @gol
--param @var{name}=@var{value}
-O -O0 -O1 -O2 -O3 -Os}
*************** optimization later. This is enabled by
*** 4721,4726 ****
--- 4722,4735 ----
@item -ftree-vectorize
Perform loop vectorization on trees.
+ @item -ftree-vect-loop-version
+ @opindex ftree-vect-loop-version
+ Perform loop versioning when doing loop vectorization on trees. When a
loop
+ appears to be vectorizable except that data alignment or data dependence
cannot
+ be determined at compile time then vectorized and non-vectorized
versions of
+ the loop are generated along with runtime checks for alignment or
dependence
+ to control which version is executed. This option is enabled by
default.
+
@item -ftracer
@opindex ftracer
Perform tail duplication to enlarge superblock size. This
transformation