diff mbox

[vec-tails,02/10] Extend _loop_vec_info structure with epilogue related fields

Message ID 20160519193811.GC40563@msticlxl57.ims.intel.com
State New
Headers show

Commit Message

Ilya Enkovich May 19, 2016, 7:38 p.m. UTC
Hi,

This patch adds new fields to _loop_vec_info structure to support loop
epilogue vectorization.

Thanks,
Ilya
--
gcc/

2016-05-19  Ilya Enkovich  <ilya.enkovich@intel.com>

	* tree-vectorizer.h (struct _loop_vec_info): Add new fields
	can_be_masked, required_masks, mask_epilogue, combine_epilogue,
	need_masking, orig_loop_info.
	(LOOP_VINFO_CAN_BE_MASKED): New.
	(LOOP_VINFO_REQUIRED_MASKS): New.
	(LOOP_VINFO_COMBINE_EPILOGUE): New.
	(LOOP_VINFO_MASK_EPILOGUE): New.
	(LOOP_VINFO_NEED_MASKING): New.
	(LOOP_VINFO_ORIG_LOOP_INFO): New.
	(LOOP_VINFO_EPILOGUE_P): New.
	(LOOP_VINFO_ORIG_MASK_EPILOGUE): New.
	(LOOP_VINFO_ORIG_VECT_FACTOR): New.
	* tree-vect-loop.c (new_loop_vec_info): Initialize new
	_loop_vec_info fields.

Comments

Jeff Law June 16, 2016, 5:11 a.m. UTC | #1
On 05/19/2016 01:38 PM, Ilya Enkovich wrote:
> Hi,
>
> This patch adds new fields to _loop_vec_info structure to support loop
> epilogue vectorization.
>
> Thanks,
> Ilya
> --
> gcc/
>
> 2016-05-19  Ilya Enkovich  <ilya.enkovich@intel.com>
>
> 	* tree-vectorizer.h (struct _loop_vec_info): Add new fields
> 	can_be_masked, required_masks, mask_epilogue, combine_epilogue,
> 	need_masking, orig_loop_info.
> 	(LOOP_VINFO_CAN_BE_MASKED): New.
> 	(LOOP_VINFO_REQUIRED_MASKS): New.
> 	(LOOP_VINFO_COMBINE_EPILOGUE): New.
> 	(LOOP_VINFO_MASK_EPILOGUE): New.
> 	(LOOP_VINFO_NEED_MASKING): New.
> 	(LOOP_VINFO_ORIG_LOOP_INFO): New.
> 	(LOOP_VINFO_EPILOGUE_P): New.
> 	(LOOP_VINFO_ORIG_MASK_EPILOGUE): New.
> 	(LOOP_VINFO_ORIG_VECT_FACTOR): New.
> 	* tree-vect-loop.c (new_loop_vec_info): Initialize new
> 	_loop_vec_info fields.
I don't see anything here that is inherently wrong/bad here; I think 
this would be fine once the whole set is approved.   I also think if you 
find that you need additional similar kinds of fields, that would be OK 
as well.

The one question I would ask -- do we ever need to copy VINFO data from 
one loop to a duplicate, and if so, ISTM that the code to copy that data 
would be a part of this patch.

jeff
Ilya Enkovich June 16, 2016, 4:10 p.m. UTC | #2
2016-06-16 8:11 GMT+03:00 Jeff Law <law@redhat.com>:
> On 05/19/2016 01:38 PM, Ilya Enkovich wrote:
>>
>> Hi,
>>
>> This patch adds new fields to _loop_vec_info structure to support loop
>> epilogue vectorization.
>>
>> Thanks,
>> Ilya
>> --
>> gcc/
>>
>> 2016-05-19  Ilya Enkovich  <ilya.enkovich@intel.com>
>>
>>         * tree-vectorizer.h (struct _loop_vec_info): Add new fields
>>         can_be_masked, required_masks, mask_epilogue, combine_epilogue,
>>         need_masking, orig_loop_info.
>>         (LOOP_VINFO_CAN_BE_MASKED): New.
>>         (LOOP_VINFO_REQUIRED_MASKS): New.
>>         (LOOP_VINFO_COMBINE_EPILOGUE): New.
>>         (LOOP_VINFO_MASK_EPILOGUE): New.
>>         (LOOP_VINFO_NEED_MASKING): New.
>>         (LOOP_VINFO_ORIG_LOOP_INFO): New.
>>         (LOOP_VINFO_EPILOGUE_P): New.
>>         (LOOP_VINFO_ORIG_MASK_EPILOGUE): New.
>>         (LOOP_VINFO_ORIG_VECT_FACTOR): New.
>>         * tree-vect-loop.c (new_loop_vec_info): Initialize new
>>         _loop_vec_info fields.
>
> I don't see anything here that is inherently wrong/bad here; I think this
> would be fine once the whole set is approved.   I also think if you find
> that you need additional similar kinds of fields, that would be OK as well.
>
> The one question I would ask -- do we ever need to copy VINFO data from one
> loop to a duplicate, and if so, ISTM that the code to copy that data would
> be a part of this patch.

