On Thu, 9 Sept 2021 at 15:38, Roger Sayle <ro...@nextmovesoftware.com> wrote:
>
>
> As observed by Jakub in comment #2 of PR 98865, the expression -(a>>63)
> is optimized in GENERIC but not in GIMPLE.  Investigating further it
> turns out that this is one of a few transformations performed by
> fold_negate_expr in fold-const.c that aren't yet performed by match.pd.
> This patch moves/duplicates them there, and should be relatively safe
> as these transformations are already performed by the compiler, but
> just in different passes.
IIRC, we should probably remove the code from fold-const.c while
porting the pattern to
match.pd, which I suppose is case RSHIFT_EXPR block in
fold_negate_expr_1 near the
end of the function ?
>
> Alas the one minor complication is that some of these transformations
> are only wins, if the intermediate result (of the multiplication or
> division) is only used once, to avoid duplication/performing them again.
> See gcc.dg/tree-ssa/ssa-free-88.c.  Normally, this is the perfect usage
> of match's single_use (aka SSA's has_single_use).  Alas, single_use is
> not always accurate in match.pd, as some passes will construct and
> simplify an expression/stmt before inserting it into GIMPLE, and folding
> during this process sees the temporary undercount from the data-flow.
> To solve this, this patch introduces a new single_use_is_op_p that
> double checks that the single_use has the expected tree_code/operation
> and skips the transformation if we can tell single_use might be invalid.
>
> A follow-up patch might be to investigate whether genmatch.c can be
> tweaked to use this new helper function to implement the :s qualifier
> when the enclosing context is/should be known, but that's overkill
> to just unblock Jakub and Andrew on 98865.
>
> This patch has been tested on x86_64-pc-linux-gnu with a "make bootstrap"
> and "make -k check" with no new failures.  Ok for mainline?
>
>
> 2021-09-09  Roger Sayle  <ro...@nextmovesoftware.com>
>
> gcc/ChangeLog
>         * generic-match-head.c (single_use_is_op_p): New helper function.
>         * gimple-match-head.c (single_use_is_op_p): New helper function.
>         * match.pd (negation simplifications): Implement some negation
>         folding transformations from fold-const.c's fold_negate_expr.
>
> gcc/testsuite/ChangeLog
>         * gcc.dg/fold-negate-1.c: New test case.
Just a small nit -- please include the test-case as part of the patch
(instead of separate attachment), thanks!

Thanks,
Prathamesh
>
> Roger
> --
>

Reply via email to