https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97997
--- Comment #3 from CVS Commits <cvs-commit at gcc dot gnu.org> --- The master branch has been updated by Jakub Jelinek <ja...@gcc.gnu.org>: https://gcc.gnu.org/g:a3ebc13492ff238873f2c6a7a3e51abefec1d052 commit r11-5444-ga3ebc13492ff238873f2c6a7a3e51abefec1d052 Author: Jakub Jelinek <ja...@redhat.com> Date: Thu Nov 26 16:24:07 2020 +0100 match.pd: Use ranges to optimize some x * y / y to x [PR97997] For signed integers with undefined overflow we already optimize x * y / y into x, but for signed integers with -fwrapv or unsigned integers we don't. The following patch allows optimizing that into just x if value ranges prove that x * y will never overflow. It uses the global SSA_NAME_RANGE_INFO only, because like mentioned in another PR we don't currently have a way to tell the ranger from match.pd the use stmt (and we'd need in that case to tell ranger to only follow SSA_NAME_DEF_STMTs + SSA_NAME_RANGE_INFO and never go in the other direction, as following immediate uses seems forbidden in match.pd). Another possibility would be to optimize this during vrp, but on the other side the optimization itself is match.pd-ish. 2020-11-26 Jakub Jelinek <ja...@redhat.com> PR tree-optimization/97997 * match.pd ((t * 2) / 2) -> t): Optimize even for defined overflow if ranges prove there is no overflow. * gcc.dg/tree-ssa/pr97997-1.c: New test. * gcc.dg/tree-ssa/pr97997-2.c: New test.