* [PATCH] [x86] Fix unrecognizable insn due to illegal immediate_operand (const_int 255) of QImode.
@ 2022-11-28 13:05 liuhongt
2022-11-29 7:04 ` Hongtao Liu
0 siblings, 1 reply; 4+ messages in thread
From: liuhongt @ 2022-11-28 13:05 UTC (permalink / raw)
To: gcc-patches; +Cc: crazylht, hjl.tools, ubizjak
For __builtin_ia32_vec_set_v16qi (a, -1, 2) with
!flag_signed_char. it's transformed to
__builtin_ia32_vec_set_v16qi (_4, 255, 2) in the gimple,
and expanded to (const_int 255) in the rtl. But for immediate_operand,
it expects (const_int 255) to be signed extended to
(const_int -1). The mismatch caused an unrecognizable insn error.
expand_expr_real_1 generates (const_int 255) without considering the target mode.
I guess it's on purpose, so I'll leave that alone and only change the expander
in the backend. After applying convert_modes to (const_int 255),
it's transformed to (const_int -1) which fix the issue.
Bootstrapped and regtested x86_64-pc-linux-gnu{-m32,}.
Ok for trunk(and backport to GCC-10/11/12 release branches)?
gcc/ChangeLog:
PR target/107863
* config/i386/i386-expand.cc (ix86_expand_vec_set_builtin):
Convert op1 to target mode whenever mode mismatch.
gcc/testsuite/ChangeLog:
* gcc.target/i386/pr107863.c: New test.
---
gcc/config/i386/i386-expand.cc | 2 +-
gcc/testsuite/gcc.target/i386/pr107863.c | 8 ++++++++
2 files changed, 9 insertions(+), 1 deletion(-)
create mode 100644 gcc/testsuite/gcc.target/i386/pr107863.c
diff --git a/gcc/config/i386/i386-expand.cc b/gcc/config/i386/i386-expand.cc
index 0373c3614a4..c639ee3a9f7 100644
--- a/gcc/config/i386/i386-expand.cc
+++ b/gcc/config/i386/i386-expand.cc
@@ -12475,7 +12475,7 @@ ix86_expand_vec_set_builtin (tree exp)
op1 = expand_expr (arg1, NULL_RTX, mode1, EXPAND_NORMAL);
elt = get_element_number (TREE_TYPE (arg0), arg2);
- if (GET_MODE (op1) != mode1 && GET_MODE (op1) != VOIDmode)
+ if (GET_MODE (op1) != mode1)
op1 = convert_modes (mode1, GET_MODE (op1), op1, true);
op0 = force_reg (tmode, op0);
diff --git a/gcc/testsuite/gcc.target/i386/pr107863.c b/gcc/testsuite/gcc.target/i386/pr107863.c
new file mode 100644
index 00000000000..99fd85d9765
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/pr107863.c
@@ -0,0 +1,8 @@
+/* { dg-do compile } */
+/* { dg-options "-mavx2 -O" } */
+
+typedef char v16qi __attribute__((vector_size(16)));
+
+v16qi foo(v16qi a){
+ return __builtin_ia32_vec_set_v16qi (a, -1, 2);
+}
--
2.27.0
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] [x86] Fix unrecognizable insn due to illegal immediate_operand (const_int 255) of QImode.
2022-11-28 13:05 [PATCH] [x86] Fix unrecognizable insn due to illegal immediate_operand (const_int 255) of QImode liuhongt
@ 2022-11-29 7:04 ` Hongtao Liu
2022-11-29 19:11 ` H.J. Lu
0 siblings, 1 reply; 4+ messages in thread
From: Hongtao Liu @ 2022-11-29 7:04 UTC (permalink / raw)
To: liuhongt; +Cc: gcc-patches, hjl.tools, ubizjak
On Mon, Nov 28, 2022 at 9:06 PM liuhongt <hongtao.liu@intel.com> wrote:
>
> For __builtin_ia32_vec_set_v16qi (a, -1, 2) with
> !flag_signed_char. it's transformed to
> __builtin_ia32_vec_set_v16qi (_4, 255, 2) in the gimple,
> and expanded to (const_int 255) in the rtl. But for immediate_operand,
> it expects (const_int 255) to be signed extended to
> (const_int -1). The mismatch caused an unrecognizable insn error.
>
> expand_expr_real_1 generates (const_int 255) without considering the target mode.
> I guess it's on purpose, so I'll leave that alone and only change the expander
> in the backend. After applying convert_modes to (const_int 255),
> it's transformed to (const_int -1) which fix the issue.
>
> Bootstrapped and regtested x86_64-pc-linux-gnu{-m32,}.
> Ok for trunk(and backport to GCC-10/11/12 release branches)?
Drop this patch since it's not a complete solution, there're also
other QI builtins which is not handled.
>
> gcc/ChangeLog:
>
> PR target/107863
> * config/i386/i386-expand.cc (ix86_expand_vec_set_builtin):
> Convert op1 to target mode whenever mode mismatch.
>
> gcc/testsuite/ChangeLog:
>
> * gcc.target/i386/pr107863.c: New test.
> ---
> gcc/config/i386/i386-expand.cc | 2 +-
> gcc/testsuite/gcc.target/i386/pr107863.c | 8 ++++++++
> 2 files changed, 9 insertions(+), 1 deletion(-)
> create mode 100644 gcc/testsuite/gcc.target/i386/pr107863.c
>
> diff --git a/gcc/config/i386/i386-expand.cc b/gcc/config/i386/i386-expand.cc
> index 0373c3614a4..c639ee3a9f7 100644
> --- a/gcc/config/i386/i386-expand.cc
> +++ b/gcc/config/i386/i386-expand.cc
> @@ -12475,7 +12475,7 @@ ix86_expand_vec_set_builtin (tree exp)
> op1 = expand_expr (arg1, NULL_RTX, mode1, EXPAND_NORMAL);
> elt = get_element_number (TREE_TYPE (arg0), arg2);
>
> - if (GET_MODE (op1) != mode1 && GET_MODE (op1) != VOIDmode)
> + if (GET_MODE (op1) != mode1)
> op1 = convert_modes (mode1, GET_MODE (op1), op1, true);
>
> op0 = force_reg (tmode, op0);
> diff --git a/gcc/testsuite/gcc.target/i386/pr107863.c b/gcc/testsuite/gcc.target/i386/pr107863.c
> new file mode 100644
> index 00000000000..99fd85d9765
> --- /dev/null
> +++ b/gcc/testsuite/gcc.target/i386/pr107863.c
> @@ -0,0 +1,8 @@
> +/* { dg-do compile } */
> +/* { dg-options "-mavx2 -O" } */
> +
> +typedef char v16qi __attribute__((vector_size(16)));
> +
> +v16qi foo(v16qi a){
> + return __builtin_ia32_vec_set_v16qi (a, -1, 2);
> +}
> --
> 2.27.0
>
--
BR,
Hongtao
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] [x86] Fix unrecognizable insn due to illegal immediate_operand (const_int 255) of QImode.
2022-11-29 7:04 ` Hongtao Liu
@ 2022-11-29 19:11 ` H.J. Lu
2022-11-30 2:03 ` Hongtao Liu
0 siblings, 1 reply; 4+ messages in thread
From: H.J. Lu @ 2022-11-29 19:11 UTC (permalink / raw)
To: Hongtao Liu; +Cc: liuhongt, gcc-patches, ubizjak
On Mon, Nov 28, 2022 at 11:04 PM Hongtao Liu <crazylht@gmail.com> wrote:
>
> On Mon, Nov 28, 2022 at 9:06 PM liuhongt <hongtao.liu@intel.com> wrote:
> >
> > For __builtin_ia32_vec_set_v16qi (a, -1, 2) with
> > !flag_signed_char. it's transformed to
> > __builtin_ia32_vec_set_v16qi (_4, 255, 2) in the gimple,
> > and expanded to (const_int 255) in the rtl. But for immediate_operand,
> > it expects (const_int 255) to be signed extended to
> > (const_int -1). The mismatch caused an unrecognizable insn error.
> >
> > expand_expr_real_1 generates (const_int 255) without considering the target mode.
> > I guess it's on purpose, so I'll leave that alone and only change the expander
> > in the backend. After applying convert_modes to (const_int 255),
> > it's transformed to (const_int -1) which fix the issue.
> >
> > Bootstrapped and regtested x86_64-pc-linux-gnu{-m32,}.
> > Ok for trunk(and backport to GCC-10/11/12 release branches)?
> Drop this patch since it's not a complete solution, there're also
> other QI builtins which is not handled.
I checked the x86 backend. __builtin_ia32_vec_set_v16qi is the
only intrinsic with this issue.
> >
> > gcc/ChangeLog:
> >
> > PR target/107863
> > * config/i386/i386-expand.cc (ix86_expand_vec_set_builtin):
> > Convert op1 to target mode whenever mode mismatch.
> >
> > gcc/testsuite/ChangeLog:
> >
> > * gcc.target/i386/pr107863.c: New test.
> > ---
> > gcc/config/i386/i386-expand.cc | 2 +-
> > gcc/testsuite/gcc.target/i386/pr107863.c | 8 ++++++++
> > 2 files changed, 9 insertions(+), 1 deletion(-)
> > create mode 100644 gcc/testsuite/gcc.target/i386/pr107863.c
> >
> > diff --git a/gcc/config/i386/i386-expand.cc b/gcc/config/i386/i386-expand.cc
> > index 0373c3614a4..c639ee3a9f7 100644
> > --- a/gcc/config/i386/i386-expand.cc
> > +++ b/gcc/config/i386/i386-expand.cc
> > @@ -12475,7 +12475,7 @@ ix86_expand_vec_set_builtin (tree exp)
> > op1 = expand_expr (arg1, NULL_RTX, mode1, EXPAND_NORMAL);
> > elt = get_element_number (TREE_TYPE (arg0), arg2);
> >
> > - if (GET_MODE (op1) != mode1 && GET_MODE (op1) != VOIDmode)
> > + if (GET_MODE (op1) != mode1)
> > op1 = convert_modes (mode1, GET_MODE (op1), op1, true);
> >
> > op0 = force_reg (tmode, op0);
> > diff --git a/gcc/testsuite/gcc.target/i386/pr107863.c b/gcc/testsuite/gcc.target/i386/pr107863.c
> > new file mode 100644
> > index 00000000000..99fd85d9765
> > --- /dev/null
> > +++ b/gcc/testsuite/gcc.target/i386/pr107863.c
> > @@ -0,0 +1,8 @@
> > +/* { dg-do compile } */
> > +/* { dg-options "-mavx2 -O" } */
> > +
> > +typedef char v16qi __attribute__((vector_size(16)));
> > +
> > +v16qi foo(v16qi a){
> > + return __builtin_ia32_vec_set_v16qi (a, -1, 2);
> > +}
> > --
> > 2.27.0
> >
>
>
> --
> BR,
> Hongtao
--
H.J.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] [x86] Fix unrecognizable insn due to illegal immediate_operand (const_int 255) of QImode.
2022-11-29 19:11 ` H.J. Lu
@ 2022-11-30 2:03 ` Hongtao Liu
0 siblings, 0 replies; 4+ messages in thread
From: Hongtao Liu @ 2022-11-30 2:03 UTC (permalink / raw)
To: H.J. Lu; +Cc: liuhongt, gcc-patches, ubizjak
On Wed, Nov 30, 2022 at 3:12 AM H.J. Lu <hjl.tools@gmail.com> wrote:
>
> On Mon, Nov 28, 2022 at 11:04 PM Hongtao Liu <crazylht@gmail.com> wrote:
> >
> > On Mon, Nov 28, 2022 at 9:06 PM liuhongt <hongtao.liu@intel.com> wrote:
> > >
> > > For __builtin_ia32_vec_set_v16qi (a, -1, 2) with
> > > !flag_signed_char. it's transformed to
> > > __builtin_ia32_vec_set_v16qi (_4, 255, 2) in the gimple,
> > > and expanded to (const_int 255) in the rtl. But for immediate_operand,
> > > it expects (const_int 255) to be signed extended to
> > > (const_int -1). The mismatch caused an unrecognizable insn error.
> > >
> > > expand_expr_real_1 generates (const_int 255) without considering the target mode.
> > > I guess it's on purpose, so I'll leave that alone and only change the expander
> > > in the backend. After applying convert_modes to (const_int 255),
> > > it's transformed to (const_int -1) which fix the issue.
> > >
> > > Bootstrapped and regtested x86_64-pc-linux-gnu{-m32,}.
> > > Ok for trunk(and backport to GCC-10/11/12 release branches)?
> > Drop this patch since it's not a complete solution, there're also
> > other QI builtins which is not handled.
>
> I checked the x86 backend. __builtin_ia32_vec_set_v16qi is the
> only intrinsic with this issue.
Ok, I'll commit the patch.
>
> > >
> > > gcc/ChangeLog:
> > >
> > > PR target/107863
> > > * config/i386/i386-expand.cc (ix86_expand_vec_set_builtin):
> > > Convert op1 to target mode whenever mode mismatch.
> > >
> > > gcc/testsuite/ChangeLog:
> > >
> > > * gcc.target/i386/pr107863.c: New test.
> > > ---
> > > gcc/config/i386/i386-expand.cc | 2 +-
> > > gcc/testsuite/gcc.target/i386/pr107863.c | 8 ++++++++
> > > 2 files changed, 9 insertions(+), 1 deletion(-)
> > > create mode 100644 gcc/testsuite/gcc.target/i386/pr107863.c
> > >
> > > diff --git a/gcc/config/i386/i386-expand.cc b/gcc/config/i386/i386-expand.cc
> > > index 0373c3614a4..c639ee3a9f7 100644
> > > --- a/gcc/config/i386/i386-expand.cc
> > > +++ b/gcc/config/i386/i386-expand.cc
> > > @@ -12475,7 +12475,7 @@ ix86_expand_vec_set_builtin (tree exp)
> > > op1 = expand_expr (arg1, NULL_RTX, mode1, EXPAND_NORMAL);
> > > elt = get_element_number (TREE_TYPE (arg0), arg2);
> > >
> > > - if (GET_MODE (op1) != mode1 && GET_MODE (op1) != VOIDmode)
> > > + if (GET_MODE (op1) != mode1)
> > > op1 = convert_modes (mode1, GET_MODE (op1), op1, true);
> > >
> > > op0 = force_reg (tmode, op0);
> > > diff --git a/gcc/testsuite/gcc.target/i386/pr107863.c b/gcc/testsuite/gcc.target/i386/pr107863.c
> > > new file mode 100644
> > > index 00000000000..99fd85d9765
> > > --- /dev/null
> > > +++ b/gcc/testsuite/gcc.target/i386/pr107863.c
> > > @@ -0,0 +1,8 @@
> > > +/* { dg-do compile } */
> > > +/* { dg-options "-mavx2 -O" } */
> > > +
> > > +typedef char v16qi __attribute__((vector_size(16)));
> > > +
> > > +v16qi foo(v16qi a){
> > > + return __builtin_ia32_vec_set_v16qi (a, -1, 2);
> > > +}
> > > --
> > > 2.27.0
> > >
> >
> >
> > --
> > BR,
> > Hongtao
>
>
>
> --
> H.J.
--
BR,
Hongtao
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2022-11-30 2:03 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-11-28 13:05 [PATCH] [x86] Fix unrecognizable insn due to illegal immediate_operand (const_int 255) of QImode liuhongt
2022-11-29 7:04 ` Hongtao Liu
2022-11-29 19:11 ` H.J. Lu
2022-11-30 2:03 ` Hongtao Liu
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).