On Wed, Feb 23, 2022 at 01:53:38PM +0100, Richard Biener wrote:
> The following patch avoids infinite recursion during generic folding.
> The (cmp (bswap @0) INTEGER_CST@1) simplification relies on
> (bswap @1) actually being simplified, if it is not simplified, we just
> move the bswap from one operand to the other and if @0 is also INTEGER_CST,
> we apply the same rule next.
> 
> The reason why bswap @1 isn't folded to INTEGER_CST is that the INTEGER_CST
> has TREE_OVERFLOW set on it and fold-const-call.cc predicate punts in
> such cases:
> static inline bool
> integer_cst_p (tree t)
> {
>   return TREE_CODE (t) == INTEGER_CST && !TREE_OVERFLOW (t);
> }
> The patch uses ! modifier to ensure the bswap is simplified and
> extends support to GENERIC by means of requiring !EXPR_P which
> is not perfect but a conservative approximation.
> 
> Bootstrap and regtest running on x86_64-unknown-linux-gnu.
> 
> I didn't bother to un-#ifdef GIMPLE the few use-cases of ! we have
> in match.pd since those are not regressions.  Let's remember
> that for stage1.  I also agree this is the safes approach at this
> stage.

Note, it is not clear if all the #if GIMPLE around ! modifier uses
are purely because of the error or not, I think we'll need to do
some archeology for each of the cases to see.  I vaguely remember one case
where I've added such #if GIMPLE wrapping only for that reason, but
don't remember which of those 6 !s I've added it was, and then there are
some from Marc and Feng.

> OK?

LGTM, thanks.

> 2022-02-22  Richard Biener  <rguent...@suse.de>
> 
>       PR tree-optimization/104644
>       * doc/match-and-simplify.texi: Amend ! documentation.
>       * genmatch.cc (expr::gen_transform): Code-generate ! support
>       for GENERIC.
>       (parser::parse_expr): Allow ! for GENERIC.
>       * match.pd (cmp (bswap @0) INTEGER_CST@1): Use ! modifier on
>       bswap.
> 
>       * gcc.dg/pr104644.c: New test.

        Jakub

Reply via email to