The purpose of the function is to peel off type casts to find out root definition for a given value. If patterns are involved, intermediate pattern-defined SSAs would be traversed instead of the originals. A subtlety here is that the root SSA (as the return value) might be the original one, even it has been recognized as a pattern. For example, a = (T1) patt_b; patt_b = (T2) c; // b = ... patt_c = not-a-cast; // c = old_seq Given 'a', the function will return 'c', instead of 'patt_c'. If a caller only does something based on type information of returned SSA, there is no problem. But if caller's pattern recog analysis is to parse definition statement of the SSA, the new pattern statement is bypassed. This tends to be inconsistent with processing logic of the pattern formation pass, which is not quite rational, and seems to be an issue, though does not cause any mistake. Anything that I missed here? Take one code snippet as example: vect_recog_mulhs_pattern () { ... vect_unpromoted_value unprom_rshift_input; tree rshift_input = vect_look_through_possible_promotion (vinfo, gimple_assign_rhs1 (last_stmt), &unprom_rshift_input); ... /* Get the definition of the shift input. */ stmt_vec_info rshift_input_stmt_info = vect_get_internal_def (vinfo, rshift_input); if (!rshift_input_stmt_info) return NULL; gassign *rshift_input_stmt = dyn_cast <gassign *> (rshift_input_stmt_info->stmt); if (!rshift_input_stmt) return NULL; ... if (gimple_assign_rhs_code (rshift_input_stmt) == PLUS_EXPR) // How about if rshift_input_stmt has a pattern replacement? { ... }
Confirmed. Probably vect_get_internal_def itself should concern itself with this.
The master branch has been updated by Feng Xue <fxue@gcc.gnu.org>: https://gcc.gnu.org/g:a3aeff4ce95bd616a2108dc2363d9cbaba53b170 commit r15-863-ga3aeff4ce95bd616a2108dc2363d9cbaba53b170 Author: Feng Xue <fxue@os.amperecomputing.com> Date: Thu May 23 15:25:53 2024 +0800 vect: Use vect representative statement instead of original in patch recog [PR115060] Some utility functions (such as vect_look_through_possible_promotion) that are to find out certain kind of direct or indirect definition SSA for a value, may return the original one of the SSA, not its pattern representative SSA, even pattern is involved. For example, a = (T1) patt_b; patt_b = (T2) c; // b = ... patt_c = not-a-cast; // c = ... Given 'a', the mentioned function will return 'c', instead of 'patt_c'. This subtlety would make some pattern recog code that is unaware of it mis-use the original instead of the new pattern statement, which is inconsistent wth processing logic of the pattern formation pass. This patch corrects the issue by forcing another utility function (vect_get_internal_def) return the pattern statement information to caller by default. 2024-05-23 Feng Xue <fxue@os.amperecomputing.com> gcc/ PR tree-optimization/115060 * tree-vect-patterns.cc (vect_get_internal_def): Return statement for vectorization. (vect_widened_op_tree): Call vect_get_internal_def instead of look_def to get statement information. (vect_recog_widen_abd_pattern): No need to call vect_stmt_to_vectorize.
Linaro reported a regression: https://linaro.atlassian.net/browse/GNU-1226 Actually, this is not, but exposes a new bug in vect_look_through_possible_promotion. The function fails to figure out root definition if casts involves more than two promotions with sign change as: long a = (long)b; // promotion cast -> int b = (int)c; // promotion cast, sign change -> unsigned short c = ...; For this case, the function thinks the 2nd cast has different sign as the 1st, so stop looking through, while "unsigned short -> integer" is a nature sign extension.
*** Bug 115707 has been marked as a duplicate of this bug. ***
Fixed.
(In reply to Feng Xue from comment #5) > Fixed. I confirmed that I don't see the failure anymore. Thank you!