From patchwork Fri Jun 16 02:09:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: liuhongt X-Patchwork-Id: 108781 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp1038299vqr; Thu, 15 Jun 2023 19:12:58 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6mqdDZ3BBopR1rsxgRsgVwG53QG0CUddkTZM8uLgt9HV1nyJxg5yGZCN2tdYD8ZGqePKX1 X-Received: by 2002:a17:906:9c49:b0:974:6334:f6b2 with SMTP id fg9-20020a1709069c4900b009746334f6b2mr465070ejc.22.1686881578308; Thu, 15 Jun 2023 19:12:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686881578; cv=none; d=google.com; s=arc-20160816; b=s0bp8YYCfbqDP8Xl8avrpypDr1I18aVfbCEVvxCMgGVlI4qb8Z5S9RpG+6oBRDs9+1 VPnByaJRRIIlQmlueMkZDF1fij9kRpT0PhZapXrf1rNRzz9agvj+5/m1Hpn7hC+Ermos VRUNodt6bC0aHSqqU/le3IJzXjBT/Q3fmBya9gaZaIZFk9u9uqBXc2PRvV4WUo6UskyW DZeP3F0G+zcyDpCFuVMCXi+ZPQX3njJ6HdB5/T623IoF4ozH3a1dMPpOl8Sal6lp+UUl UXjLCF9+BWZ83ktZUFKaLQWd+ID7gICxNqMOrYbRpySKQ0aHWngYAqqmFfyWQvSKqzIG MOrw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:message-id:date:subject:cc :to:dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=zCmZSbFi19D0iqz98KbRmcHo0lsiw9xv+OC56REvljc=; b=mtOJLu91HObh2Ksj0kz0dnoVKRB6304Sk+XX2IpZSFRsiw/8670P65qLTHj1jpSIhX /DjvYF+x/8qpfUN9u+rfyu5rW6gx/CXppwen62/lRQcJylmHrpNus4ojGgu8Vqjrvj1D kKT1ERDaWd7bIczwJB34fDI+gT132SiDeiOek7o0wkidaZHCB0jqyWvvNlcAOLHjGBxu tDZcUeL0fZGFkVGmwkM9m0PqsYHXx7G79h0gb+IzFepxdKwnREPbXoOgiJgcT5YRJVXA xFbzWwmKqL/ILnyA85oSakb8vDyUsVH8jqO1ViueGDEnEVgf1rYt/UQG4rRcIJvvBHLX vlNA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=A9EmAxLx; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id w26-20020a17090652da00b0098278ade520si2573371ejn.301.2023.06.15.19.12.58 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 15 Jun 2023 19:12:58 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=A9EmAxLx; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 3D6003856611 for ; Fri, 16 Jun 2023 02:12:57 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 3D6003856611 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1686881577; bh=zCmZSbFi19D0iqz98KbRmcHo0lsiw9xv+OC56REvljc=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=A9EmAxLxj30aoJ2z++FsvyTdtjCDS8UGkNlUlBwgKFFgjQosvcWy7vLrOyELTmiS+ 3hOD/64+K5xK60DnQLUtttujRwb6czf/rPOErn1X7Caa8TJie5J/rGWH5MI5yDMr59 gfY0BoBMBYeOFOQ3Tx1T8JHGjNrUQw82u2kJXPOU= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by sourceware.org (Postfix) with ESMTPS id 28CEE3858C36 for ; Fri, 16 Jun 2023 02:12:10 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 28CEE3858C36 X-IronPort-AV: E=McAfee;i="6600,9927,10742"; a="359094492" X-IronPort-AV: E=Sophos;i="6.00,246,1681196400"; d="scan'208";a="359094492" Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Jun 2023 19:12:00 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10742"; a="825537974" X-IronPort-AV: E=Sophos;i="6.00,246,1681196400"; d="scan'208";a="825537974" Received: from shvmail03.sh.intel.com ([10.239.245.20]) by fmsmga002.fm.intel.com with ESMTP; 15 Jun 2023 19:11:59 -0700 Received: from shliclel4217.sh.intel.com (shliclel4217.sh.intel.com [10.239.240.127]) by shvmail03.sh.intel.com (Postfix) with ESMTP id 6675E10079A1; Fri, 16 Jun 2023 10:11:58 +0800 (CST) To: gcc-patches@gcc.gnu.org Cc: ubizjak@gmail.com Subject: [PATCH 1/2] Reimplement packuswb/packusdw with UNSPEC_US_TRUNCATE instead of original us_truncate. Date: Fri, 16 Jun 2023 10:09:57 +0800 Message-Id: <20230616020958.1413585-1-hongtao.liu@intel.com> X-Mailer: git-send-email 2.39.1.388.g2fc9e9ca3c MIME-Version: 1.0 X-Spam-Status: No, score=-12.0 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: liuhongt via Gcc-patches From: liuhongt Reply-To: liuhongt Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1768823537883273633?= X-GMAIL-MSGID: =?utf-8?q?1768823537883273633?= packuswb/packusdw does unsigned saturation for signed source, but rtl us_truncate means does unsigned saturation for unsigned source. So for value -1, packuswb will produce 0, but us_truncate produces 255. The patch reimplement those related patterns and functions with UNSPEC_US_TRUNCATE instead of us_truncate. The patch will fix below testcase which failed after g:921b841350c4fc298d09f6c5674663e0f4208610 added constant-folding for US_TRUNCATE FAIL: gcc.target/i386/avx-vpackuswb-1.c execution test FAIL: gcc.target/i386/avx2-vpackusdw-2.c execution test FAIL: gcc.target/i386/avx2-vpackuswb-2.c execution test FAIL: gcc.target/i386/sse2-packuswb-1.c execution test Bootstrapped and regtested on x86_64-pc-linux-gnu. Ok for trunk? gcc/ChangeLog: PR target/110235 * config/i386/i386-expand.cc (ix86_split_mmx_pack): Use UNSPEC_US_TRUNCATE instead of original us_truncate for packusdw/packuswb. * config/i386/mmx.md (mmx_packswb): Splitted to below 2 new patterns. (mmx_packsswb): New reload_completed define_insn_and_split. (mmx_packuswb): Ditto. (mmx_packusdw): Use UNSPEC_US_TRUNCATE instead of original us_truncate. (s_trunsuffix): Removed. (any_s_truncate): Removed. * config/i386/sse.md (_packuswb): Use UNSPEC_US_TRUNCATE instead of original us_truncate. (_packusdw): Ditto. * config/i386/i386.md (UNSPEC_US_TRUNCATE): New unspec_c_enum. --- gcc/config/i386/i386-expand.cc | 20 ++++++++++++---- gcc/config/i386/i386.md | 4 ++++ gcc/config/i386/mmx.md | 43 ++++++++++++++++++++++------------ gcc/config/i386/sse.md | 20 ++++++++-------- 4 files changed, 57 insertions(+), 30 deletions(-) diff --git a/gcc/config/i386/i386-expand.cc b/gcc/config/i386/i386-expand.cc index def060ab562..35e2740f9b6 100644 --- a/gcc/config/i386/i386-expand.cc +++ b/gcc/config/i386/i386-expand.cc @@ -1019,6 +1019,7 @@ ix86_split_mmx_pack (rtx operands[], enum rtx_code code) rtx op0 = operands[0]; rtx op1 = operands[1]; rtx op2 = operands[2]; + rtx src; machine_mode dmode = GET_MODE (op0); machine_mode smode = GET_MODE (op1); @@ -1042,11 +1043,20 @@ ix86_split_mmx_pack (rtx operands[], enum rtx_code code) op1 = lowpart_subreg (sse_smode, op1, GET_MODE (op1)); op2 = lowpart_subreg (sse_smode, op2, GET_MODE (op2)); - op1 = gen_rtx_fmt_e (code, sse_half_dmode, op1); - op2 = gen_rtx_fmt_e (code, sse_half_dmode, op2); - rtx insn = gen_rtx_SET (dest, gen_rtx_VEC_CONCAT (sse_dmode, - op1, op2)); - emit_insn (insn); + /* For packusdw/packuswb, it does unsigned saturation for + signed source which is different for rtl US_TRUNCATE. */ + if (code == US_TRUNCATE) + src = gen_rtx_UNSPEC (sse_dmode, + gen_rtvec (2, op1, op2), + UNSPEC_US_TRUNCATE); + else + { + op1 = gen_rtx_fmt_e (code, sse_half_dmode, op1); + op2 = gen_rtx_fmt_e (code, sse_half_dmode, op2); + src = gen_rtx_VEC_CONCAT (sse_dmode, op1, op2); + } + + emit_move_insn (dest, src); ix86_move_vector_high_sse_to_mmx (op0); } diff --git a/gcc/config/i386/i386.md b/gcc/config/i386/i386.md index 0929115ed4d..070a84d8af9 100644 --- a/gcc/config/i386/i386.md +++ b/gcc/config/i386/i386.md @@ -129,6 +129,10 @@ (define_c_enum "unspec" [ UNSPEC_RSQRT UNSPEC_PSADBW + ;; US_TRUNCATE this is different from rtl us_truncate, + ;; it does unsigned truncation for signed source. + UNSPEC_US_TRUNCATE + ;; For AVX/AVX512F support UNSPEC_SCALEF UNSPEC_PCMP diff --git a/gcc/config/i386/mmx.md b/gcc/config/i386/mmx.md index 6fbe3909c8b..315eb4193c4 100644 --- a/gcc/config/i386/mmx.md +++ b/gcc/config/i386/mmx.md @@ -3337,27 +3337,41 @@ (define_split ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -;; Used in signed and unsigned truncations with saturation. -(define_code_iterator any_s_truncate [ss_truncate us_truncate]) -;; Instruction suffix for truncations with saturation. -(define_code_attr s_trunsuffix [(ss_truncate "s") (us_truncate "u")]) - -(define_insn_and_split "mmx_packswb" +(define_insn_and_split "mmx_packsswb" [(set (match_operand:V8QI 0 "register_operand" "=y,x,Yw") (vec_concat:V8QI - (any_s_truncate:V4QI + (ss_truncate:V4QI (match_operand:V4HI 1 "register_operand" "0,0,Yw")) - (any_s_truncate:V4QI + (ss_truncate:V4QI (match_operand:V4HI 2 "register_mmxmem_operand" "ym,x,Yw"))))] "TARGET_MMX || TARGET_MMX_WITH_SSE" "@ - packswb\t{%2, %0|%0, %2} + packsswb\t{%2, %0|%0, %2} + # + #" + "&& reload_completed + && SSE_REGNO_P (REGNO (operands[0]))" + [(const_int 0)] + "ix86_split_mmx_pack (operands, SS_TRUNCATE); DONE;" + [(set_attr "mmx_isa" "native,sse_noavx,avx") + (set_attr "type" "mmxshft,sselog,sselog") + (set_attr "mode" "DI,TI,TI")]) + +(define_insn_and_split "mmx_packuswb" + [(set (match_operand:V8QI 0 "register_operand" "=y,x,Yw") + (unspec:V8QI + [(match_operand:V4HI 1 "register_operand" "0,0,Yw") + (match_operand:V4HI 2 "register_mmxmem_operand" "ym,x,Yw")] + UNSPEC_US_TRUNCATE))] + "TARGET_MMX || TARGET_MMX_WITH_SSE" + "@ + packuswb\t{%2, %0|%0, %2} # #" "&& reload_completed && SSE_REGNO_P (REGNO (operands[0]))" [(const_int 0)] - "ix86_split_mmx_pack (operands, ); DONE;" + "ix86_split_mmx_pack (operands, US_TRUNCATE); DONE;" [(set_attr "mmx_isa" "native,sse_noavx,avx") (set_attr "type" "mmxshft,sselog,sselog") (set_attr "mode" "DI,TI,TI")]) @@ -3384,11 +3398,10 @@ (define_insn_and_split "mmx_packssdw" (define_insn_and_split "mmx_packusdw" [(set (match_operand:V4HI 0 "register_operand" "=Yr,*x,Yw") - (vec_concat:V4HI - (us_truncate:V2HI - (match_operand:V2SI 1 "register_operand" "0,0,Yw")) - (us_truncate:V2HI - (match_operand:V2SI 2 "register_operand" "Yr,*x,Yw"))))] + (unspec:V4HI + [(match_operand:V2SI 1 "register_operand" "0,0,Yw") + (match_operand:V2SI 2 "register_operand" "Yr,*x,Yw")] + UNSPEC_US_TRUNCATE))] "TARGET_SSE4_1 && TARGET_MMX_WITH_SSE" "#" "&& reload_completed" diff --git a/gcc/config/i386/sse.md b/gcc/config/i386/sse.md index 7d4b4ec8df5..83e3f534fd2 100644 --- a/gcc/config/i386/sse.md +++ b/gcc/config/i386/sse.md @@ -17796,13 +17796,14 @@ (define_insn "_packssdw" (set_attr "prefix" "orig,") (set_attr "mode" "")]) +;; This is different from rtl unsigned saturation, the instruction does +;; unsigned saturation for signed value. (define_insn "_packuswb" [(set (match_operand:VI1_AVX512 0 "register_operand" "=x,") - (vec_concat:VI1_AVX512 - (us_truncate: - (match_operand: 1 "register_operand" "0,")) - (us_truncate: - (match_operand: 2 "vector_operand" "xBm,m"))))] + (unspec:VI1_AVX512 + [(match_operand: 1 "register_operand" "0,") + (match_operand: 2 "vector_operand" "xBm,m")] + UNSPEC_US_TRUNCATE))] "TARGET_SSE2 && && " "@ packuswb\t{%2, %0|%0, %2} @@ -21889,11 +21890,10 @@ (define_insn "_mpsadbw" (define_insn "_packusdw" [(set (match_operand:VI2_AVX2 0 "register_operand" "=Yr,*x,") - (vec_concat:VI2_AVX2 - (us_truncate: - (match_operand: 1 "register_operand" "0,0,")) - (us_truncate: - (match_operand: 2 "vector_operand" "YrBm,*xBm,m"))))] + (unspec:VI2_AVX2 + [(match_operand: 1 "register_operand" "0,0,") + (match_operand: 2 "vector_operand" "YrBm,*xBm,m")] + UNSPEC_US_TRUNCATE))] "TARGET_SSE4_1 && && " "@ packusdw\t{%2, %0|%0, %2}