https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112746

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |missed-optimization
             Status|UNCONFIRMED                 |NEW
     Ever confirmed|0                           |1
            Summary|Missed optimization for     |Missed optimization for
                   |redundancy computation      |exact division with
                   |elimination (fre1(tree) for |multi-use addition chain
                   |global variable)            |
   Last reconfirmed|                            |2023-11-28

--- Comment #1 from Richard Biener <rguenth at gcc dot gnu.org> ---
The issue with test2 is that with value-numbering we have

(n.3_1 * 2 + n.3_1) / n.3_1

and that does not simplify.  That is, we do not simplify 2 * n + n to
3 * n as in general that wouldn't be profitable if 2 * n is live after
the use is elided (and it is live since it's stored to 'b').

Which means we ask for (n.3_1 * 2 + n.3_1) / n.3_1 which we currently
cannot simplify to a constant.  Handling cases like this in match.pd
feels wrong.

Note that with -fwrapv the optimization wouldn't be valid.

Other passes face the same issue, 'b' keeps n*2 live so an add
looks cheaper than to compute n*3 for the division.  We're not
anticipating the division here.

But:

  _3 = n.3_1 + _2;
  _4 = _3 / n.3_1;

could be simplified to

  _5 = _2 / n.3_1;
  _4 = _5 + 1;

if we know _2 is a multiple of n.3_1 which then could be simplified as well.

Note that all passes doing analyses on addition chains also stop at the
multi-use, so we'd need to improve at that point somehow.
  • [Bug tree-optimization/1... 652023330028 at smail dot nju.edu.cn via Gcc-bugs
    • [Bug tree-optimizat... rguenth at gcc dot gnu.org via Gcc-bugs

Reply via email to