AFAIK we currently never copy vectorized loop in vectorizer.  I never saw VINFO
to be copied and I don't see corresponding API in tree-vectorizer.h.
I'll double-check it.

Thanks,
Ilya

>
> jeff
>
diff mbox

Patch

diff --git a/gcc/tree-vect-loop.c b/gcc/tree-vect-loop.c
index da98211..aac0df9 100644
--- a/gcc/tree-vect-loop.c
+++ b/gcc/tree-vect-loop.c
@@ -1125,6 +1125,12 @@  new_loop_vec_info (struct loop *loop)
   LOOP_VINFO_PEELING_FOR_GAPS (res) = false;
   LOOP_VINFO_PEELING_FOR_NITER (res) = false;
   LOOP_VINFO_OPERANDS_SWAPPED (res) = false;
+  LOOP_VINFO_CAN_BE_MASKED (res) = false;
+  LOOP_VINFO_REQUIRED_MASKS (res) = 0;
+  LOOP_VINFO_COMBINE_EPILOGUE (res) = false;
+  LOOP_VINFO_MASK_EPILOGUE (res) = false;
+  LOOP_VINFO_NEED_MASKING (res) = false;
+  LOOP_VINFO_ORIG_LOOP_INFO (res) = NULL;
 
   return res;
 }
diff --git a/gcc/tree-vectorizer.h b/gcc/tree-vectorizer.h
index bd1d55a..4c19317 100644
--- a/gcc/tree-vectorizer.h
+++ b/gcc/tree-vectorizer.h
@@ -336,6 +336,23 @@  typedef struct _loop_vec_info : public vec_info {
   /* Mark loops having masked stores.  */
   bool has_mask_store;
 
+  /* True if vectorized loop can be masked.  */
+  bool can_be_masked;
+  /* If vector mask with 2^N elements is required to mask the loop
+     then N-th bit of this field is set to 1.  */
+  unsigned required_masks;
+
+  /* True if we should vectorize loop epilogue with masking.  */
+  bool mask_epilogue;
+  /* True if we should combine main loop with epilogue using masking.  */
+  bool combine_epilogue;
+  /* True if loop vectorization requires masking.  E.g. we want to
+     vectorize loop with low trip count.  */
+  bool need_masking;
+  /* For loops being epilogues of already vectorized loops
+     this points to the original vectorized loop.  Otherwise NULL.  */
+  _loop_vec_info *orig_loop_info;
+
 } *loop_vec_info;
 
 /* Access Functions.  */
@@ -374,6 +391,12 @@  typedef struct _loop_vec_info : public vec_info {
 #define LOOP_VINFO_HAS_MASK_STORE(L)       (L)->has_mask_store
 #define LOOP_VINFO_SCALAR_ITERATION_COST(L) (L)->scalar_cost_vec
 #define LOOP_VINFO_SINGLE_SCALAR_ITERATION_COST(L) (L)->single_scalar_iteration_cost
+#define LOOP_VINFO_CAN_BE_MASKED(L)        (L)->can_be_masked
+#define LOOP_VINFO_REQUIRED_MASKS(L)       (L)->required_masks
+#define LOOP_VINFO_COMBINE_EPILOGUE(L)     (L)->combine_epilogue
+#define LOOP_VINFO_MASK_EPILOGUE(L)        (L)->mask_epilogue
+#define LOOP_VINFO_NEED_MASKING(L)         (L)->need_masking
+#define LOOP_VINFO_ORIG_LOOP_INFO(L)       (L)->orig_loop_info
 
 #define LOOP_REQUIRES_VERSIONING_FOR_ALIGNMENT(L) \
   ((L)->may_misalign_stmts.length () > 0)
@@ -383,6 +406,14 @@  typedef struct _loop_vec_info : public vec_info {
 #define LOOP_VINFO_NITERS_KNOWN_P(L)          \
   (tree_fits_shwi_p ((L)->num_iters) && tree_to_shwi ((L)->num_iters) > 0)
 
+#define LOOP_VINFO_EPILOGUE_P(L) \
+  (LOOP_VINFO_ORIG_LOOP_INFO(L) != NULL)
+
+#define LOOP_VINFO_ORIG_MASK_EPILOGUE(L) \
+  (LOOP_VINFO_MASK_EPILOGUE (LOOP_VINFO_ORIG_LOOP_INFO(L)))
+#define LOOP_VINFO_ORIG_VECT_FACTOR(L) \
+  (LOOP_VINFO_VECT_FACTOR (LOOP_VINFO_ORIG_LOOP_INFO(L)))
+
 static inline loop_vec_info
 loop_vec_info_for_loop (struct loop *loop)
 {