On Fri, 28 Apr 2023, Andre Vieira (lists) wrote: > Hi, > > I'm posting the patches separately now with ChangeLogs. > > I made the suggested changes and tried to simplify the code a bit further. > Where internal to tree-vect-stmts I changed most functions to use code_helper > to avoid having to check at places we didn't need to. I was trying to simplify > things further by also modifying supportable_half_widening_operation and > supportable_convert_operation but the result of that was that I ended up > moving the code to cast to tree code inside them rather than at the call site > and it didn't look simpler, so I left those. Though if we did make those > changes we'd no longer need to keep around the tc1 variable in > vectorizable_conversion... Let me know what you think.
I see that - else if (CONVERT_EXPR_CODE_P (code) + else if (CONVERT_EXPR_CODE_P (code.safe_as_tree_code ()) is convenient (as much as I dislike safe_as_tree_code). Isn't the following - if (!CONVERT_EXPR_CODE_P (code)) + if (!CONVERT_EXPR_CODE_P ((tree_code) code)) return false; then wrong? In other places you added an assert - I assume that we might want to checking assert in the cast operators? (those were added mainly for convenience, maybe we want as_a <>, etc. here - not sure if those will play well with enums though). Just suggestions for eventual followups in this area. +inline enum tree_code +code_helper::safe_as_tree_code () const +{ + return is_tree_code () ? (tree_code) *this : MAX_TREE_CODES; +} + +inline combined_fn +code_helper::safe_as_fn_code () const { + return is_fn_code () ? (combined_fn) *this : CFN_LAST; +} + newline after the last 'const'. Can you place a comment before these to explain their intended use? Aka give the case the code isn't the desired kind a safe value? The patch is OK with just the last bit fixed. Thanks, Richard. > gcc/ChangeLog: > > 2023-04-28 Andre Vieira <andre.simoesdiasvie...@arm.com> > Joel Hutton <joel.hut...@arm.com> > > * tree-vect-patterns.cc (vect_gimple_build): New Function. > (vect_recog_widen_op_pattern): Refactor to use code_helper. > * tree-vect-stmts.cc (vect_gen_widened_results_half): Likewise. > (vect_create_vectorized_demotion_stmts): Likewise. > (vect_create_vectorized_promotion_stmts): Likewise. > (vect_create_half_widening_stmts): Likewise. > (vectorizable_conversion): Likewise. > (vectorizable_call): Likewise. > (supportable_widening_operation): Likewise. > (supportable_narrowing_operation): Likewise. > (simple_integer_narrowing): Likewise. > * tree-vectorizer.h (supportable_widening_operation): Likewise. > (supportable_narrowing_operation): Likewise. > (vect_gimple_build): New function prototype. > * tree.h (code_helper::safe_as_tree_code): New function. > (code_helper::safe_as_fn_code): New function. > -- Richard Biener <rguent...@suse.de> SUSE Software Solutions Germany GmbH, Frankenstrasse 146, 90461 Nuernberg, Germany; GF: Ivo Totev, Andrew Myers, Andrew McDonald, Boudien Moerman; HRB 36809 (AG Nuernberg)