public inbox for gcc-cvs@sourceware.org help / color / mirror / Atom feed
From: Andrew Pinski <pinskia@gcc.gnu.org> To: gcc-cvs@gcc.gnu.org Subject: [gcc r14-362] MATCH: add some of what phiopt's builtin_zero_pattern did Date: Sun, 30 Apr 2023 20:45:42 +0000 (GMT) [thread overview] Message-ID: <20230430204542.F1C693858C50@sourceware.org> (raw) https://gcc.gnu.org/g:c53237cefbad0c52799927d6fd99775426a8a92a commit r14-362-gc53237cefbad0c52799927d6fd99775426a8a92a Author: Andrew Pinski <apinski@marvell.com> Date: Sat Apr 8 18:46:37 2023 -0700 MATCH: add some of what phiopt's builtin_zero_pattern did This adds the patterns for POPCOUNT BSWAP FFS PARITY CLZ and CTZ. For "a != 0 ? FUNC(a) : CST". CLRSB, CLRSBL, and CLRSBLL will be moved next. Note this is not enough to remove cond_removal_in_builtin_zero_pattern as we need to handle the case where there is an NOP_CONVERT inside the conditional to move out of the condition inside match_simplify_replacement. OK? Bootstrapped and tested on x86_64-linux-gnu. gcc/ChangeLog: * match.pd: Add patterns for "a != 0 ? FUNC(a) : CST" for FUNC of POPCOUNT BSWAP FFS PARITY CLZ and CTZ. Diff: --- gcc/match.pd | 41 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 39 insertions(+), 2 deletions(-) diff --git a/gcc/match.pd b/gcc/match.pd index e17597ead26..0e782cde71d 100644 --- a/gcc/match.pd +++ b/gcc/match.pd @@ -52,6 +52,8 @@ along with GCC; see the file COPYING3. If not see gt ge eq ne le lt unordered ordered ungt unge unlt unle uneq ltgt) (define_operator_list simple_comparison lt le eq ne ge gt) (define_operator_list swapped_simple_comparison gt ge eq ne le lt) +(define_operator_list BSWAP BUILT_IN_BSWAP16 BUILT_IN_BSWAP32 + BUILT_IN_BSWAP64 BUILT_IN_BSWAP128) #include "cfn-operators.pd" @@ -4313,8 +4315,7 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) (complex (convert:itype @0) (negate (convert:itype @1))))) /* BSWAP simplifications, transforms checked by gcc.dg/builtin-bswap-8.c. */ -(for bswap (BUILT_IN_BSWAP16 BUILT_IN_BSWAP32 - BUILT_IN_BSWAP64 BUILT_IN_BSWAP128) +(for bswap (BSWAP) (simplify (bswap (bswap @0)) @0) @@ -7780,6 +7781,42 @@ DEFINE_INT_AND_FLOAT_ROUND_FN (RINT) (bit_xor (PARITY:s @0) (PARITY:s @1)) (PARITY (bit_xor @0 @1))) +/* a != 0 ? FUN(a) : 0 -> Fun(a) for some builtin functions. */ +(for func (POPCOUNT BSWAP FFS PARITY) + (simplify + (cond (ne @0 integer_zerop@1) (func@4 (convert? @2)) integer_zerop@3) + @4)) + +#if GIMPLE +/* a != 0 ? CLZ(a) : CST -> .CLZ(a) where CST is the result of the internal function for 0. */ +(for func (CLZ) + (simplify + (cond (ne @0 integer_zerop@1) (func (convert?@4 @2)) INTEGER_CST@3) + (with { int val; + internal_fn ifn = IFN_LAST; + if (direct_internal_fn_supported_p (IFN_CLZ, type, OPTIMIZE_FOR_BOTH) + && CLZ_DEFINED_VALUE_AT_ZERO (SCALAR_INT_TYPE_MODE (type), + val) == 2) + ifn = IFN_CLZ; + } + (if (ifn == IFN_CLZ && wi::to_widest (@3) == val) + (IFN_CLZ @4))))) + +/* a != 0 ? CTZ(a) : CST -> .CTZ(a) where CST is the result of the internal function for 0. */ +(for func (CTZ) + (simplify + (cond (ne @0 integer_zerop@1) (func (convert?@4 @2)) INTEGER_CST@3) + (with { int val; + internal_fn ifn = IFN_LAST; + if (direct_internal_fn_supported_p (IFN_CTZ, type, OPTIMIZE_FOR_BOTH) + && CTZ_DEFINED_VALUE_AT_ZERO (SCALAR_INT_TYPE_MODE (type), + val) == 2) + ifn = IFN_CTZ; + } + (if (ifn == IFN_CTZ && wi::to_widest (@3) == val) + (IFN_CTZ @4))))) +#endif + /* Common POPCOUNT/PARITY simplifications. */ /* popcount(X&C1) is (X>>C2)&1 when C1 == 1<<C2. Same for parity(X&C1). */ (for pfun (POPCOUNT PARITY)
reply other threads:[~2023-04-30 20:45 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20230430204542.F1C693858C50@sourceware.org \ --to=pinskia@gcc.gnu.org \ --cc=gcc-cvs@gcc.gnu.org \ /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: linkBe 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).