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 <jakub@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.