Re: [PATCH] [AVX512] Fix ICE: Convert integer mask to vector in ix86_expand_fp_vec_cmp/ix86_expand_int_vec_cmp [PR98537]

2021-02-04 Thread Hongtao Liu via Gcc-patches
On Thu, Feb 4, 2021 at 8:00 PM Jakub Jelinek  wrote:
>
> On Thu, Feb 04, 2021 at 01:31:52PM +0800, Hongtao Liu via Gcc-patches wrote:
> * gcc.target/i386/avx512vl-pr92686-vpcmp-1.c: This test is
> used to guard code generation of integer mask comparison, but
> for vector comparison to vector dest, integer mask comparison
> is disliked, so detele this useless test.
> * gcc.target/i386/avx512vl-pr92686-vpcmp-2.c: Ditto.
> * gcc.target/i386/avx512vl-pr92686-vpcmp-intelasm-1.c: Ditto.
>
> s/detele/delete/; but I'd say just write : Remove.
> for all 3 tests, the explanation should go into the commit message, not
> ChangeLog.
> +  /* When op_true is NULL, op_flase must be NULL, vice either.  */
>
> s/flase/false/
> s/vice either/or vice versa/
>
> +  gcc_assert (!op_true == !op_false);
> +
> +  /* When op_true/op_false is NULL or cmp_mode is not valid mask cmp mode,
> + vector dest is required.  */
> +  if (!op_true || !ix86_valid_mask_cmp_mode (cmp_mode))
> +return false;
> +
> +  /* Exclude those could be optimized in ix86_expand_sse_movcc.  */
>
> s/those/those that/
>
> Otherwise LGTM.
>
Ok for backport?
> Jakub
>


-- 
BR,
Hongtao


Re: [PATCH] [AVX512] Fix ICE: Convert integer mask to vector in ix86_expand_fp_vec_cmp/ix86_expand_int_vec_cmp [PR98537]

2021-02-04 Thread Jakub Jelinek via Gcc-patches
On Thu, Feb 04, 2021 at 01:31:52PM +0800, Hongtao Liu via Gcc-patches wrote:
* gcc.target/i386/avx512vl-pr92686-vpcmp-1.c: This test is
used to guard code generation of integer mask comparison, but
for vector comparison to vector dest, integer mask comparison
is disliked, so detele this useless test.
* gcc.target/i386/avx512vl-pr92686-vpcmp-2.c: Ditto.
* gcc.target/i386/avx512vl-pr92686-vpcmp-intelasm-1.c: Ditto.

s/detele/delete/; but I'd say just write : Remove.
for all 3 tests, the explanation should go into the commit message, not
ChangeLog.
+  /* When op_true is NULL, op_flase must be NULL, vice either.  */

s/flase/false/
s/vice either/or vice versa/

+  gcc_assert (!op_true == !op_false);
+
+  /* When op_true/op_false is NULL or cmp_mode is not valid mask cmp mode,
+ vector dest is required.  */
+  if (!op_true || !ix86_valid_mask_cmp_mode (cmp_mode))
+return false;
+
+  /* Exclude those could be optimized in ix86_expand_sse_movcc.  */

s/those/those that/

Otherwise LGTM.

Jakub



Re: [PATCH] [AVX512] Fix ICE: Convert integer mask to vector in ix86_expand_fp_vec_cmp/ix86_expand_int_vec_cmp [PR98537]

2021-02-03 Thread Hongtao Liu via Gcc-patches
Rebase and update patch:

Fix ICE: Don't generate integer mask comparison for 128/256-bits
vector when op_true/op_false are NULL or constm1_rtx/const0_rtx
[PR98537]

in ix86_expand_sse_cmp/ix86_expand_int_sse_cmp

gcc/ChangeLog:

PR target/98537
* config/i386/i386-expand.c (ix86_expand_sse_cmp): Don't
generate integer mask comparison for 128/256-bits vector when
op_true/op_false is NULL_RTX or CONSTM1_RTX/CONST0_RTX. Also
delete redundant !maskcmp condition.
(ix86_expand_int_vec_cmp): Ditto but no redundant deletion
here.
(ix86_expand_sse_movcc): Delete definition of maskcmp, add the
condition directly to if (maskcmp), add extra check for
cmpmode, it should be MODE_INT.
(ix86_expand_fp_vec_cmp): Pass NULL to ix86_expand_sse_cmp's
parameters op_true/op_false.
(ix86_use_mask_cmp_p): New.

