From: Richard Biener <richard.guenther@gmail.com>
To: GCC Patches <gcc-patches@gcc.gnu.org>,
Richard Sandiford <richard.sandiford@arm.com>
Subject: Re: [1/5] Improve tree-vect-patterns.c handling of boolean comparisons
Date: Fri, 29 Nov 2019 10:53:00 -0000 [thread overview]
Message-ID: <CAFiYyc3N0FvK6YgeWdqb=avKpoCf9rxekvzv75t4fKKokW1WLA@mail.gmail.com> (raw)
In-Reply-To: <mpto8wvyosi.fsf@arm.com>
On Fri, Nov 29, 2019 at 11:12 AM Richard Sandiford
<richard.sandiford@arm.com> wrote:
>
> vect_recog_bool_pattern assumed that a comparison between two booleans
> should always become a comparison of vector mask types (implemented as an
> XOR_EXPR). But if the booleans in question are generated as data values
> (e.g. because they're loaded directly from memory), we should treat them
> like ordinary integers instead, just as we do for boolean logic ops whose
> operands are loaded from memory. vect_get_mask_type_for_stmt already
> handled this case:
>
> /* We may compare boolean value loaded as vector of integers.
> Fix mask_type in such case. */
> if (mask_type
> && !VECTOR_BOOLEAN_TYPE_P (mask_type)
> && gimple_code (stmt) == GIMPLE_ASSIGN
> && TREE_CODE_CLASS (gimple_assign_rhs_code (stmt)) == tcc_comparison)
> mask_type = truth_type_for (mask_type);
>
> and not handling it here complicated later patches.
>
> The initial list of targets for vect_bool_cmp is deliberately conservative.
OK.
Richard.
>
> 2019-11-30 Richard Sandiford <richard.sandiford@arm.com>
>
> gcc/
> * doc/sourcebuild.texi (vect_bool_cmp): Document.
> * tree-vect-patterns.c (search_type_for_mask_1): If neither
> operand to a boolean comparison is a natural vector mask,
> handle both operands like normal integers instead.
>
> gcc/testsuite/
> * gcc.dg/vect/vect-bool-cmp-2.c: New test.
> * lib/target-supports.exp (check_effective_target_vect_bool_cmp): New
> effective target procedure.
>
> Index: gcc/doc/sourcebuild.texi
> ===================================================================
> --- gcc/doc/sourcebuild.texi 2019-11-20 21:11:59.065472803 +0000
> +++ gcc/doc/sourcebuild.texi 2019-11-29 09:11:21.365130870 +0000
> @@ -1522,6 +1522,10 @@ Target does not support a vector add ins
> @item vect_no_bitwise
> Target does not support vector bitwise instructions.
>
> +@item vect_bool_cmp
> +Target supports comparison of @code{bool} vectors for at least one
> +vector length.
> +
> @item vect_char_add
> Target supports addition of @code{char} vectors for at least one
> vector length.
> Index: gcc/tree-vect-patterns.c
> ===================================================================
> --- gcc/tree-vect-patterns.c 2019-11-16 10:29:21.207212217 +0000
> +++ gcc/tree-vect-patterns.c 2019-11-29 09:11:21.389130702 +0000
> @@ -3944,7 +3944,8 @@ search_type_for_mask_1 (tree var, vec_in
> vinfo, cache);
> if (!res || (res2 && TYPE_PRECISION (res) > TYPE_PRECISION (res2)))
> res = res2;
> - break;
> + if (res)
> + break;
> }
>
> comp_vectype = get_vectype_for_scalar_type (vinfo, TREE_TYPE (rhs1));
> Index: gcc/testsuite/gcc.dg/vect/vect-bool-cmp-2.c
> ===================================================================
> --- /dev/null 2019-09-17 11:41:18.176664108 +0100
> +++ gcc/testsuite/gcc.dg/vect/vect-bool-cmp-2.c 2019-11-29 09:11:21.373130815 +0000
> @@ -0,0 +1,10 @@
> +/* { dg-do compile } */
> +
> +void
> +f (_Bool *restrict x, _Bool *restrict y)
> +{
> + for (int i = 0; i < 128; ++i)
> + x[i] = x[i] == y[i];
> +}
> +
> +/* { dg-final { scan-tree-dump "loop vectorized" "vect" { target vect_bool_cmp } } } */
> Index: gcc/testsuite/lib/target-supports.exp
> ===================================================================
> --- gcc/testsuite/lib/target-supports.exp 2019-11-26 22:11:24.494545152 +0000
> +++ gcc/testsuite/lib/target-supports.exp 2019-11-29 09:11:21.373130815 +0000
> @@ -5749,6 +5749,16 @@ proc check_effective_target_vect_bswap {
> || [istarget amdgcn-*-*] }}]
> }
>
> +# Return 1 if the target supports comparison of bool vectors for at
> +# least one vector length.
> +
> +proc check_effective_target_vect_bool_cmp { } {
> + return [check_cached_effective_target_indexed vect_bool_cmp {
> + expr { [istarget i?86-*-*] || [istarget x86_64-*-*]
> + || [istarget aarch64*-*-*]
> + || [is-effective-target arm_neon] }}]
> +}
> +
> # Return 1 if the target supports addition of char vectors for at least
> # one vector length.
>
next prev parent reply other threads:[~2019-11-29 10:34 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-11-29 10:11 [0/5] Don't defer vector type choice for bools (PR 92596) Richard Sandiford
2019-11-29 10:13 ` [1/5] Improve tree-vect-patterns.c handling of boolean comparisons Richard Sandiford
2019-11-29 10:53 ` Richard Biener [this message]
2019-11-29 10:14 ` [2/5] Make vectorizable_operation punt early on codes it doesn't handle Richard Sandiford
2019-11-29 10:26 ` Richard Biener
2019-11-29 10:14 ` [3/5] Make vect_get_mask_type_for_stmt take a group size Richard Sandiford
2019-11-29 10:30 ` Richard Biener
2019-11-29 10:15 ` [4/5] Record the vector mask precision in stmt_vec_info Richard Sandiford
2019-11-29 10:34 ` Richard Biener
2019-11-29 10:25 ` [5/5] Don't defer choice of vector type for bools (PR 92596) Richard Sandiford
2019-11-29 12:58 ` Richard Biener
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='CAFiYyc3N0FvK6YgeWdqb=avKpoCf9rxekvzv75t4fKKokW1WLA@mail.gmail.com' \
--to=richard.guenther@gmail.com \
--cc=gcc-patches@gcc.gnu.org \
--cc=richard.sandiford@arm.com \
/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).