https://gcc.gnu.org/bugzilla/show_bug.cgi?id=119683
--- Comment #9 from GCC Commits <cvs-commit at gcc dot gnu.org> --- The master branch has been updated by Jakub Jelinek <[email protected]>: https://gcc.gnu.org/g:d5db22c890df83f84d186916348d16b79f278b33 commit r16-5622-gd5db22c890df83f84d186916348d16b79f278b33 Author: Jakub Jelinek <[email protected]> Date: Wed Nov 26 10:57:37 2025 +0100 match.pd: Use get_range_query (cfun) in more simplifications and pass current stmt to range_of_expr [PR119683] The following testcase regressed with r13-3596 which switched over vrp1 to ranger vrp. Before that, I believe vrp1 was registering SSA_NAMEs with ASSERT_EXPRs at the start of bbs and so even when querying the global ranges from match.pd patterns during the vrp1 pass, they saw the local ranges for a particular bb rather than global ranges. In ranger vrp that doesn't happen anymore, so we need to pass a stmt to range_of_expr if we want the local ranges rather than global ones, plus should be using get_range_query (cfun) instead of get_global_range_query () (most patterns actually use the former already). Now, for stmt the following patch attempts to pass the innermost stmt on which that particular capture appears as operand, but because some passes use match.pd folding on expressions not yet in the IL, I've added a helper function which tries to find out from a capture of the LHS operation whether it is a SSA_NAME with SSA_NAME_DEF_STMT which is in the IL right now and only query the ranger with that in that case, otherwise NULL (i.e. what it has been using before). 2025-11-26 Jakub Jelinek <[email protected]> PR tree-optimization/119683 * gimple-match.h (gimple_match_ctx): New inline function. * match.pd ((mult (plus:s (mult:s @0 @1) @2) @3)): Capture PLUS, use get_range_query (cfun) instead of get_global_range_query () and pass gimple_match_ctx (@5) as 3rd argument to range_of_expr. ((plus (mult:s (plus:s @0 @1) @2) @3)): Similarly for MULT, with @4 instead of @5. ((t * u) / u -> t): Similarly with @2 instead of @4. ((t * u) / v -> t * (u / v)): Capture MULT, pass gimple_match_ctx (@3) as 3rd argument to range_of_expr. ((X + M*N) / N -> X / N + M): Pass gimple_match_ctx (@3) or gimple_match_ctx (@4) as 3rd arg to some range_of_expr calls. ((X - M*N) / N -> X / N - M): Likewise. ((X + C) / N -> X / N + C / N): Similarly. (((T)(A)) + CST -> (T)(A + CST)): Capture CONVERT, use get_range_query (cfun) instead of get_global_range_query () and pass gimple_match_ctx (@2) as 3rd argument to range_of_expr. (x_5 == cstN ? cst4 : cst3): Capture EQNE and pass gimple_match_ctx (@4) as 3rd argument to range_of_expr. * gcc.dg/tree-ssa/pr119683.c: New test.