gcc/testsuite/ChangeLog:

PR target/98537
* g++.target/i386/avx512bw-pr98537-1.C: New test.
* g++.target/i386/avx512vl-pr98537-1.C: New test.
* g++.target/i386/avx512vl-pr98537-2.C: New test.
* gcc.target/i386/avx512vl-pr88547-1.c: Adjust testcase,
integer mask comparison should not be generated.
* gcc.target/i386/avx512vl-pr92686-vpcmp-1.c: This test is
used to guard code generation of integer mask comparison, but
for vector comparison to vector dest, integer mask comparison
is disliked, so detele this useless test.
* gcc.target/i386/avx512vl-pr92686-vpcmp-2.c: Ditto.
* gcc.target/i386/avx512vl-pr92686-vpcmp-intelasm-1.c: Ditto.



-- 
BR,
Hongtao


0001-Fix-ICE-Don-t-generate-integer-mask-comparision-for-.patch
Description: Binary data


Re: [PATCH] [AVX512] Fix ICE: Convert integer mask to vector in ix86_expand_fp_vec_cmp/ix86_expand_int_vec_cmp [PR98537]

2021-01-25 Thread Hongtao Liu via Gcc-patches
On Thu, Jan 14, 2021 at 7:16 PM Hongtao Liu  wrote:
>
> ping.
>
> On Thu, Jan 7, 2021 at 1:22 PM Hongtao Liu  wrote:
> >
> > On Wed, Jan 6, 2021 at 10:39 PM Jakub Jelinek  wrote:
> > >
> > > On Wed, Jan 06, 2021 at 02:49:13PM +0800, Hongtao Liu wrote:
> > > >   ix86_expand_fp_vec_cmp/ix86_expand_int_vec_cmp are used by vec_cmpmn
> > > > for vector comparison to vector mask, but ix86_expand_sse_cmp(which is
> > > > called in upper 2 functions.) may return integer mask whenever integer
> > > > mask is available, so convert integer mask back to vector mask if
> > > > needed.
> > > >
> > > > gcc/ChangeLog:
> > > >
> > > > PR target/98537
> > > > * config/i386/i386-expand.c (ix86_expand_fp_vec_cmp):
> > > > When cmp is integer mask, convert it to vector.
> > > > (ix86_expand_int_vec_cmp): Ditto.
> > > >
> > > > gcc/testsuite/ChangeLog:
> > > >
> > > > PR target/98537
> > > > * g++.target/i386/avx512bw-pr98537-1.C: New test.
> > > > * g++.target/i386/avx512vl-pr98537-1.C: New test.
> > > > * g++.target/i386/avx512vl-pr98537-2.C: New test.
> > >
> > > Do we optimize it then to an AVX/AVX2 comparison if possible?

  A new patch is proposed to solve a series of performance and
correctness regressions brought by r10-5250.
Integer mask comparison will only be used for 512-bit vectors, and
128/256-bit vcondmn(excluding the case where op_true/op_false is all
1s or 0s, it is actually a vec_cmpmn).

in ix86_expand_sse_cmp/ix86_expand_int_sse_cmp

