tree-optimization/107672 - avoid vector mode type_for_mode call

Message ID 20221122084850.B6CA313B01@imap2.suse-dmz.suse.de
State New
Headers
Series tree-optimization/107672 - avoid vector mode type_for_mode call |

Commit Message

Richard Biener Nov. 22, 2022, 8:48 a.m. UTC
  The following avoids using type_for_mode on vector modes which might
not work for all frontends.  Instead we look for the inner mode
type and use build_vector_type_for_mode instead.

Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed.

	PR tree-optimization/107672
	* tree-vect-stmts.cc (supportable_widening_operation): Avoid
	type_for_mode on vector modes.
---
 gcc/tree-vect-stmts.cc | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)
  

Comments

Vaseeharan Vinayagamoorthy Nov. 25, 2022, 1:30 p.m. UTC | #1
Hi,


I am seeing an internal compiler error, related to this patch:



during GIMPLE pass: slp

options-save.cc: In function 'void cl_optimization_restore(gcc_options*, gcc_options*, cl_optimization*)':

options-save.cc:1292:1: internal compiler error: in supportable_widening_operation, at tree-vect-stmts.cc:12199


 1292 | cl_optimization_restore (struct gcc_options *opts, struct gcc_options *opts_set,

 | ^~~~~~~~~~~~~~~~~~~~~~~

/…/src/gcc/gcc/profile-count.cc: In member function 'int profile_count::to_cgraph_frequency(profile_count) const':

/…/src/gcc/gcc/profile-count.cc:308:1: note: parameter passing for argument of type 'profile_count' changed in GCC 9.1

 308 | profile_count::to_cgraph_frequency (profile_count entry_bb_count) const

 | ^~~~~~~~~~~~~

/…/src/gcc/gcc/profile-count.cc: In member function 'sreal profile_count::to_sreal_scale(profile_count, bool*) const':

/…/src/gcc/gcc/profile-count.cc:326:1: note: parameter passing for argument of type 'profile_count' changed in GCC 9.1

 326 | profile_count::to_sreal_scale (profile_count in, bool *known) const

 | ^~~~~~~~~~~~~

0x2195bdd supportable_widening_operation(vec_info*, tree_code, _stmt_vec_info*, tree_node*, tree_node*, tree_code*, tree_code*, int*, vec<tree_node*, va_heap, vl_ptr>*)

 /…/src/gcc/gcc/tree-vect-stmts.cc:12199

0x2180493 vectorizable_conversion

 /…/src/gcc/gcc/tree-vect-stmts.cc:5064

0x2192fdd vect_analyze_stmt(vec_info*, _stmt_vec_info*, bool*, _slp_tree*, _slp_instance*, vec<stmt_info_for_cost, va_heap, vl_ptr>*)

 /…/src/gcc/gcc/tree-vect-stmts.cc:11256


/…/src/gcc/gcc/profile-count.cc: In member function 'profile_count profile_count::combine_with_ipa_count(profile_count)':

/…/src/gcc/gcc/profile-count.cc:398:1: note: parameter passing for argument of type 'profile_count' changed in GCC 9.1

 398 | profile_count::combine_with_ipa_count (profile_count ipa)

 | ^~~~~~~~~~~~~

0x14f95d1 vect_slp_analyze_node_operations_1

 /…/src/gcc/gcc/tree-vect-slp.cc:5958

0x14f9c19 vect_slp_analyze_node_operations

 /…/src/gcc/gcc/tree-vect-slp.cc:6147

0x14f9b4d vect_slp_analyze_node_operations

 /…/src/gcc/gcc/tree-vect-slp.cc:6126

0x14fa439 vect_slp_analyze_operations(vec_info*)

 /…/src/gcc/gcc/tree-vect-slp.cc:6387

0x14fd423 vect_slp_analyze_bb_1

 /…/src/gcc/gcc/tree-vect-slp.cc:7372

0x14fd599 vect_slp_region

 /…/src/gcc/gcc/tree-vect-slp.cc:7419

0x14fe0d1 vect_slp_bbs

 /…/src/gcc/gcc/tree-vect-slp.cc:7610

0x14fe46f vect_slp_function(function*)

 /…/src/gcc/gcc/tree-vect-slp.cc:7698

0x151a109 execute

 /…/src/gcc/gcc/tree-vectorizer.cc:1532

Please submit a full bug report, with preprocessed source (by using -freport-bug).

Please include the complete backtrace with any bug report.

See <https://gcc.gnu.org/bugs/> for instructions.

Makefile:1146: recipe for target 'options-save.o' failed

make[3]: *** [options-save.o] Error 1


That happens when building the arm-none-linux-gnueabihf toolchain natively with glibc bootstrap:
Build:arm-none-linux-gnueabihf
Host:arm-none-linux-gnueabihf
Target: arm-none-linux-gnueabihf

The compiler being used to build the toolchain is gcc 7.5.0.


Kind regards
Vasee
  
Richard Biener Nov. 25, 2022, 8:08 p.m. UTC | #2
On Fri, 25 Nov 2022, Vaseeharan Vinayagamoorthy wrote:

> Hi,
> 
> I am seeing an internal compiler error, related to this patch:

Can you please open a bugzilla for this and attach preprocessed
source so I can reproduce the ICE with a cc1 cross compiler?

Thanks,
Richard.

> 
> during GIMPLE pass: slp
> 
> options-save.cc: In function 'void cl_optimization_restore(gcc_options*,
> gcc_options*, cl_optimization*)':
> 
> options-save.cc:1292:1: internal compiler error: in
> supportable_widening_operation, at tree-vect-stmts.cc:12199
> 
>  
> 
>  1292 | cl_optimization_restore (struct gcc_options *opts, struct
> gcc_options *opts_set,
> 
>  | ^~~~~~~~~~~~~~~~~~~~~~~
> 
> /…/src/gcc/gcc/profile-count.cc: In member function 'int
> profile_count::to_cgraph_frequency(profile_count) const':
> 
> /…/src/gcc/gcc/profile-count.cc:308:1: note: parameter passing for argument
> of type 'profile_count' changed in GCC 9.1
> 
>  308 | profile_count::to_cgraph_frequency (profile_count entry_bb_count)
> const
> 
>  | ^~~~~~~~~~~~~
> 
> /…/src/gcc/gcc/profile-count.cc: In member function 'sreal
> profile_count::to_sreal_scale(profile_count, bool*) const':
> 
> /…/src/gcc/gcc/profile-count.cc:326:1: note: parameter passing for argument
> of type 'profile_count' changed in GCC 9.1
> 
>  326 | profile_count::to_sreal_scale (profile_count in, bool *known) const
> 
>  | ^~~~~~~~~~~~~
> 
> 0x2195bdd supportable_widening_operation(vec_info*, tree_code,
> _stmt_vec_info*, tree_node*, tree_node*, tree_code*, tree_code*, int*,
> vec<tree_node*, va_heap, vl_ptr>*)
> 
>  /…/src/gcc/gcc/tree-vect-stmts.cc:12199
> 
> 0x2180493 vectorizable_conversion
> 
>  /…/src/gcc/gcc/tree-vect-stmts.cc:5064
> 
> 0x2192fdd vect_analyze_stmt(vec_info*, _stmt_vec_info*, bool*, _slp_tree*,
> _slp_instance*, vec<stmt_info_for_cost, va_heap, vl_ptr>*)
> 
>  /…/src/gcc/gcc/tree-vect-stmts.cc:11256
> 
>  
> 
> /…/src/gcc/gcc/profile-count.cc: In member function 'profile_count
> profile_count::combine_with_ipa_count(profile_count)':
> 
> /…/src/gcc/gcc/profile-count.cc:398:1: note: parameter passing for argument
> of type 'profile_count' changed in GCC 9.1
> 
>  398 | profile_count::combine_with_ipa_count (profile_count ipa)
> 
>  | ^~~~~~~~~~~~~
> 
> 0x14f95d1 vect_slp_analyze_node_operations_1
> 
>  /…/src/gcc/gcc/tree-vect-slp.cc:5958
> 
> 0x14f9c19 vect_slp_analyze_node_operations
> 
>  /…/src/gcc/gcc/tree-vect-slp.cc:6147
> 
> 0x14f9b4d vect_slp_analyze_node_operations
> 
>  /…/src/gcc/gcc/tree-vect-slp.cc:6126
> 
> 0x14fa439 vect_slp_analyze_operations(vec_info*)
> 
>  /…/src/gcc/gcc/tree-vect-slp.cc:6387
> 
> 0x14fd423 vect_slp_analyze_bb_1
> 
>  /…/src/gcc/gcc/tree-vect-slp.cc:7372
> 
> 0x14fd599 vect_slp_region
> 
>  /…/src/gcc/gcc/tree-vect-slp.cc:7419
> 
> 0x14fe0d1 vect_slp_bbs
> 
>  /…/src/gcc/gcc/tree-vect-slp.cc:7610
> 
> 0x14fe46f vect_slp_function(function*)
> 
>  /…/src/gcc/gcc/tree-vect-slp.cc:7698
> 
> 0x151a109 execute
> 
>  /…/src/gcc/gcc/tree-vectorizer.cc:1532
> 
> Please submit a full bug report, with preprocessed source (by using
> -freport-bug).
> 
> Please include the complete backtrace with any bug report.
> 
> See <https://gcc.gnu.org/bugs/> for instructions.
> 
> Makefile:1146: recipe for target 'options-save.o' failed
> 
> make[3]: *** [options-save.o] Error 1
> 
> 
> 
> That happens when building the arm-none-linux-gnueabihf toolchain natively
> with glibc bootstrap:
> Build:arm-none-linux-gnueabihf
> Host:arm-none-linux-gnueabihf
> Target: arm-none-linux-gnueabihf
> 
> The compiler being used to build the toolchain is gcc 7.5.0.
> 
> 
> Kind regards
> Vasee
> 
> ____________________________________________________________________________
> From: Gcc-patches <gcc-patches-bounces+vvinayag=arm.com@gcc.gnu.org> on
> behalf of Richard Biener via Gcc-patches <gcc-patches@gcc.gnu.org>
> Sent: 22 November 2022 08:48
> To: gcc-patches@gcc.gnu.org <gcc-patches@gcc.gnu.org>
> Subject: [PATCH] tree-optimization/107672 - avoid vector mode type_for_mode
> call  
> The following avoids using type_for_mode on vector modes which might
> not work for all frontends.  Instead we look for the inner mode
> type and use build_vector_type_for_mode instead.
> 
> Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed.
> 
>         PR tree-optimization/107672
>         * tree-vect-stmts.cc (supportable_widening_operation): Avoid
>         type_for_mode on vector modes.
> ---
>  gcc/tree-vect-stmts.cc | 12 +++++++++---
>  1 file changed, 9 insertions(+), 3 deletions(-)
> 
> diff --git a/gcc/tree-vect-stmts.cc b/gcc/tree-vect-stmts.cc
> index bc0ef136f19..b35b986889d 100644
> --- a/gcc/tree-vect-stmts.cc
> +++ b/gcc/tree-vect-stmts.cc
> @@ -12195,9 +12195,15 @@ supportable_widening_operation (vec_info *vinfo,
>          intermediate_type
>            = vect_halve_mask_nunits (prev_type, intermediate_mode);
>        else
> -       intermediate_type
> -         = lang_hooks.types.type_for_mode (intermediate_mode,
> -                                           TYPE_UNSIGNED (prev_type));
> +       {
> +         gcc_assert (VECTOR_MODE_P (intermediate_mode));
> +         tree intermediate_element_type
> +           = lang_hooks.types.type_for_mode (GET_MODE_INNER
> (intermediate_mode),
> +                                             TYPE_UNSIGNED (prev_type));
> +         intermediate_type
> +           = build_vector_type_for_mode (intermediate_element_type,
> +                                         intermediate_mode);
> +       }
>  
>        if (VECTOR_BOOLEAN_TYPE_P (intermediate_type)
>            && VECTOR_BOOLEAN_TYPE_P (prev_type)
> --
> 2.35.3
> 
>
  
Alex Coplan Nov. 28, 2022, 4:06 p.m. UTC | #3
Hi Richard,

On 25/11/2022 21:08, Richard Biener via Gcc-patches wrote:
> 
> 
> On Fri, 25 Nov 2022, Vaseeharan Vinayagamoorthy wrote:
> 
> > Hi,
> > 
> > I am seeing an internal compiler error, related to this patch:
> 
> Can you please open a bugzilla for this and attach preprocessed
> source so I can reproduce the ICE with a cc1 cross compiler?

I've raised a PR for this with a reduced testcase here:
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107896

Thanks,
Alex

> 
> Thanks,
> Richard.
> 
> > 
> > during GIMPLE pass: slp
> > 
> > options-save.cc: In function 'void cl_optimization_restore(gcc_options*,
> > gcc_options*, cl_optimization*)':
> > 
> > options-save.cc:1292:1: internal compiler error: in
> > supportable_widening_operation, at tree-vect-stmts.cc:12199
> > 
> > �
> > 
> > �1292 | cl_optimization_restore (struct gcc_options *opts, struct
> > gcc_options *opts_set,
> > 
> > �| ^~~~~~~~~~~~~~~~~~~~~~~
> > 
> > /�/src/gcc/gcc/profile-count.cc: In member function 'int
> > profile_count::to_cgraph_frequency(profile_count) const':
> > 
> > /�/src/gcc/gcc/profile-count.cc:308:1: note: parameter passing for argument
> > of type 'profile_count' changed in GCC 9.1
> > 
> > �308 | profile_count::to_cgraph_frequency (profile_count entry_bb_count)
> > const
> > 
> > �| ^~~~~~~~~~~~~
> > 
> > /�/src/gcc/gcc/profile-count.cc: In member function 'sreal
> > profile_count::to_sreal_scale(profile_count, bool*) const':
> > 
> > /�/src/gcc/gcc/profile-count.cc:326:1: note: parameter passing for argument
> > of type 'profile_count' changed in GCC 9.1
> > 
> > �326 | profile_count::to_sreal_scale (profile_count in, bool *known) const
> > 
> > �| ^~~~~~~~~~~~~
> > 
> > 0x2195bdd supportable_widening_operation(vec_info*, tree_code,
> > _stmt_vec_info*, tree_node*, tree_node*, tree_code*, tree_code*, int*,
> > vec<tree_node*, va_heap, vl_ptr>*)
> > 
> > �/�/src/gcc/gcc/tree-vect-stmts.cc:12199
> > 
> > 0x2180493 vectorizable_conversion
> > 
> > �/�/src/gcc/gcc/tree-vect-stmts.cc:5064
> > 
> > 0x2192fdd vect_analyze_stmt(vec_info*, _stmt_vec_info*, bool*, _slp_tree*,
> > _slp_instance*, vec<stmt_info_for_cost, va_heap, vl_ptr>*)
> > 
> > �/�/src/gcc/gcc/tree-vect-stmts.cc:11256
> > 
> > �
> > 
> > /�/src/gcc/gcc/profile-count.cc: In member function 'profile_count
> > profile_count::combine_with_ipa_count(profile_count)':
> > 
> > /�/src/gcc/gcc/profile-count.cc:398:1: note: parameter passing for argument
> > of type 'profile_count' changed in GCC 9.1
> > 
> > �398 | profile_count::combine_with_ipa_count (profile_count ipa)
> > 
> > �| ^~~~~~~~~~~~~
> > 
> > 0x14f95d1 vect_slp_analyze_node_operations_1
> > 
> > �/�/src/gcc/gcc/tree-vect-slp.cc:5958
> > 
> > 0x14f9c19 vect_slp_analyze_node_operations
> > 
> > �/�/src/gcc/gcc/tree-vect-slp.cc:6147
> > 
> > 0x14f9b4d vect_slp_analyze_node_operations
> > 
> > �/�/src/gcc/gcc/tree-vect-slp.cc:6126
> > 
> > 0x14fa439 vect_slp_analyze_operations(vec_info*)
> > 
> > �/�/src/gcc/gcc/tree-vect-slp.cc:6387
> > 
> > 0x14fd423 vect_slp_analyze_bb_1
> > 
> > �/�/src/gcc/gcc/tree-vect-slp.cc:7372
> > 
> > 0x14fd599 vect_slp_region
> > 
> > �/�/src/gcc/gcc/tree-vect-slp.cc:7419
> > 
> > 0x14fe0d1 vect_slp_bbs
> > 
> > �/�/src/gcc/gcc/tree-vect-slp.cc:7610
> > 
> > 0x14fe46f vect_slp_function(function*)
> > 
> > �/�/src/gcc/gcc/tree-vect-slp.cc:7698
> > 
> > 0x151a109 execute
> > 
> > �/�/src/gcc/gcc/tree-vectorizer.cc:1532
> > 
> > Please submit a full bug report, with preprocessed source (by using
> > -freport-bug).
> > 
> > Please include the complete backtrace with any bug report.
> > 
> > See <https://gcc.gnu.org/bugs/> for instructions.
> > 
> > Makefile:1146: recipe for target 'options-save.o' failed
> > 
> > make[3]: *** [options-save.o] Error 1
> > 
> > 
> > 
> > That happens when building the�arm-none-linux-gnueabihf toolchain natively
> > with glibc bootstrap:
> > Build:arm-none-linux-gnueabihf
> > Host:arm-none-linux-gnueabihf
> > Target: arm-none-linux-gnueabihf
> > 
> > The compiler being used to build the toolchain is gcc 7.5.0.
> > 
> > 
> > Kind regards
> > Vasee
> > 
> > ____________________________________________________________________________
> > From: Gcc-patches <gcc-patches-bounces+vvinayag=arm.com@gcc.gnu.org> on
> > behalf of Richard Biener via Gcc-patches <gcc-patches@gcc.gnu.org>
> > Sent: 22 November 2022 08:48
> > To: gcc-patches@gcc.gnu.org <gcc-patches@gcc.gnu.org>
> > Subject: [PATCH] tree-optimization/107672 - avoid vector mode type_for_mode
> > call �
> > The following avoids using type_for_mode on vector modes which might
> > not work for all frontends.� Instead we look for the inner mode
> > type and use build_vector_type_for_mode instead.
> > 
> > Bootstrapped and tested on x86_64-unknown-linux-gnu, pushed.
> > 
> > ������� PR tree-optimization/107672
> > ������� * tree-vect-stmts.cc (supportable_widening_operation): Avoid
> > ������� type_for_mode on vector modes.
> > ---
> > �gcc/tree-vect-stmts.cc | 12 +++++++++---
> > �1 file changed, 9 insertions(+), 3 deletions(-)
> > 
> > diff --git a/gcc/tree-vect-stmts.cc b/gcc/tree-vect-stmts.cc
> > index bc0ef136f19..b35b986889d 100644
> > --- a/gcc/tree-vect-stmts.cc
> > +++ b/gcc/tree-vect-stmts.cc
> > @@ -12195,9 +12195,15 @@ supportable_widening_operation (vec_info *vinfo,
> > �������� intermediate_type
> > ���������� = vect_halve_mask_nunits (prev_type, intermediate_mode);
> > ������ else
> > -������ intermediate_type
> > -�������� = lang_hooks.types.type_for_mode (intermediate_mode,
> > -������������������������������������������ TYPE_UNSIGNED (prev_type));
> > +������ {
> > +�������� gcc_assert (VECTOR_MODE_P (intermediate_mode));
> > +�������� tree intermediate_element_type
> > +���������� = lang_hooks.types.type_for_mode (GET_MODE_INNER
> > (intermediate_mode),
> > +�������������������������������������������� TYPE_UNSIGNED (prev_type));
> > +�������� intermediate_type
> > +���������� = build_vector_type_for_mode (intermediate_element_type,
> > +���������������������������������������� intermediate_mode);
> > +������ }
> > �
> > ������ if (VECTOR_BOOLEAN_TYPE_P (intermediate_type)
> > ���������� && VECTOR_BOOLEAN_TYPE_P (prev_type)
> > --
> > 2.35.3
> > 
> >
  

Patch

diff --git a/gcc/tree-vect-stmts.cc b/gcc/tree-vect-stmts.cc
index bc0ef136f19..b35b986889d 100644
--- a/gcc/tree-vect-stmts.cc
+++ b/gcc/tree-vect-stmts.cc
@@ -12195,9 +12195,15 @@  supportable_widening_operation (vec_info *vinfo,
 	intermediate_type
 	  = vect_halve_mask_nunits (prev_type, intermediate_mode);
       else
-	intermediate_type
-	  = lang_hooks.types.type_for_mode (intermediate_mode,
-					    TYPE_UNSIGNED (prev_type));
+	{
+	  gcc_assert (VECTOR_MODE_P (intermediate_mode));
+	  tree intermediate_element_type
+	    = lang_hooks.types.type_for_mode (GET_MODE_INNER (intermediate_mode),
+					      TYPE_UNSIGNED (prev_type));
+	  intermediate_type
+	    = build_vector_type_for_mode (intermediate_element_type,
+					  intermediate_mode);
+	}
 
       if (VECTOR_BOOLEAN_TYPE_P (intermediate_type)
 	  && VECTOR_BOOLEAN_TYPE_P (prev_type)