public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] i386: Fix up *one_cmplv*2* insn with avx512f [PR94343]
@ 2020-03-26 23:46 Jakub Jelinek
  2020-03-30 15:51 ` Jeff Law
  0 siblings, 1 reply; 2+ messages in thread
From: Jakub Jelinek @ 2020-03-26 23:46 UTC (permalink / raw)
  To: Jeff Law, Uros Bizjak; +Cc: gcc-patches

Hi!

This define_insn has two issues.
One is that with -mavx512f -mno-avx512vl it can emit an AVX512VL-only insn
- 128-bit or 256-bit EVEX encoded vpternlog{d,q}.
Another one is that because there is no vpternlog{b,w}, we emit vpternlogd
instead, but then we shouldn't pretend we support masking of that, because
we don't.
The first one can be fixed by forcing the use of %zmm* registers instead of
%xmm* or %ymm* if AVX512F but not AVX512VL, like we do for a couple of other
insns (although that is primarily done in order to support %xmm16+ regs).
But we need to make sure that in that case the input operand isn't memory,
because while we can read and store the higher bits of registers, we don't
want to read from memory more bytes than what we should read.

A variant to these two if_then_else set attrs, condition in the output and
larger condition would be 4 different define_insns (one with something like
VI48_AVX512VL iterator, masking, no g modifiers and "vm" input constraint,
another one with VI48_AVX iterator, !TARGET_AVX512VL in condition,
no masking, g modifiers and "v" input constraint, one with VI12_AVX512VL
iterator, no masking, no g modifiers and "vm" input constraint and last one with
VI12_AVX2 iterator, !TARGET_AVX512VL in condition, no masking, g modifiers
and "v" input constraint, but I think having one pattern is shorter than
that.

Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?

2020-03-26  Jakub Jelinek  <jakub@redhat.com>

	PR target/94343
	* config/i386/sse.md (<mask_codefor>one_cmpl<mode>2<mask_name>): If
	!TARGET_AVX512VL, use 512-bit vpternlog and make sure the input
	operand is a register.  Don't enable masked variants for V*[QH]Imode.

	* gcc.target/i386/avx512f-pr94343.c: New test.
	* gcc.target/i386/avx512vl-pr94343.c: New test.

--- gcc/config/i386/sse.md.jj	2020-03-06 11:35:46.284074858 +0100
+++ gcc/config/i386/sse.md	2020-03-26 18:49:39.644131577 +0100
@@ -12796,14 +12796,29 @@ (define_expand "one_cmpl<mode>2"
 })
 
 (define_insn "<mask_codefor>one_cmpl<mode>2<mask_name>"
-  [(set (match_operand:VI 0 "register_operand" "=v")
-	(xor:VI (match_operand:VI 1 "nonimmediate_operand" "vm")
-		(match_operand:VI 2 "vector_all_ones_operand" "BC")))]
-  "TARGET_AVX512F"
-  "vpternlog<ternlogsuffix>\t{$0x55, %1, %0, %0<mask_operand3>|%0<mask_operand3>, %0, %1, 0x55}"
+  [(set (match_operand:VI 0 "register_operand" "=v,v")
+	(xor:VI (match_operand:VI 1 "nonimmediate_operand" "v,m")
+		(match_operand:VI 2 "vector_all_ones_operand" "BC,BC")))]
+  "TARGET_AVX512F
+   && (!<mask_applied>
+       || <ssescalarmode>mode == SImode
+       || <ssescalarmode>mode == DImode)"
+{
+  if (TARGET_AVX512VL)
+    return "vpternlog<ternlogsuffix>\t{$0x55, %1, %0, %0<mask_operand3>|%0<mask_operand3>, %0, %1, 0x55}";
+  else
+    return "vpternlog<ternlogsuffix>\t{$0x55, %g1, %g0, %g0<mask_operand3>|%g0<mask_operand3>, %g0, %g1, 0x55}";
+}
   [(set_attr "type" "sselog")
    (set_attr "prefix" "evex")
-   (set_attr "mode" "<sseinsnmode>")])
+   (set (attr "mode")
+        (if_then_else (match_test "TARGET_AVX512VL")
+		      (const_string "<sseinsnmode>")
+		      (const_string "XI")))
+   (set (attr "enabled")
+	(if_then_else (eq_attr "alternative" "1")
+		      (symbol_ref "<MODE_SIZE> == 64 || TARGET_AVX512VL")
+		      (const_int 1)))])
 
 (define_expand "<sse2_avx2>_andnot<mode>3"
   [(set (match_operand:VI_AVX2 0 "register_operand")
--- gcc/testsuite/gcc.target/i386/avx512f-pr94343.c.jj	2020-03-26 17:47:40.008654504 +0100
+++ gcc/testsuite/gcc.target/i386/avx512f-pr94343.c	2020-03-26 17:48:37.169811375 +0100
@@ -0,0 +1,12 @@
+/* PR target/94343 */
+/* { dg-do compile } */
+/* { dg-options "-O2 -mavx512f -mno-avx512vl" } */
+/* { dg-final { scan-assembler-not "vpternlogd\[^\n\r]*xmm\[0-9]*" } } */
+
+typedef int __v4si __attribute__((vector_size (16)));
+
+__v4si
+foo (__v4si a)
+{
+  return ~a;
+}
--- gcc/testsuite/gcc.target/i386/avx512vl-pr94343.c.jj	2020-03-26 17:48:53.232573115 +0100
+++ gcc/testsuite/gcc.target/i386/avx512vl-pr94343.c	2020-03-26 17:49:08.034352968 +0100
@@ -0,0 +1,12 @@
+/* PR target/94343 */
+/* { dg-do compile } */
+/* { dg-options "-O2 -mavx512vl" } */
+/* { dg-final { scan-assembler "vpternlogd\[^\n\r]*xmm\[0-9]*" } } */
+
+typedef int __v4si __attribute__((vector_size (16)));
+
+__v4si
+foo (__v4si a)
+{
+  return ~a;
+}

	Jakub


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] i386: Fix up *one_cmplv*2* insn with avx512f [PR94343]
  2020-03-26 23:46 [PATCH] i386: Fix up *one_cmplv*2* insn with avx512f [PR94343] Jakub Jelinek
@ 2020-03-30 15:51 ` Jeff Law
  0 siblings, 0 replies; 2+ messages in thread
