tree-optimization/100499 - niter analysis and multiple_of_p
authorRichard Biener <rguenther@suse.de>
Wed, 26 Jan 2022 08:35:57 +0000 (09:35 +0100)
committerRichard Biener <rguenther@suse.de>
Fri, 4 Feb 2022 13:38:47 +0000 (14:38 +0100)
commit0898049ad9bf6c46e510b18aaafca4946802749f
tree14ebaafca33c719cbde7610151467bfac7e7f6ad
parent9d3236ff3791ea74e1bc1c293d82fee11b1a5e24
tree-optimization/100499 - niter analysis and multiple_of_p

niter analysis uses multiple_of_p which currently assumes
operations like MULT_EXPR do not wrap.  We've got to rely on this
for optimizing size expressions like those in DECL_SIZE and those
generally use unsigned arithmetic with no indication that they
are not expected to wrap.  To preserve that the following adds
a parameter to multiple_of_p, defaulted to true, indicating that
the TOP expression is not expected to wrap for outer computations
in TYPE.  This mostly follows a patch proposed by Bin last year
with the conversion behavior added.

Applying to all users the new effect is that upon type conversions
in the TOP expression the behavior will switch to honor
TYPE_OVERFLOW_UNDEFINED for the converted sub-expressions.

The patch also changes the occurance in niter analysis that we
know is problematic and we have testcases for to pass false
to multiple_of_p.  The patch also contains a change to the
PR72817 fix from Bin to avoid regressing gcc.dg/tree-ssa/loop-42.c.

The intent for stage1 is to introduce a size_multiple_of_p and
internalize the added parameter so all multiple_of_p users will
honor TYPE_OVERFLOW_UNDEFINED and users dealing with size expressions
need to be switched to size_multiple_of_p.

2022-01-26  Richard Biener  <rguenther@suse.de>

PR tree-optimization/100499
* fold-const.h (multiple_of_p): Add nowrap parameter, defaulted
to true.
* fold-const.cc (multiple_of_p): Likewise.  Honor it for
MULT_EXPR, PLUS_EXPR and MINUS_EXPR and pass it along,
switching to false for conversions.
* tree-ssa-loop-niter.cc (number_of_iterations_ne): Do not
claim the outermost expression does not wrap when calling
multiple_of_p.  Refactor the check done to check the
original IV, avoiding a bias that might wrap.

* gcc.dg/torture/pr100499-1.c: New testcase.
* gcc.dg/torture/pr100499-2.c: Likewise.
* gcc.dg/torture/pr100499-3.c: Likewise.

Co-authored-by: Bin Cheng <bin.cheng@linux.alibaba.com>
gcc/fold-const.cc
gcc/fold-const.h
gcc/testsuite/gcc.dg/torture/pr100499-1.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/torture/pr100499-2.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/torture/pr100499-3.c [new file with mode: 0644]
gcc/tree-ssa-loop-niter.cc