diff mbox series

[i386] Fix ICE [PR target/100549]

Message ID CAMZc-bxANUT1yW0Gv+=v8geGyfvU39NQ_-D=yKjnNkkvczjg3w@mail.gmail.com
State New
Headers show
Series [i386] Fix ICE [PR target/100549] | expand

Commit Message

Hongtao Liu May 13, 2021, 9:12 a.m. UTC
Hi:
  When arg0 is same as arg1 in __builtin_ia32_pcmpgtw,
gimple_build (&stmts, GT_EXPR, cmp_type, arg0, arg1) will simplify the
comparison to vector constant 0, no stmts is generated, which causes
ICE in gsi_insert_before (gsi, stmts, GSI_SAME_STMT). So don't insert
stmts when it's NULL.

  Bootstrapped and regtested on x86_64-linux-gnu{-m32,}
  Ok for trunk?

gcc/ChangeLog:

        PR target/100549
        * config/i386/i386.c (ix86_gimple_fold_builtin): Insert gimple
        stmts if stmts is not NULL.

gcc/testsuite/ChangeLog:

        PR target/100549
        * gcc.target/i386/pr100549.c: New test.

Comments

Richard Biener May 17, 2021, 9:01 a.m. UTC | #1
On Thu, May 13, 2021 at 11:43 AM Hongtao Liu via Gcc-patches
<gcc-patches@gcc.gnu.org> wrote:
>
> Hi:
>   When arg0 is same as arg1 in __builtin_ia32_pcmpgtw,
> gimple_build (&stmts, GT_EXPR, cmp_type, arg0, arg1) will simplify the
> comparison to vector constant 0, no stmts is generated, which causes
> ICE in gsi_insert_before (gsi, stmts, GSI_SAME_STMT). So don't insert
> stmts when it's NULL.
>
>   Bootstrapped and regtested on x86_64-linux-gnu{-m32,}
>   Ok for trunk?

It should use

  gsi_insert_seq_before (gsi, stmts, ...)

otherwise it will only insert the first stmt in the sequence
and gsi_insert_seq_before handles a NULL seq just fine.
(you might want to scan ix86_gimple_fold_builtin for more
similar errors).

OK with that change.

Richard.

> gcc/ChangeLog:
>
>         PR target/100549
>         * config/i386/i386.c (ix86_gimple_fold_builtin): Insert gimple
>         stmts if stmts is not NULL.
>
> gcc/testsuite/ChangeLog:
>
>         PR target/100549
>         * gcc.target/i386/pr100549.c: New test.
>
> --
> BR,
> Hongtao
Hongtao Liu May 17, 2021, 9:56 a.m. UTC | #2
On Mon, May 17, 2021 at 5:01 PM Richard Biener
<richard.guenther@gmail.com> wrote:
>
> On Thu, May 13, 2021 at 11:43 AM Hongtao Liu via Gcc-patches
> <gcc-patches@gcc.gnu.org> wrote:
> >
> > Hi:
> >   When arg0 is same as arg1 in __builtin_ia32_pcmpgtw,
> > gimple_build (&stmts, GT_EXPR, cmp_type, arg0, arg1) will simplify the
> > comparison to vector constant 0, no stmts is generated, which causes
> > ICE in gsi_insert_before (gsi, stmts, GSI_SAME_STMT). So don't insert
> > stmts when it's NULL.
> >
> >   Bootstrapped and regtested on x86_64-linux-gnu{-m32,}
> >   Ok for trunk?
>
> It should use
>
>   gsi_insert_seq_before (gsi, stmts, ...)
>
> otherwise it will only insert the first stmt in the sequence
> and gsi_insert_seq_before handles a NULL seq just fine.

Oh, Good to know that.

> (you might want to scan ix86_gimple_fold_builtin for more
Others are fine.
> similar errors).
>
> OK with that change.
>
> Richard.
>
> > gcc/ChangeLog:
> >
> >         PR target/100549
> >         * config/i386/i386.c (ix86_gimple_fold_builtin): Insert gimple
> >         stmts if stmts is not NULL.
> >
> > gcc/testsuite/ChangeLog:
> >
> >         PR target/100549
> >         * gcc.target/i386/pr100549.c: New test.
> >
> > --
> > BR,
> > Hongtao

Thanks for the review.
diff mbox series

Patch

From 21eeafce731ec28f3d378b5c1cc94f505a677121 Mon Sep 17 00:00:00 2001
From: liuhongt <hongtao.liu@intel.com>
Date: Thu, 13 May 2021 13:08:16 +0800
Subject: [PATCH] [i386] Fix ICE [PR target/100549]

When arg0 is same as arg1 in __builtin_ia32_pcmpgtw,
gimple_build (&stmts, GT_EXPR, cmp_type, arg0, arg1) will simplify the
comparison to vector constant 0, no stmts is generated, which causes
ICE in gsi_insert_before (gsi, stmts, GSI_SAME_STMT). So don't insert
stmts when it's NULL.

