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

--- Comment #4 from Richard Biener <rguenth at gcc dot gnu.org> ---
Note the same is true for

(simplify
 (plus @1 @2)
 (plus (convert (minus @1 @2)) @2))

so any convert wrapped around another expression.  Code generation for the
outermost expression is somewhat duplicated in dt_simplify::gen_1 vs.
expr::gen_transform which has code to handle leafs, but only those.

(simplify
 (plus @1 @2)
 (plus @1 (convert @2)))

generates

        _o1[0] = captures[1];
        if (type != TREE_TYPE (_o1[0])
            && !useless_type_conversion_p (type, TREE_TYPE (_o1[0])))
          {
            gimple_match_op tem_op (res_op->cond.any_else (), NOP_EXPR, type,
_o1[0]);
            tem_op.resimplify (lseq, valueize);
            _r1 = maybe_push_res_to_seq (&tem_op, lseq);
            if (!_r1) goto next_after_fail1;
          }
        else
          _r1 = _o1[0];
        res_op->ops[1] = _r1;

which "works" because captures[1] isn't the result of an earlier
simplification.

Fixing the non-outermost case is going to be effective only in some cases
when there's only a single "active" conversion, and that in turn can
depend on visitation order processing operands.


Trying to fix this "quickly" shows it needs quite some refactoring to be
generic enough.  Duplicating quite a bit of code to handle just 'expr *'
kind inside the convert looks doable more easily.

Reply via email to