-  if (ix86_valid_mask_cmp_mode (cmp_ops_mode))
+  if (GET_MODE_SIZE (mode) == 64
+  || (ix86_valid_mask_cmp_mode (cmp_ops_mode)
+ /* When op_true and op_false is NULL, vector dest is required.  */
+ && op_true && op_false
+ /* Gimple sometimes transforms vec_cmpmn to vcondmn with
+op_true/op_false as constm1_rtx/const0_rtx.
+Don't generate integer mask comparison then.  */
+ && !((vector_all_ones_operand (op_true, GET_MODE (op_true))
+   && CONST0_RTX (GET_MODE (op_false)) == op_false)
+  || (vector_all_ones_operand (op_false, GET_MODE (op_false))
+  && CONST0_RTX (GET_MODE (op_true)) == op_true

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

gcc/ChangeLog:

PR target/98537
* config/i386/i386-expand.c (ix86_expand_sse_cmp): Don't
generate integer mask comparison for 128/256-bits vector when
op_true/op_false is NULL_RTX or CONSTM1_RTX/CONST0_RTX. Also
delete redundant !maskcmp condition.
(ix86_expand_int_vec_cmp): Ditto but no redundant deletion
here.
(ix86_expand_sse_movcc): Delete definition of maskcmp, add the
condition directly to if (maskcmp), add extra check for
cmpmode, it should be MODE_INT.
(ix86_expand_fp_vec_cmp): Pass NULL to ix86_expand_sse_cmp's
parameters op_true/op_false.

gcc/testsuite/ChangeLog:

PR target/98537
* g++.target/i386/avx512bw-pr98537-1.C: New test.
* g++.target/i386/avx512vl-pr98537-1.C: New test.
* g++.target/i386/avx512vl-pr98537-2.C: New test.
* gcc.target/i386/avx512vl-pr88547-1.c: Adjust testcase,
integer mask comparison should not be generated.
* gcc.target/i386/avx512vl-pr92686-vpcmp-1.c: This test is
used to guard code generation of integer mask comparison, but
for vector comparison to vector dest, integer mask comparison
is disliked, so detele this useless test.
* gcc.target/i386/avx512vl-pr92686-vpcmp-2.c: Ditto.
* gcc.target/i386/avx512vl-pr92686-vpcmp-intelasm-1.c: Ditto.


-- 
BR,
Hongtao
From 2b648edd06daa432ce65397768e25ab54f470759 Mon Sep 17 00:00:00 2001
From: liuhongt 
Date: Thu, 7 Jan 2021 10:15:33 +0800
Subject: [PATCH] Fix ICE: Don't generate integer mask comparision for
 128/256-bits vector when op_true/op_false are NULL or constm1_rtx/const0_rtx
 [PR98537]

in ix86_expand_sse_cmp/ix86_expand_int_sse_cmp

-  if (ix86_valid_mask_cmp_mode (cmp_ops_mode))
+  if (GET_MODE_SIZE (mode) == 64
+  || (ix86_valid_mask_cmp_mode (cmp_ops_mode)
+	  /* When op_true and op_false is NULL, vector dest is required.  */
+	  && op_true && op_false
+	  /* Gimple sometimes transforms vec_cmpmn to vcondmn with
+	 op_true/op_false as constm1_rtx/const0_rtx.
+	 Don't generate integer mask comparison then.  */
+	  && !((vector_all_ones_operand (op_true, GET_MODE (op_true))
+		&& CONST0_RTX (GET_MODE (op_false)) == op_false)
+	   || (vector_all_ones_operand (op_false, GET_MODE (op_false))
+		   && CONST0_RTX (GET_MODE (op_true)) == op_true

gcc/ChangeLog:

	PR target/98537
	* config/i386/i386-expand.c (ix86_expand_sse_cmp): Don't
	generate integer mask comparison for 128/256-bits vector when
	op_true/op_false is NULL_RTX or CONSTM1_RTX/CONST0_RTX. Also
	delete redundant !maskcmp condition.
	(ix86_expand_int_vec_cmp): Ditto but no 

Re: [PATCH] [AVX512] Fix ICE: Convert integer mask to vector in ix86_expand_fp_vec_cmp/ix86_expand_int_vec_cmp [PR98537]

2021-01-14 Thread Hongtao Liu via Gcc-patches
ping.

On Thu, Jan 7, 2021 at 1:22 PM Hongtao Liu  wrote:
>
> On Wed, Jan 6, 2021 at 10:39 PM Jakub Jelinek  wrote:
> >
> > On Wed, Jan 06, 2021 at 02:49:13PM +0800, Hongtao Liu wrote:
> > >   ix86_expand_fp_vec_cmp/ix86_expand_int_vec_cmp are used by vec_cmpmn
> > > for vector comparison to vector mask, but ix86_expand_sse_cmp(which is
> > > called in upper 2 functions.) may return integer mask whenever integer
> > > mask is available, so convert integer mask back to vector mask if
> > > needed.
> > >
> > > gcc/ChangeLog:
> > >
> > > PR target/98537
> > > * config/i386/i386-expand.c (ix86_expand_fp_vec_cmp):
> > > When cmp is integer mask, convert it to vector.
> > > (ix86_expand_int_vec_cmp): Ditto.
> > >
> > > gcc/testsuite/ChangeLog:
> > >
> > > PR target/98537
> > > * g++.target/i386/avx512bw-pr98537-1.C: New test.
> > > * g++.target/i386/avx512vl-pr98537-1.C: New test.
> > > * g++.target/i386/avx512vl-pr98537-2.C: New test.
> >
> > Do we optimize it then to an AVX/AVX2 comparison if possible?
> >
> When i'm looking at the code, i find there's other places which
> require comparison dest to be vector(i.e. ix86_expand_sse_unpack,
> ix86_expand_mul_widen_evenodd). It's a potential bug.
> So I fix this bug in another way which won't generate an integer mask
> when the comparison dest is required to a vector mask.
>
> Update patch:
>   ix86_expand_sse_cmp/ix86_expand_int_sse_cmp is used for vector
> comparison, considering that avx512 introduces integer mask, but some
> original callers require the dest of comparison to be a vector.
> So add a new parameter vector_mask_p to control the result
> of vector comparison to be vector or not.
>   regtested/bootstrapped on x86_64-linux-gnu{-m32,}.
>
> gcc/ChangeLog:
>
> PR target/98537
> * config/i386/i386-expand.c (ix86_expand_sse_cmp): Add a new
> parameter vector_mask_p to control whether the comparison
> result should be a vector or not.
> (ix86_expand_int_sse_cmp): Ditto.
> (ix86_expand_sse_movcc): cmpmode should be MODE_INT.
> (ix86_expand_fp_movcc): Allow vector comparison dest as
> integer mask.
> (ix86_expand_fp_vcond): Ditto.
> (ix86_expand_int_vcond): Ditto.
> (ix86_expand_fp_vec_cmp): Require vector comparison dest as
> vector.
> (ix86_expand_int_vec_cmp): Ditto.
> (ix86_expand_sse_unpack): Ditto.
> (ix86_expand_mul_widen_evenodd): Ditto.
>
> gcc/testsuite/ChangeLog:
>
> PR target/98537
> * g++.target/i386/avx512bw-pr98537-1.C: New test.
> * g++.target/i386/avx512vl-pr98537-1.C: New test.
> * g++.target/i386/avx512vl-pr98537-2.C: New test.
>
>
> > @@ -4024,8 +4025,18 @@ ix86_expand_fp_vec_cmp (rtx operands[])
> >  cmp = ix86_expand_sse_cmp (operands[0], code, operands[2], operands[3],
> >operands[1], operands[2]);
> >
> > -  if (operands[0] != cmp)
> > -emit_move_insn (operands[0], cmp);
> > +if (operands[0] != cmp)
> > +{
> >
> > The indentation of the if above looks wrong.
> > Otherwise LGTM.
> >
> > Jakub
> >
>
>
> --
> BR,
> Hongtao



-- 
BR,
Hongtao


Re: [PATCH] [AVX512] Fix ICE: Convert integer mask to vector in ix86_expand_fp_vec_cmp/ix86_expand_int_vec_cmp [PR98537]

2021-01-06 Thread Hongtao Liu via Gcc-patches
On Wed, Jan 6, 2021 at 10:39 PM Jakub Jelinek  wrote:
>
> On Wed, Jan 06, 2021 at 02:49:13PM +0800, Hongtao Liu wrote:
> >   ix86_expand_fp_vec_cmp/ix86_expand_int_vec_cmp are used by vec_cmpmn
> > for vector comparison to vector mask, but ix86_expand_sse_cmp(which is
> > called in upper 2 functions.) may return integer mask whenever integer
> > mask is available, so convert integer mask back to vector mask if
> > needed.
> >
> > gcc/ChangeLog:
> >
> > PR target/98537
> > * config/i386/i386-expand.c (ix86_expand_fp_vec_cmp):
> > When cmp is integer mask, convert it to vector.
> > (ix86_expand_int_vec_cmp): Ditto.
> >
> > gcc/testsuite/ChangeLog:
> >
> > PR target/98537
> > * g++.target/i386/avx512bw-pr98537-1.C: New test.
> > * g++.target/i386/avx512vl-pr98537-1.C: New test.
> > * g++.target/i386/avx512vl-pr98537-2.C: New test.
>
> Do we optimize it then to an AVX/AVX2 comparison if possible?
>
When i'm looking at the code, i find there's other places which
require comparison dest to be vector(i.e. ix86_expand_sse_unpack,
ix86_expand_mul_widen_evenodd). It's a potential bug.
So I fix this bug in another way which won't generate an integer mask
when the comparison dest is required to a vector mask.

Update patch:
  ix86_expand_sse_cmp/ix86_expand_int_sse_cmp is used for vector
comparison, considering that avx512 introduces integer mask, but some
original callers require the dest of comparison to be a vector.
So add a new parameter vector_mask_p to control the result
of vector comparison to be vector or not.
  regtested/bootstrapped on x86_64-linux-gnu{-m32,}.

gcc/ChangeLog:

PR target/98537
* config/i386/i386-expand.c (ix86_expand_sse_cmp): Add a new
parameter vector_mask_p to control whether the comparison
result should be a vector or not.
(ix86_expand_int_sse_cmp): Ditto.
(ix86_expand_sse_movcc): cmpmode should be MODE_INT.
(ix86_expand_fp_movcc): Allow vector comparison dest as
integer mask.
(ix86_expand_fp_vcond): Ditto.
(ix86_expand_int_vcond): Ditto.
(ix86_expand_fp_vec_cmp): Require vector comparison dest as
vector.
(ix86_expand_int_vec_cmp): Ditto.
(ix86_expand_sse_unpack): Ditto.
(ix86_expand_mul_widen_evenodd): Ditto.

gcc/testsuite/ChangeLog:

PR target/98537
* g++.target/i386/avx512bw-pr98537-1.C: New test.
* g++.target/i386/avx512vl-pr98537-1.C: New test.
* g++.target/i386/avx512vl-pr98537-2.C: New test.


> @@ -4024,8 +4025,18 @@ ix86_expand_fp_vec_cmp (rtx operands[])
>  cmp = ix86_expand_sse_cmp (operands[0], code, operands[2], operands[3],
>operands[1], operands[2]);
>
> -  if (operands[0] != cmp)
> -emit_move_insn (operands[0], cmp);
> +if (operands[0] != cmp)
> +{
>
> The indentation of the if above looks wrong.
> Otherwise LGTM.
>
> Jakub
>


-- 
BR,
Hongtao
From bae4500e17f7590a45504c8c9e3ab0fe6200681d Mon Sep 17 00:00:00 2001
From: liuhongt 
Date: Thu, 7 Jan 2021 10:15:33 +0800
Subject: [PATCH] Fix ICE: Convert integer mask to vector in
 ix86_expand_fp_vec_cmp/ix86_expand_int_vec_cmp [PR98537]

ix86_expand_sse_cmp/ix86_expand_int_sse_cmp is used for vector
comparison, considering that avx512 introduces integer mask, but some
original callers require the dest of comparison to be a vector.
So add a new parameter vector_mask_p to control the result
of vector comparison to be vector or not.

gcc/ChangeLog:

	PR target/98537
	* config/i386/i386-expand.c (ix86_expand_sse_cmp): Add a new
	parameter vector_mask_p to control whether the comparison
	result should be a vector or not.
	(ix86_expand_int_sse_cmp): Ditto.
	(ix86_expand_sse_movcc): cmpmode should be MODE_INT.
	(ix86_expand_fp_movcc): Allow vector comparison dest as
	integer mask.
	(ix86_expand_fp_vcond): Ditto.
	(ix86_expand_int_vcond): Ditto.
	(ix86_expand_fp_vec_cmp): Require vector comparison dest as
	vector.
	(ix86_expand_int_vec_cmp): Ditto.
	(ix86_expand_sse_unpack): Ditto.
	(ix86_expand_mul_widen_evenodd): Ditto.

gcc/testsuite/ChangeLog:

	PR target/98537
	* g++.target/i386/avx512bw-pr98537-1.C: New test.
	* g++.target/i386/avx512vl-pr98537-1.C: New test.
	* g++.target/i386/avx512vl-pr98537-2.C: New test.
---
 gcc/config/i386/i386-expand.c | 63 ++-
 .../g++.target/i386/avx512bw-pr98537-1.C  | 11 
 .../g++.target/i386/avx512vl-pr98537-1.C  | 40 
 .../g++.target/i386/avx512vl-pr98537-2.C  |  8 +++
 4 files changed, 93 insertions(+), 29 deletions(-)
 create mode 100644 gcc/testsuite/g++.target/i386/avx512bw-pr98537-1.C
 create mode 100644 gcc/testsuite/g++.target/i386/avx512vl-pr98537-1.C
 create mode 100644 gcc/testsuite/g++.target/i386/avx512vl-pr98537-2.C

diff --git a/gcc/config/i386/i386-expand.c b/gcc/config/i386/i386-expand.c
index 6e08fd32726..1e4ef3b9f3f 100644
--- 

Re: [PATCH] [AVX512] Fix ICE: Convert integer mask to vector in ix86_expand_fp_vec_cmp/ix86_expand_int_vec_cmp [PR98537]

2021-01-06 Thread Jakub Jelinek via Gcc-patches
On Wed, Jan 06, 2021 at 02:49:13PM +0800, Hongtao Liu wrote:
>   ix86_expand_fp_vec_cmp/ix86_expand_int_vec_cmp are used by vec_cmpmn
> for vector comparison to vector mask, but ix86_expand_sse_cmp(which is
> called in upper 2 functions.) may return integer mask whenever integer
> mask is available, so convert integer mask back to vector mask if
> needed.
> 
> gcc/ChangeLog:
> 
> PR target/98537
> * config/i386/i386-expand.c (ix86_expand_fp_vec_cmp):
> When cmp is integer mask, convert it to vector.
> (ix86_expand_int_vec_cmp): Ditto.
> 
> gcc/testsuite/ChangeLog:
> 
> PR target/98537
> * g++.target/i386/avx512bw-pr98537-1.C: New test.
> * g++.target/i386/avx512vl-pr98537-1.C: New test.
> * g++.target/i386/avx512vl-pr98537-2.C: New test.

Do we optimize it then to an AVX/AVX2 comparison if possible?

@@ -4024,8 +4025,18 @@ ix86_expand_fp_vec_cmp (rtx operands[])
 cmp = ix86_expand_sse_cmp (operands[0], code, operands[2], operands[3],
   operands[1], operands[2]);
 
-  if (operands[0] != cmp)
-emit_move_insn (operands[0], cmp);
+if (operands[0] != cmp)
+{

The indentation of the if above looks wrong.
Otherwise LGTM.

Jakub



[PATCH] [AVX512] Fix ICE: Convert integer mask to vector in ix86_expand_fp_vec_cmp/ix86_expand_int_vec_cmp [PR98537]

2021-01-05 Thread Hongtao Liu via Gcc-patches
Hi:
  ix86_expand_fp_vec_cmp/ix86_expand_int_vec_cmp are used by vec_cmpmn
for vector comparison to vector mask, but ix86_expand_sse_cmp(which is
called in upper 2 functions.) may return integer mask whenever integer
mask is available, so convert integer mask back to vector mask if
needed.

gcc/ChangeLog:

PR target/98537
* config/i386/i386-expand.c (ix86_expand_fp_vec_cmp):
When cmp is integer mask, convert it to vector.
(ix86_expand_int_vec_cmp): Ditto.

gcc/testsuite/ChangeLog:

PR target/98537
* g++.target/i386/avx512bw-pr98537-1.C: New test.
* g++.target/i386/avx512vl-pr98537-1.C: New test.
* g++.target/i386/avx512vl-pr98537-2.C: New test.

--
BR,
Hongtao
From f7c8341793639c401199d5029053244cd7e5f828 Mon Sep 17 00:00:00 2001
From: liuhongt 
Date: Wed, 6 Jan 2021 11:24:00 +0800
Subject: [PATCH] [AVX512] Fix ICE: Convert integer mask to vector in
 ix86_expand_fp_vec_cmp/ix86_expand_int_vec_cmp [PR98537]

gcc/ChangeLog:

	PR target/98537
	* config/i386/i386-expand.c (ix86_expand_fp_vec_cmp):
	When cmp is integer mask, convert it to vector.
	(ix86_expand_int_vec_cmp): Ditto.

gcc/testsuite/ChangeLog:

	PR target/98537
	* g++.target/i386/avx512bw-pr98537-1.C: New test.
	* g++.target/i386/avx512vl-pr98537-1.C: New test.
	* g++.target/i386/avx512vl-pr98537-2.C: New test.
---
 gcc/config/i386/i386-expand.c | 28 +++--
 .../g++.target/i386/avx512bw-pr98537-1.C  | 11 +
 .../g++.target/i386/avx512vl-pr98537-1.C  | 40 +++
 .../g++.target/i386/avx512vl-pr98537-2.C  |  8 
 4 files changed, 84 insertions(+), 3 deletions(-)
 create mode 100644 gcc/testsuite/g++.target/i386/avx512bw-pr98537-1.C
 create mode 100644 gcc/testsuite/g++.target/i386/avx512vl-pr98537-1.C
 create mode 100644 gcc/testsuite/g++.target/i386/avx512vl-pr98537-2.C

diff --git a/gcc/config/i386/i386-expand.c b/gcc/config/i386/i386-expand.c
index 6e08fd32726..c879953b023 100644
--- a/gcc/config/i386/i386-expand.c
+++ b/gcc/config/i386/i386-expand.c
@@ -3991,6 +3991,7 @@ bool
 ix86_expand_fp_vec_cmp (rtx operands[])
 {
   enum rtx_code code = GET_CODE (operands[1]);
+  machine_mode dest_mode = GET_MODE (operands[0]);
   rtx cmp;
 
   code = ix86_prepare_sse_fp_compare_args (operands[0], code,
@@ -4024,8 +4025,18 @@ ix86_expand_fp_vec_cmp (rtx operands[])
 cmp = ix86_expand_sse_cmp (operands[0], code, operands[2], operands[3],
 			   operands[1], operands[2]);
 
-  if (operands[0] != cmp)
-emit_move_insn (operands[0], cmp);
+if (operands[0] != cmp)
+{
+  if (GET_MODE (cmp) == dest_mode)
+	emit_move_insn (operands[0], cmp);
+  else
+	{
+	  gcc_assert (ix86_valid_mask_cmp_mode (dest_mode));
+	  ix86_expand_sse_movcc (operands[0], cmp,
+ CONSTM1_RTX (dest_mode),
+ CONST0_RTX (dest_mode));
+	}
+}
 
   return true;
 }
@@ -4286,6 +4297,7 @@ bool
 ix86_expand_int_vec_cmp (rtx operands[])
 {
   rtx_code code = GET_CODE (operands[1]);
+  machine_mode dest_mode = GET_MODE (operands[0]);
   bool negate = false;
   rtx cmp = ix86_expand_int_sse_cmp (operands[0], code, operands[2],
  operands[3], NULL, NULL, );
@@ -4301,7 +4313,17 @@ ix86_expand_int_vec_cmp (rtx operands[])
   gcc_assert (!negate);
 
   if (operands[0] != cmp)
-emit_move_insn (operands[0], cmp);
+{
+  if (GET_MODE (cmp) == dest_mode)
+	emit_move_insn (operands[0], cmp);
+  else
+	{
+	  gcc_assert (ix86_valid_mask_cmp_mode (dest_mode));
+	  ix86_expand_sse_movcc (operands[0], cmp,
+ CONSTM1_RTX (dest_mode),
+ CONST0_RTX (dest_mode));
+	}
+}
 
   return true;
 }
diff --git a/gcc/testsuite/g++.target/i386/avx512bw-pr98537-1.C b/gcc/testsuite/g++.target/i386/avx512bw-pr98537-1.C
new file mode 100644
index 000..969684a222b
--- /dev/null
+++ b/gcc/testsuite/g++.target/i386/avx512bw-pr98537-1.C
@@ -0,0 +1,11 @@
+/* PR target/98537 */
+/* { dg-do compile } */
+/* { dg-options "-O2 -march=x86-64 -std=c++11" } */
+
+#define TYPEV char
+#define TYPEW short
+
+#define T_ARR		\
+  __attribute__ ((target ("avx512vl,avx512bw")))
+
+#include "avx512vl-pr98537-1.C"
diff --git a/gcc/testsuite/g++.target/i386/avx512vl-pr98537-1.C b/gcc/testsuite/g++.target/i386/avx512vl-pr98537-1.C
new file mode 100644
index 000..b2ba9da
--- /dev/null
+++ b/gcc/testsuite/g++.target/i386/avx512vl-pr98537-1.C
@@ -0,0 +1,40 @@
+/* PR target/98537 */
+/* { dg-do compile } */
+/* { dg-options "-O2 -march=x86-64 -std=c++11" } */
+
+#ifndef TYPEV
+#define TYPEV int
+#endif
+
+#ifndef TYPEW
+#define TYPEW long long
+#endif
+
+#ifndef T_ARR
+#define T_ARR	\
+  __attribute__ ((target ("avx512vl")))
+#endif
+
+typedef TYPEV V __attribute__((__vector_size__(32)));
+typedef TYPEW W __attribute__((__vector_size__(32)));
+
+W c, d;
+struct B {};
+B e;
+struct C { W i; };
+void foo (C);
+
+C
+operator== (B, B)
+{
+  W r = (V)c == (V)d;
+  return {r};
+}
+
+void
+T_ARR
+bar