From: Richard Biener <richard.guenther@gmail.com>
To: Marc Glisse <marc.glisse@inria.fr>
Cc: GCC Patches <gcc-patches@gcc.gnu.org>
Subject: Re: Small fold-const.c / match.pd tweaks
Date: Mon, 18 May 2015 10:00:00 -0000 [thread overview]
Message-ID: <CAFiYyc0bLyS1CRiphvhBcQwHsZaA3cENFm++hWf4Xaf+S1SKBg@mail.gmail.com> (raw)
In-Reply-To: <alpine.DEB.2.02.1505151159030.19595@stedding.saclay.inria.fr>
On Fri, May 15, 2015 at 12:52 PM, Marc Glisse <marc.glisse@inria.fr> wrote:
> Hello,
>
> these are just a few tweaks / clean-ups. The 'ord' pattern is the dual of
> the 'unord' one I added last month. The tree_unary_nonnegative_warnv_p
> change should have no effect (it is only used from VRP which does not handle
> vectors (yet?)) but it seems right to handle vectors like scalars here.
>
> Regtested on ppc64le-redhat-linux.
>
> 2015-05-15 Marc Glisse <marc.glisse@inria.fr>
>
> PR tree-optimization/63387
> gcc/
> * match.pd ((X /[ex] A) * A -> X): Remove unnecessary condition.
> ((x ord x) & (y ord y) -> (x ord y),
> (x ord x) & (x ord y) -> (x ord y)): New simplifications.
> * fold-const.c (tree_unary_nonnegative_warnv_p) <ABS_EXPR>: Handle
> vectors like scalars.
> gcc/testsuite/
> * gcc.dg/pr63387-2.c: New testcase.
>
> --
> Marc Glisse
> Index: gcc/fold-const.c
> ===================================================================
> --- gcc/fold-const.c (revision 223214)
> +++ gcc/fold-const.c (working copy)
> @@ -14685,21 +14685,21 @@ tree_unary_nonnegative_warnv_p (enum tre
> bool *strict_overflow_p)
> {
> if (TYPE_UNSIGNED (type))
> return true;
>
> switch (code)
> {
> case ABS_EXPR:
> /* We can't return 1 if flag_wrapv is set because
> ABS_EXPR<INT_MIN> = INT_MIN. */
> - if (!INTEGRAL_TYPE_P (type))
> + if (!ANY_INTEGRAL_TYPE_P (type))
> return true;
> if (TYPE_OVERFLOW_UNDEFINED (type))
> {
> *strict_overflow_p = true;
> return true;
> }
> break;
>
> case NON_LVALUE_EXPR:
> case FLOAT_EXPR:
> Index: gcc/match.pd
> ===================================================================
> --- gcc/match.pd (revision 223214)
> +++ gcc/match.pd (working copy)
> @@ -791,22 +791,21 @@ along with GCC; see the file COPYING3.
> && TYPE_PRECISION (type) <= TYPE_PRECISION (TREE_TYPE (@0))
> && operand_equal_p (@1, build_low_bits_mask (TREE_TYPE (@1),
> TYPE_PRECISION (type)),
> 0))
> (convert @0)))
>
>
> /* (X /[ex] A) * A -> X. */
> (simplify
> (mult (convert? (exact_div @0 @1)) @1)
> /* Look through a sign-changing conversion. */
> - (if (TYPE_PRECISION (TREE_TYPE (@0)) == TYPE_PRECISION (type))
> - (convert @0)))
> + (convert @0))
Hmm, indeed. Looks like we were overly cautionous (in forwprop where I moved
this from)
> /* Canonicalization of binary operations. */
>
> /* Convert X + -C into X - C. */
> (simplify
> (plus @0 REAL_CST@1)
> (if (REAL_VALUE_NEGATIVE (TREE_REAL_CST (@1)))
> (with { tree tem = fold_unary (NEGATE_EXPR, type, @1); }
> (if (!TREE_OVERFLOW (tem) || !flag_trapping_math)
> (minus @0 { tem; })))))
> @@ -944,22 +943,29 @@ along with GCC; see the file COPYING3.
> (icmp @0 @1))
> (if (ic == ncmp)
> (ncmp @0 @1)))))
>
> /* Unordered tests if either argument is a NaN. */
> (simplify
> (bit_ior (unordered @0 @0) (unordered @1 @1))
> (if (types_match (@0, @1))
> (unordered @0 @1)))
> (simplify
> + (bit_and (ordered @0 @0) (ordered @1 @1))
> + (if (types_match (@0, @1))
> + (ordered @0 @1)))
(for op (unordered ordered)
op2 (bit_ior bit_and)
(simplify
(op2 (op @0 @0) (op @1 @1))
(if ...
(op @0 @1)))
would be a merged variant (nor sure if better - if the list increases
maybe). I suppose
your version is easier to read and not very much bigger.
Patch is ok as-is.
Thanks,
Richard.
> +(simplify
> (bit_ior:c (unordered @0 @0) (unordered:c@2 @0 @1))
> @2)
> +(simplify
> + (bit_and:c (ordered @0 @0) (ordered:c@2 @0 @1))
> + @2)
>
> /* Simplification of math builtins. */
>
> (define_operator_list LOG BUILT_IN_LOGF BUILT_IN_LOG BUILT_IN_LOGL)
> (define_operator_list EXP BUILT_IN_EXPF BUILT_IN_EXP BUILT_IN_EXPL)
> (define_operator_list LOG2 BUILT_IN_LOG2F BUILT_IN_LOG2 BUILT_IN_LOG2L)
> (define_operator_list EXP2 BUILT_IN_EXP2F BUILT_IN_EXP2 BUILT_IN_EXP2L)
> (define_operator_list LOG10 BUILT_IN_LOG10F BUILT_IN_LOG10 BUILT_IN_LOG10L)
> (define_operator_list EXP10 BUILT_IN_EXP10F BUILT_IN_EXP10 BUILT_IN_EXP10L)
> (define_operator_list POW BUILT_IN_POWF BUILT_IN_POW BUILT_IN_POWL)
> Index: gcc/testsuite/gcc.dg/pr63387-2.c
> ===================================================================
> --- gcc/testsuite/gcc.dg/pr63387-2.c (revision 0)
> +++ gcc/testsuite/gcc.dg/pr63387-2.c (working copy)
> @@ -0,0 +1,26 @@
> +/* { dg-do compile } */
> +/* { dg-options "-O -fdump-tree-optimized" } */
> +
> +int f(double aaa, double bbb){
> + int xa = !__builtin_isunordered(aaa, aaa);
> + int xb = !__builtin_isunordered(bbb, bbb);
> + return xa & xb;
> +}
> +
> +int g(double aaa, double bbb){
> + int xa = !__builtin_isunordered(aaa, bbb);
> + int xb = !__builtin_isunordered(bbb, bbb);
> + return xa & xb;
> +}
> +
> +int h(double ccc, float ddd){
> + int xc = !__builtin_isunordered(ccc, ccc);
> + int xd = !__builtin_isunordered(ddd, ddd);
> + return xc & xd;
> +}
> +
> +/* { dg-final { scan-tree-dump-not "aaa\[^\n\r\]* ord aaa" "optimized" } }
> */
> +/* { dg-final { scan-tree-dump-not "bbb\[^\n\r\]* ord bbb" "optimized" } }
> */
> +/* { dg-final { scan-tree-dump-times "aaa\[^\n\r\]* ord bbb" 2 "optimized"
> } } */
> +/* { dg-final { scan-tree-dump-not "ccc\[^\n\r\]* ord ddd" "optimized" } }
> */
> +/* { dg-final { cleanup-tree-dump "optimized" } } */
>
prev parent reply other threads:[~2015-05-18 9:55 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-05-15 11:08 Marc Glisse
2015-05-18 10:00 ` Richard Biener [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CAFiYyc0bLyS1CRiphvhBcQwHsZaA3cENFm++hWf4Xaf+S1SKBg@mail.gmail.com \
--to=richard.guenther@gmail.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=marc.glisse@inria.fr \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).