From: Jeff Law @ 2020-03-30 15:51 UTC (permalink / raw)
  To: Jakub Jelinek, Uros Bizjak; +Cc: gcc-patches

On Fri, 2020-03-27 at 00:46 +0100, Jakub Jelinek wrote:
> Hi!
> 
> This define_insn has two issues.
> One is that with -mavx512f -mno-avx512vl it can emit an AVX512VL-only insn
> - 128-bit or 256-bit EVEX encoded vpternlog{d,q}.
> Another one is that because there is no vpternlog{b,w}, we emit vpternlogd
> instead, but then we shouldn't pretend we support masking of that, because
> we don't.
> The first one can be fixed by forcing the use of %zmm* registers instead of
> %xmm* or %ymm* if AVX512F but not AVX512VL, like we do for a couple of other
> insns (although that is primarily done in order to support %xmm16+ regs).
> But we need to make sure that in that case the input operand isn't memory,
> because while we can read and store the higher bits of registers, we don't
> want to read from memory more bytes than what we should read.
> 
> A variant to these two if_then_else set attrs, condition in the output and
> larger condition would be 4 different define_insns (one with something like
> VI48_AVX512VL iterator, masking, no g modifiers and "vm" input constraint,
> another one with VI48_AVX iterator, !TARGET_AVX512VL in condition,
> no masking, g modifiers and "v" input constraint, one with VI12_AVX512VL
> iterator, no masking, no g modifiers and "vm" input constraint and last one
> with
> VI12_AVX2 iterator, !TARGET_AVX512VL in condition, no masking, g modifiers
> and "v" input constraint, but I think having one pattern is shorter than
> that.
> 
> Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk?
> 
> 2020-03-26  Jakub Jelinek  <jakub@redhat.com>
> 
> 	PR target/94343
> 	* config/i386/sse.md (<mask_codefor>one_cmpl<mode>2<mask_name>): If
> 	!TARGET_AVX512VL, use 512-bit vpternlog and make sure the input
> 	operand is a register.  Don't enable masked variants for V*[QH]Imode.
> 
> 	* gcc.target/i386/avx512f-pr94343.c: New test.
> 	* gcc.target/i386/avx512vl-pr94343.c: New test.
OK
jeff


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2020-03-30 15:51 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-26 23:46 [PATCH] i386: Fix up *one_cmplv*2* insn with avx512f [PR94343] Jakub Jelinek
2020-03-30 15:51 ` Jeff Law

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).