https://gcc.gnu.org/bugzilla/show_bug.cgi?id=128884
--- Comment #3 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:8adaf6a45cbf3fdda8a62122cc8ea980b13e27e6 commit r17-6500-g8adaf6a45cbf3fdda8a62122cc8ea980b13e27e6 Author: Richard Biener <[email protected]> Date: Fri Nov 20 10:52:02 2026 +0100 tree-optimization/128884 - use available leader when simplifying in VN When value-numbering (T)(a op b) as ((T)a op (T)b) & mask for a widening conversion from a wrapping type, we accepted a wider operation that was merely insertable because its type wraps. Simplifying the BIT_AND_EXPR then may use range info of that value, which is only valid where its definition dominates. With the value defined in a sibling branch the mask can be dropped wrongly, and PRE then hoists the unmasked wider operation. The same issue exists for the unmasked conversion case and for the inverse (T)A +- B handling, since rpo_vn_valueize does not resort to eliminate_avail for a value that is its own value number. The following factors the masked and the (T)A +- B cases into vn_nary_build_or_lookup_avail which simplifies using the available leader if there is one and otherwise, when the value is of wrapping type, inserts the unsimplified expression. For the unmasked conversion case the wider operation already has the desired type, so value-number to it directly when it is available or of wrapping type. This leaves vn_nary_result_avail_or_insertable_p with a single use where the type does not wrap, so replace it with a direct availability check. PR tree-optimization/128884 * tree-ssa-sccvn.cc (vn_nary_result_avail_or_insertable_p): Remove. (vn_nary_build_or_lookup_avail): New. (visit_nary_op): Use it for the masked conversion and the PLUS_EXPR/MINUS_EXPR special cases instead of checking vn_nary_result_avail_or_insertable_p and simplifying with a possibly not available value. Use the wider operation directly for the unmasked conversion case. Check availability directly for the negated operand of the MULT_EXPR/RDIV_EXPR case. * gcc.dg/torture/pr128884.c: New testcase.
