https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80342
Bug ID: 80342
Summary: useless outermost conversions not fully elided by
genmatch generated code
Product: gcc
Version: 7.0.1
Status: UNCONFIRMED
Keywords: missed-optimization
Severity: normal
Priority: P3
Component: middle-end
Assignee: rguenth at gcc dot gnu.org
Reporter: rguenth at gcc dot gnu.org
Target Milestone: ---
if you write
(simplify
(plus @1 @2)
(convert (plus @1 @2)))
then genmatch generates
*res_code = NOP_EXPR;
{
tree ops1[2], res;
ops1[0] = captures[0];
ops1[1] = captures[1];
code_helper tem_code = PLUS_EXPR;
tree tem_ops[3] = { ops1[0], ops1[1] };
gimple_resimplify2 (lseq, &tem_code, TREE_TYPE (ops1[0]), tem_ops,
valueize);
res = maybe_push_res_to_seq (tem_code, TREE_TYPE (ops1[0]), tem_ops,
lseq);
if (!res) return false;
res_ops[0] = res;
}
gimple_resimplify1 (lseq, res_code, type, res_ops, valueize);
which means the (plus @1 @2) is pushed to seq even if the conversion ends up
being simplified away. This results in forwprop changes like
+ _1 = x_6(D) - _10;
+ _7 = _1;
and also in missed optimizations in SCCVN which uses seq == NULL and thus
won't survive this.
Individual patterns can be adjusted to provide special-casing for the
case of useless conversions but a genmatch solution is prefered. Note
it won't come cheap (it will duplicate the transform code).