gcc/ChangeLog:

	PR target/100549
	* config/i386/i386.c (ix86_gimple_fold_builtin): Insert gimple
	stmts if stmts is not NULL.

gcc/testsuite/ChangeLog:

	PR target/100549
	* gcc.target/i386/pr100549.c: New test.
---
 gcc/config/i386/i386.c                   |   5 +-
 gcc/testsuite/gcc.target/i386/pr100549.c | 108 +++++++++++++++++++++++
 2 files changed, 111 insertions(+), 2 deletions(-)
 create mode 100644 gcc/testsuite/gcc.target/i386/pr100549.c

diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c
index 780da108a7c..245044e0186 100644
--- a/gcc/config/i386/i386.c
+++ b/gcc/config/i386/i386.c
@@ -17981,8 +17981,9 @@  ix86_gimple_fold_builtin (gimple_stmt_iterator *gsi)
 	tree cmp_type = truth_type_for (type);
 	gimple_seq stmts = NULL;
 	tree cmp = gimple_build (&stmts, tcode, cmp_type, arg0, arg1);
-	gsi_insert_before (gsi, stmts, GSI_SAME_STMT);
-	gimple *g = gimple_build_assign (gimple_call_lhs (stmt),
+	if (stmts)
+	  gsi_insert_before (gsi, stmts, GSI_SAME_STMT);
+	gimple* g = gimple_build_assign (gimple_call_lhs (stmt),
 					 VEC_COND_EXPR, cmp,
 					 minus_one_vec, zero_vec);
 	gimple_set_location (g, loc);
diff --git a/gcc/testsuite/gcc.target/i386/pr100549.c b/gcc/testsuite/gcc.target/i386/pr100549.c
new file mode 100644
index 00000000000..83bba3cfd0d
--- /dev/null
+++ b/gcc/testsuite/gcc.target/i386/pr100549.c
@@ -0,0 +1,108 @@ 
+/* PR target/100549  */
+/* { dg-do compile } */
+/* { dg-options "-O -mavx2" } */
+
+typedef char v16qi __attribute__ ((vector_size (16)));
+typedef char v32qi __attribute__ ((vector_size (32)));
+typedef short v8hi __attribute__ ((vector_size (16)));
+typedef short v16hi __attribute__ ((vector_size (32)));
+typedef int v4si __attribute__ ((vector_size (16)));
+typedef int v8si __attribute__ ((vector_size (32)));
+typedef long long v2di __attribute__ ((vector_size (16)));
+typedef long long v4di __attribute__ ((vector_size (32)));
+
+v16qi
+f1 (v16qi a)
+{
+  return __builtin_ia32_pcmpeqb128 (a, a);
+}
+
+v8hi
+f2 (v8hi a)
+{
+  return __builtin_ia32_pcmpeqw128 (a, a);
+}
+
+v4si
+f3 (v4si a)
+{
+  return __builtin_ia32_pcmpeqd128 (a, a);
+}
+
+v2di
+f4 (v2di a)
+{
+  return __builtin_ia32_pcmpeqq (a, a);
+}
+
+v16qi
+f5 (v16qi a)
+{
+  return __builtin_ia32_pcmpgtb128 (a, a);
+}
+
+v8hi
+f6 (v8hi a)
+{
+  return __builtin_ia32_pcmpgtw128 (a, a);
+}
+
+v4si
+f7 (v4si a)
+{
+  return __builtin_ia32_pcmpgtd128 (a, a);
+}
+
+v2di
+f8 (v2di a)
+{
+  return __builtin_ia32_pcmpgtq (a, a);
+}
+
+v32qi
+f9 (v32qi a)
+{
+  return __builtin_ia32_pcmpeqb256 (a, a);
+}
+
+v16hi
+f10 (v16hi a)
+{
+  return __builtin_ia32_pcmpeqw256 (a, a);
+}
+
+v8si
+f11 (v8si a)
+{
+  return __builtin_ia32_pcmpeqd256 (a, a);
+}
+
+v4di
+f12 (v4di a)
+{
+  return __builtin_ia32_pcmpeqq256 (a, a);
+}
+
+v32qi
+f13 (v32qi a)
+{
+  return __builtin_ia32_pcmpgtb256 (a, a);
+}
+
+v16hi
+f14 (v16hi a)
+{
+  return __builtin_ia32_pcmpgtw256 (a, a);
+}
+
+v8si
+f15 (v8si a)
+{
+  return __builtin_ia32_pcmpgtd256 (a, a);
+}
+
+v4di
+f16 (v4di a)
+{
+  return __builtin_ia32_pcmpgtq256 (a, a);
+}
-- 
2.18.1