From: Prathamesh Kulkarni <prathamesh.kulkarni@linaro.org>
To: Prathamesh Kulkarni <prathamesh.kulkarni@linaro.org>,
gcc Patches <gcc-patches@gcc.gnu.org>,
Richard Biener <rguenther@suse.de>,
richard.sandiford@arm.com
Subject: Re: [2/2] PR96463 -- changes to type checking vec_perm_expr in middle end
Date: Mon, 27 Dec 2021 15:55:02 +0530 [thread overview]
Message-ID: <CAAgBjMm1pzrd=ekGjVqbKxavobk7aXKg61Z_CHyGkJWYB5sbKQ@mail.gmail.com> (raw)
In-Reply-To: <mptk0g3a3qy.fsf@arm.com>
[-- Attachment #1: Type: text/plain, Size: 5986 bytes --]
On Fri, 17 Dec 2021 at 16:37, Richard Sandiford
<richard.sandiford@arm.com> wrote:
>
> Prathamesh Kulkarni <prathamesh.kulkarni@linaro.org> writes:
> > Hi,
> > The attached patch rearranges order of type-check for vec_perm_expr
> > and relaxes type checking for
> > lhs = vec_perm_expr<rhs1, rhs2, mask>
> >
> > when:
> > rhs1 == rhs2,
> > lhs is variable length vector,
> > rhs1 is fixed length vector,
> > TREE_TYPE (lhs) == TREE_TYPE (rhs1)
> >
> > I am not sure tho if this check is correct ? My intent was to capture
> > case when vec_perm_expr is used to "extend" fixed length vector to
> > it's VLA equivalent.
>
> VLAness isn't really the issue. We want the same thing to work for
> -msve-vector-bits=256, -msve-vector-bits=512, etc., even though the
> vectors are fixed-length in that case.
>
> The principle is that for:
>
> A = VEC_PERM_EXPR <B, C, D>;
>
> the requirements are:
>
> - A, B, C and D must be vectors
> - A, B and C must have the same element type
> - D must have an integer element type
> - A and D must have the same number of elements (NA)
> - B and C must have the same number of elements (NB)
>
> The semantics are that we create a joined vector BC (all elements of B
> followed by all element of C) and that:
>
> A[i] = BC[D[i] % (NB+NB)]
>
> for 0 ≤ i < NA.
>
> This operation makes sense even if NA != NB.
Thanks for the suggestions, I tried to modify the patch accordingly.
Does it look OK ?
Passes bootstrap+test on aarch64-linux-gnu.
Thanks,
Prathamesh
>
> Thanks,
> Richard
>
> >
> > Thanks,
> > Prathamesh
> >
> > diff --git a/gcc/tree-cfg.c b/gcc/tree-cfg.c
> > index 672e384ef09..9f91878c468 100644
> > --- a/gcc/tree-cfg.c
> > +++ b/gcc/tree-cfg.c
> > @@ -4325,10 +4325,11 @@ verify_gimple_assign_ternary (gassign *stmt)
> > break;
> >
> > case VEC_PERM_EXPR:
> > - if (!useless_type_conversion_p (lhs_type, rhs1_type)
> > - || !useless_type_conversion_p (lhs_type, rhs2_type))
> > + if (TREE_CODE (rhs1_type) != VECTOR_TYPE
> > + || TREE_CODE (rhs2_type) != VECTOR_TYPE
> > + || TREE_CODE (rhs3_type) != VECTOR_TYPE)
> > {
> > - error ("type mismatch in %qs", code_name);
> > + error ("vector types expected in %qs", code_name);
> > debug_generic_expr (lhs_type);
> > debug_generic_expr (rhs1_type);
> > debug_generic_expr (rhs2_type);
> > @@ -4336,11 +4337,14 @@ verify_gimple_assign_ternary (gassign *stmt)
> > return true;
> > }
> >
> > - if (TREE_CODE (rhs1_type) != VECTOR_TYPE
> > - || TREE_CODE (rhs2_type) != VECTOR_TYPE
> > - || TREE_CODE (rhs3_type) != VECTOR_TYPE)
> > + if (TREE_CODE (TREE_TYPE (rhs3_type)) != INTEGER_TYPE
> > + || (TREE_CODE (rhs3) != VECTOR_CST
> > + && (GET_MODE_BITSIZE (SCALAR_INT_TYPE_MODE
> > + (TREE_TYPE (rhs3_type)))
> > + != GET_MODE_BITSIZE (SCALAR_TYPE_MODE
> > + (TREE_TYPE (rhs1_type))))))
> > {
> > - error ("vector types expected in %qs", code_name);
> > + error ("invalid mask type in %qs", code_name);
> > debug_generic_expr (lhs_type);
> > debug_generic_expr (rhs1_type);
> > debug_generic_expr (rhs2_type);
> > @@ -4348,15 +4352,18 @@ verify_gimple_assign_ternary (gassign *stmt)
> > return true;
> > }
> >
> > - if (maybe_ne (TYPE_VECTOR_SUBPARTS (rhs1_type),
> > - TYPE_VECTOR_SUBPARTS (rhs2_type))
> > - || maybe_ne (TYPE_VECTOR_SUBPARTS (rhs2_type),
> > - TYPE_VECTOR_SUBPARTS (rhs3_type))
> > - || maybe_ne (TYPE_VECTOR_SUBPARTS (rhs3_type),
> > - TYPE_VECTOR_SUBPARTS (lhs_type)))
> > + /* Accept lhs = vec_perm_expr<v, v, mask> if lhs is vector length agnostic,
> > + and has same element type as v. */
> > + if (!TYPE_VECTOR_SUBPARTS (lhs_type).is_constant ()
> > + && operand_equal_p (rhs1, rhs2, 0)
> > + && TYPE_VECTOR_SUBPARTS (rhs1_type).is_constant ()
> > + && TREE_TYPE (lhs_type) == TREE_TYPE (rhs1_type))
> > + return false;
> > +
> > + if (!useless_type_conversion_p (lhs_type, rhs1_type)
> > + || !useless_type_conversion_p (lhs_type, rhs2_type))
> > {
> > - error ("vectors with different element number found in %qs",
> > - code_name);
> > + error ("type mismatch in %qs", code_name);
> > debug_generic_expr (lhs_type);
> > debug_generic_expr (rhs1_type);
> > debug_generic_expr (rhs2_type);
> > @@ -4364,21 +4371,21 @@ verify_gimple_assign_ternary (gassign *stmt)
> > return true;
> > }
> >
> > - if (TREE_CODE (TREE_TYPE (rhs3_type)) != INTEGER_TYPE
> > - || (TREE_CODE (rhs3) != VECTOR_CST
> > - && (GET_MODE_BITSIZE (SCALAR_INT_TYPE_MODE
> > - (TREE_TYPE (rhs3_type)))
> > - != GET_MODE_BITSIZE (SCALAR_TYPE_MODE
> > - (TREE_TYPE (rhs1_type))))))
> > + if (maybe_ne (TYPE_VECTOR_SUBPARTS (rhs1_type),
> > + TYPE_VECTOR_SUBPARTS (rhs2_type))
> > + || maybe_ne (TYPE_VECTOR_SUBPARTS (rhs2_type),
> > + TYPE_VECTOR_SUBPARTS (rhs3_type))
> > + || maybe_ne (TYPE_VECTOR_SUBPARTS (rhs3_type),
> > + TYPE_VECTOR_SUBPARTS (lhs_type)))
> > {
> > - error ("invalid mask type in %qs", code_name);
> > + error ("vectors with different element number found in %qs",
> > + code_name);
> > debug_generic_expr (lhs_type);
> > debug_generic_expr (rhs1_type);
> > debug_generic_expr (rhs2_type);
> > debug_generic_expr (rhs3_type);
> > return true;
> > }
> > -
> > return false;
> >
> > case SAD_EXPR:
[-- Attachment #2: pr96463-4-midend.txt --]
[-- Type: text/plain, Size: 3654 bytes --]
diff --git a/gcc/tree-cfg.c b/gcc/tree-cfg.c
index 672e384ef09..acc835c77cc 100644
--- a/gcc/tree-cfg.c
+++ b/gcc/tree-cfg.c
@@ -4325,10 +4325,12 @@ verify_gimple_assign_ternary (gassign *stmt)
break;
case VEC_PERM_EXPR:
- if (!useless_type_conversion_p (lhs_type, rhs1_type)
- || !useless_type_conversion_p (lhs_type, rhs2_type))
+ if (TREE_CODE (lhs_type) != VECTOR_TYPE
+ || TREE_CODE (rhs1_type) != VECTOR_TYPE
+ || TREE_CODE (rhs2_type) != VECTOR_TYPE
+ || TREE_CODE (rhs3_type) != VECTOR_TYPE)
{
- error ("type mismatch in %qs", code_name);
+ error ("vector types expected in %qs", code_name);
debug_generic_expr (lhs_type);
debug_generic_expr (rhs1_type);
debug_generic_expr (rhs2_type);
@@ -4336,11 +4338,14 @@ verify_gimple_assign_ternary (gassign *stmt)
return true;
}
- if (TREE_CODE (rhs1_type) != VECTOR_TYPE
- || TREE_CODE (rhs2_type) != VECTOR_TYPE
- || TREE_CODE (rhs3_type) != VECTOR_TYPE)
+ if (TREE_CODE (TREE_TYPE (rhs3_type)) != INTEGER_TYPE
+ || (TREE_CODE (rhs3) != VECTOR_CST
+ && (GET_MODE_BITSIZE (SCALAR_INT_TYPE_MODE
+ (TREE_TYPE (rhs3_type)))
+ != GET_MODE_BITSIZE (SCALAR_TYPE_MODE
+ (TREE_TYPE (rhs1_type))))))
{
- error ("vector types expected in %qs", code_name);
+ error ("invalid mask type in %qs", code_name);
debug_generic_expr (lhs_type);
debug_generic_expr (rhs1_type);
debug_generic_expr (rhs2_type);
@@ -4348,15 +4353,23 @@ verify_gimple_assign_ternary (gassign *stmt)
return true;
}
- if (maybe_ne (TYPE_VECTOR_SUBPARTS (rhs1_type),
- TYPE_VECTOR_SUBPARTS (rhs2_type))
- || maybe_ne (TYPE_VECTOR_SUBPARTS (rhs2_type),
- TYPE_VECTOR_SUBPARTS (rhs3_type))
- || maybe_ne (TYPE_VECTOR_SUBPARTS (rhs3_type),
- TYPE_VECTOR_SUBPARTS (lhs_type)))
+ /* If lhs and rhs have different types, check that:
+ (a) Elements have same type.
+ (b) lhs length == rhs3 length.
+ (c) rhs1 length == rhs2 length. */
+
+ if (!(types_compatible_p (lhs_type, rhs1_type)
+ && types_compatible_p (lhs_type, rhs2_type))
+ && TREE_TYPE (lhs_type) == TREE_TYPE (rhs1_type)
+ && TREE_TYPE (lhs_type) == TREE_TYPE (rhs2_type)
+ && known_eq (TYPE_VECTOR_SUBPARTS (lhs_type), TYPE_VECTOR_SUBPARTS (rhs3_type))
+ && known_eq (TYPE_VECTOR_SUBPARTS (rhs1_type), TYPE_VECTOR_SUBPARTS (rhs2_type)))
+ return false;
+
+ if (!useless_type_conversion_p (lhs_type, rhs1_type)
+ || !useless_type_conversion_p (lhs_type, rhs2_type))
{
- error ("vectors with different element number found in %qs",
- code_name);
+ error ("type mismatch in %qs", code_name);
debug_generic_expr (lhs_type);
debug_generic_expr (rhs1_type);
debug_generic_expr (rhs2_type);
@@ -4364,14 +4377,15 @@ verify_gimple_assign_ternary (gassign *stmt)
return true;
}
- if (TREE_CODE (TREE_TYPE (rhs3_type)) != INTEGER_TYPE
- || (TREE_CODE (rhs3) != VECTOR_CST
- && (GET_MODE_BITSIZE (SCALAR_INT_TYPE_MODE
- (TREE_TYPE (rhs3_type)))
- != GET_MODE_BITSIZE (SCALAR_TYPE_MODE
- (TREE_TYPE (rhs1_type))))))
+ if (maybe_ne (TYPE_VECTOR_SUBPARTS (rhs1_type),
+ TYPE_VECTOR_SUBPARTS (rhs2_type))
+ || maybe_ne (TYPE_VECTOR_SUBPARTS (rhs2_type),
+ TYPE_VECTOR_SUBPARTS (rhs3_type))
+ || maybe_ne (TYPE_VECTOR_SUBPARTS (rhs3_type),
+ TYPE_VECTOR_SUBPARTS (lhs_type)))
{
- error ("invalid mask type in %qs", code_name);
+ error ("vectors with different element number found in %qs",
+ code_name);
debug_generic_expr (lhs_type);
debug_generic_expr (rhs1_type);
debug_generic_expr (rhs2_type);
next prev parent reply other threads:[~2021-12-27 10:25 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-12-17 10:05 Prathamesh Kulkarni
2021-12-17 11:07 ` Richard Sandiford
2021-12-27 10:25 ` Prathamesh Kulkarni [this message]
2022-01-03 10:40 ` Richard Biener
2022-01-04 11:50 ` Richard Sandiford
2022-01-04 12:40 ` Richard Biener
2022-01-04 13:42 ` Richard Sandiford
2022-05-03 10:41 ` Prathamesh Kulkarni
2022-05-03 12:55 ` Richard Sandiford
2022-05-09 11:21 ` Prathamesh Kulkarni
2022-05-09 13:52 ` Richard Sandiford
2022-05-09 15:51 ` Prathamesh Kulkarni
2022-05-23 17:27 ` Prathamesh Kulkarni
2022-05-31 11:35 ` Prathamesh Kulkarni
2022-06-01 7: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='CAAgBjMm1pzrd=ekGjVqbKxavobk7aXKg61Z_CHyGkJWYB5sbKQ@mail.gmail.com' \
--to=prathamesh.kulkarni@linaro.org \
--cc=gcc-patches@gcc.gnu.org \
--cc=rguenther@suse.de \
--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).