https://gcc.gnu.org/bugzilla/show_bug.cgi?id=128658
--- Comment #4 from GCC Commits <cvs-commit at gcc dot gnu.org> --- The master branch has been updated by Richard Biener <[email protected]>: https://gcc.gnu.org/g:b14dc9ddea18a3d1fd7bd05bfaf8c572bf08f428 commit r17-6472-gb14dc9ddea18a3d1fd7bd05bfaf8c572bf08f428 Author: Richard Biener <[email protected]> Date: Thu Nov 19 13:43:53 2026 +0100 tree-optimization/128658 do not set min_input_precision for non-truncatable operations In vect_determine_precisions_from_range, value_precision is computed from the ranges of the LHS and RHS operands. For non-truncatable operations such as TRUNC_DIV_EXPR, the determined input precision only holds if the operation is actually narrowed. When doing BB vectorization a stmt may stay scalar and so a truncated input can cause wrong-code. I have opted to disable the propagation for both loop and BB vectorization though technically loop vectorization should never hit this issue. THere is a similar issue with shifts: vect_determine_precisions_from_users computes min_input_precision for LSHIFT_EXPR and RSHIFT_EXPR based on the shift amount, and that precision only applies to the shifted value, not to the shift count. vect_determine_min_output_precision_1 however propagated use_stmt_info->min_input_precision to all uses, including the shift count. For a left shift by an amount in [MIN, MAX] the recorded input precision can be smaller than the number of bits needed to represent the shift amount itself, so the def chain feeding the shift count could be narrowed and compute a wrong shift amount. PR tree-optimization/128658 * tree-vect-patterns.cc (vect_determine_precisions_from_range): Only call vect_set_min_input_precision if vect_truncatable_operation_p. (vect_determine_min_output_precision_1): Return false if the use is the shift amount of an LSHIFT_EXPR or RSHIFT_EXPR. * gcc.dg/vect/bb-slp-over-widen-3.c: New test. * gcc.dg/vect/bb-slp-over-widen-4.c: Likewise.
