From d4630b65d12046ecc477d382f5a2094b8250b21b Mon Sep 17 00:00:00 2001 From: Jan Beulich Date: Fri, 3 Jun 2022 10:21:21 +0200 Subject: [PATCH] x86: {,v}psadbw have commutative source operands Like noticed for gas as well (binutils-gdb commit c8cad9d389b7), the "absolute difference" aspect of the insns makes their source operands commutative. gcc/ * config/i386/mmx.md (mmx_psadbw): Convert to expander. (*mmx_psadbw): New. Mark as commutative. * config/i386/sse.md (_psadbw): Convert to expander. (*_psadbw): New. Mark as commutative. --- gcc/config/i386/mmx.md | 16 ++++++++++++---- gcc/config/i386/sse.md | 18 ++++++++++++++---- 2 files changed, 26 insertions(+), 8 deletions(-) diff --git a/gcc/config/i386/mmx.md b/gcc/config/i386/mmx.md index 03aa01f8693..ba53007a35e 100644 --- a/gcc/config/i386/mmx.md +++ b/gcc/config/i386/mmx.md @@ -4405,13 +4405,21 @@ (set_attr "type" "sseiadd") (set_attr "mode" "TI")]) -(define_insn "mmx_psadbw" +(define_expand "mmx_psadbw" + [(set (match_operand:V1DI 0 "register_operand") + (unspec:V1DI [(match_operand:V8QI 1 "register_mmxmem_operand") + (match_operand:V8QI 2 "register_mmxmem_operand")] + UNSPEC_PSADBW))] + "(TARGET_MMX || TARGET_MMX_WITH_SSE) && (TARGET_SSE || TARGET_3DNOW_A)" + "ix86_fixup_binary_operands_no_copy (PLUS, V8QImode, operands);") + +(define_insn "*mmx_psadbw" [(set (match_operand:V1DI 0 "register_operand" "=y,x,Yw") - (unspec:V1DI [(match_operand:V8QI 1 "register_operand" "0,0,Yw") + (unspec:V1DI [(match_operand:V8QI 1 "register_mmxmem_operand" "%0,0,Yw") (match_operand:V8QI 2 "register_mmxmem_operand" "ym,x,Yw")] UNSPEC_PSADBW))] - "(TARGET_MMX || TARGET_MMX_WITH_SSE) - && (TARGET_SSE || TARGET_3DNOW_A)" + "(TARGET_MMX || TARGET_MMX_WITH_SSE) && (TARGET_SSE || TARGET_3DNOW_A) + && ix86_binary_operator_ok (PLUS, V8QImode, operands)" "@ psadbw\t{%2, %0|%0, %2} psadbw\t{%2, %0|%0, %2} diff --git a/gcc/config/i386/sse.md b/gcc/config/i386/sse.md index 8b3163fe5e3..62688f8e29d 100644 --- a/gcc/config/i386/sse.md +++ b/gcc/config/i386/sse.md @@ -19982,13 +19982,23 @@ ;; The correct representation for this is absolutely enormous, and ;; surely not generally useful. -(define_insn "_psadbw" - [(set (match_operand:VI8_AVX2_AVX512BW 0 "register_operand" "=x,YW") +(define_expand "_psadbw" + [(set (match_operand:VI8_AVX2_AVX512BW 0 "register_operand") (unspec:VI8_AVX2_AVX512BW - [(match_operand: 1 "register_operand" "0,YW") - (match_operand: 2 "vector_operand" "xBm,YWm")] + [(match_operand: 1 "vector_operand") + (match_operand: 2 "vector_operand")] UNSPEC_PSADBW))] "TARGET_SSE2" + "ix86_fixup_binary_operands_no_copy (PLUS, mode, operands);") + +(define_insn "*_psadbw" + [(set (match_operand:VI8_AVX2_AVX512BW 0 "register_operand" "=x,YW") + (unspec:VI8_AVX2_AVX512BW + [(match_operand: 1 "vector_operand" "%0,YW") + (match_operand: 2 "vector_operand" "xBm,YWm")] + UNSPEC_PSADBW))] + "TARGET_SSE2 + && ix86_binary_operator_ok (PLUS, mode, operands)" "@ psadbw\t{%2, %0|%0, %2} vpsadbw\t{%2, %1, %0|%0, %1, %2}"