From patchwork Mon Jul 18 01:59:35 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Li, Pan2 via Gcc-patches" X-Patchwork-Id: 31 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a98:d5ce:0:b0:178:cc93:bf7d with SMTP id g14csp1614796eik; Sun, 17 Jul 2022 19:00:31 -0700 (PDT) X-Google-Smtp-Source: AGRyM1u4yQVx6lfg1Cj5qEMjM2d3HRMUgpSQOV9MEEj1286h1ZLACKEz0cWNH7zEaq/BiSpafGNk X-Received: by 2002:a05:6402:501d:b0:437:e000:a898 with SMTP id p29-20020a056402501d00b00437e000a898mr35009989eda.265.1658109631170; Sun, 17 Jul 2022 19:00:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658109631; cv=none; d=google.com; s=arc-20160816; b=RUJoh6zy51LB21T8cgvBFcB6vkdGH4WLChsC+ZP+4mOq8IyigIX2JWoCRrxBJU6EZ7 p7pL1JXXmIoURqROT+rKhwCg/Qq+fdtmtj2blRDpkWBmavuB1O2xzMMFciecbCb1QTOn G7OEGN7SHILw5vIZSpxVHy8Jfvk99TIX4p77BZ+GnwKrhi9RxZXNrNQrWXRS14dTcSfy 5zJjMCoxgEfoqvW90lUMasCIi7AB5Nq9jeP8KzqpDl7KAbtOiqzwwBpt+2XIjIXpICYD 03EzWs9rCvoyov5fp505J9UasG3hwk8Ykse5enBmLehMdMS5+NAthP1yi2hdwPrYW2kn 13Zg== 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:references :in-reply-to:message-id:date:subject:to:dmarc-filter:delivered-to :dkim-signature:dkim-filter; bh=av4P+00hExI/T609vFfA1zIFVkZtl1c7cvO1czHNRYU=; b=nX9KuoXE737/AEr43/iO4de7mhAC2PVHevkk/tFAdtoIaTW42958MYcftcxEIQ5Dyt UNGMnRaEiKky80hkoFSznJOAKsGCa14GVyh//lIaS9M+IKpBVOfvCMsDev0/EIk0vl2s F5pFl3sp2C79N7sTFy2uuRJK5muhK9K28jM4XnEDouO12Y766jlENlDJUlxtRioDPxOy 3m3I8Qpb5P+/skFLjBMJvm/KWl8TEVcumbjtK3GTycBeEfbuDFUpJC8i9l3DwAuMcP9L ldHTJnVdfKLrQgs9Ahdb3JoSogusEUSgKvAFK2mfG9Nxpbw0Eh0sTLsspz254phN4asQ OY0A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=wjzetmSw; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c 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 (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id sa10-20020a1709076d0a00b0072b9ef49142si15861255ejc.571.2022.07.17.19.00.31 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 17 Jul 2022 19:00:31 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=wjzetmSw; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c 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 F267C385840F for ; Mon, 18 Jul 2022 02:00:29 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org F267C385840F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1658109630; bh=av4P+00hExI/T609vFfA1zIFVkZtl1c7cvO1czHNRYU=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=wjzetmSwukPju7bB66BanUNoOTpajLNz57ck9s87ZuNFf9N5Veauo0Hsee483aM1m XwhXvLGluy7sbG4/eHrSWSTjDFi3nO1xaIStvTN3UNTjuHDsZm3NomBx1gGd5k+ZKi KLvATFx5ZC2tZ2+DjfEBfQUpwEzHM/r7V4Rxs3zA= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) by sourceware.org (Postfix) with ESMTPS id 567CE3858407 for ; Mon, 18 Jul 2022 01:59:46 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 567CE3858407 X-IronPort-AV: E=McAfee;i="6400,9594,10411"; a="266516380" X-IronPort-AV: E=Sophos;i="5.92,280,1650956400"; d="scan'208";a="266516380" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Jul 2022 18:59:37 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.92,280,1650956400"; d="scan'208";a="739290201" Received: from shvmail03.sh.intel.com ([10.239.245.20]) by fmsmga001.fm.intel.com with ESMTP; 17 Jul 2022 18:59:35 -0700 Received: from shliclel320.sh.intel.com (shliclel320.sh.intel.com [10.239.240.127]) by shvmail03.sh.intel.com (Postfix) with ESMTP id 1050610056AC; Mon, 18 Jul 2022 09:59:35 +0800 (CST) To: gcc-patches@gcc.gnu.org Subject: [PATCH] Extend 16/32-bit vector bit_op patterns with (m, 0, i)(vertical) alternative. Date: Mon, 18 Jul 2022 09:59:35 +0800 Message-Id: <20220718015935.66003-1-hongtao.liu@intel.com> X-Mailer: git-send-email 2.18.1 In-Reply-To: References: X-Spam-Status: No, score=-12.5 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 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: "Li, Pan2 via Gcc-patches" 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?1738653964518631814?= X-GMAIL-MSGID: =?utf-8?q?1738653964518631814?= And split it after reload. >IMO, the only case it is worth adding is a direct immediate store to >memory, which HJ recently added. Bootstrapped and regtested on x86_64-pc-linux-gnu{-m32,}. Ok for trunk? gcc/ChangeLog: PR target/106038 * config/i386/mmx.md (3): Extend to AND mem,imm, and adjust below define_split. (mmxinsnmode): New mode attribute. (*mov_imm): Refactor with mmxinsnmode. * config/i386/predicates.md (register_or_x86_64_const_vector_operand): New predicate. gcc/testsuite/ChangeLog: * gcc.target/i386/pr106038-1.c: New test. --- gcc/config/i386/mmx.md | 58 +++++++++++----------- gcc/config/i386/predicates.md | 4 ++ gcc/testsuite/gcc.target/i386/pr106038-1.c | 27 ++++++++++ 3 files changed, 60 insertions(+), 29 deletions(-) create mode 100644 gcc/testsuite/gcc.target/i386/pr106038-1.c diff --git a/gcc/config/i386/mmx.md b/gcc/config/i386/mmx.md index 3294c1e6274..fbcb34d4395 100644 --- a/gcc/config/i386/mmx.md +++ b/gcc/config/i386/mmx.md @@ -86,6 +86,14 @@ (define_mode_attr mmxvecsize [(V8QI "b") (V4QI "b") (V2QI "b") (V4HI "w") (V2HI "w") (V2SI "d") (V1DI "q")]) +;; Mapping to same size integral mode. +(define_mode_attr mmxinsnmode + [(V8QI "DI") (V4QI "SI") (V2QI "HI") + (V4HI "DI") (V2HI "SI") + (V2SI "DI") + (V4HF "DI") (V2HF "SI") + (V2SF "DI")]) + (define_mode_attr mmxdoublemode [(V8QI "V8HI") (V4HI "V4SI")]) @@ -350,22 +358,7 @@ (define_insn_and_split "*mov_imm" HOST_WIDE_INT val = ix86_convert_const_vector_to_integer (operands[1], mode); operands[1] = GEN_INT (val); - machine_mode mode; - switch (GET_MODE_SIZE (mode)) - { - case 2: - mode = HImode; - break; - case 4: - mode = SImode; - break; - case 8: - mode = DImode; - break; - default: - gcc_unreachable (); - } - operands[0] = lowpart_subreg (mode, operands[0], mode); + operands[0] = lowpart_subreg (mode, operands[0], mode); }) ;; For TARGET_64BIT we always round up to 8 bytes. @@ -2975,32 +2968,39 @@ (define_insn "*mmx_3" (set_attr "mode" "DI,TI,TI,TI")]) (define_insn "3" - [(set (match_operand:VI_16_32 0 "register_operand" "=?r,x,x,v") + [(set (match_operand:VI_16_32 0 "nonimmediate_operand" "=?r,m,x,x,v") (any_logic:VI_16_32 - (match_operand:VI_16_32 1 "register_operand" "%0,0,x,v") - (match_operand:VI_16_32 2 "register_operand" "r,x,x,v"))) + (match_operand:VI_16_32 1 "nonimmediate_operand" "%0,0,0,x,v") + (match_operand:VI_16_32 2 "register_or_x86_64_const_vector_operand" "r,i,x,x,v"))) (clobber (reg:CC FLAGS_REG))] "" "#" - [(set_attr "isa" "*,sse2_noavx,avx,avx512vl") - (set_attr "type" "alu,sselog,sselog,sselog") - (set_attr "mode" "SI,TI,TI,TI")]) + [(set_attr "isa" "*,*,sse2_noavx,avx,avx512vl") + (set_attr "type" "alu,alu,sselog,sselog,sselog") + (set_attr "mode" "SI,SI,TI,TI,TI")]) (define_split - [(set (match_operand:VI_16_32 0 "general_reg_operand") + [(set (match_operand:VI_16_32 0 "nonimmediate_gr_operand") (any_logic:VI_16_32 - (match_operand:VI_16_32 1 "general_reg_operand") - (match_operand:VI_16_32 2 "general_reg_operand"))) + (match_operand:VI_16_32 1 "nonimmediate_gr_operand") + (match_operand:VI_16_32 2 "register_or_x86_64_const_vector_operand"))) (clobber (reg:CC FLAGS_REG))] "reload_completed" [(parallel [(set (match_dup 0) - (any_logic:SI (match_dup 1) (match_dup 2))) + (any_logic: (match_dup 1) (match_dup 2))) (clobber (reg:CC FLAGS_REG))])] { - operands[2] = lowpart_subreg (SImode, operands[2], mode); - operands[1] = lowpart_subreg (SImode, operands[1], mode); - operands[0] = lowpart_subreg (SImode, operands[0], mode); + if (GET_CODE (operands[2]) == CONST_VECTOR) + { + HOST_WIDE_INT val = ix86_convert_const_vector_to_integer (operands[2], + mode); + operands[2] = GEN_INT (val); + } + else + operands[2] = lowpart_subreg (mode, operands[2], mode); + operands[1] = lowpart_subreg (mode, operands[1], mode); + operands[0] = lowpart_subreg (mode, operands[0], mode); }) (define_split diff --git a/gcc/config/i386/predicates.md b/gcc/config/i386/predicates.md index c71c453cceb..5f63a7d52f5 100644 --- a/gcc/config/i386/predicates.md +++ b/gcc/config/i386/predicates.md @@ -1205,6 +1205,10 @@ (define_predicate "x86_64_const_vector_operand" return trunc_int_for_mode (val, SImode) == val; }) +(define_predicate "register_or_x86_64_const_vector_operand" + (ior (match_operand 0 "register_operand") + (match_operand 0 "x86_64_const_vector_operand"))) + ;; Return true when OP is nonimmediate or standard SSE constant. (define_predicate "nonimmediate_or_sse_const_operand" (ior (match_operand 0 "nonimmediate_operand") diff --git a/gcc/testsuite/gcc.target/i386/pr106038-1.c b/gcc/testsuite/gcc.target/i386/pr106038-1.c new file mode 100644 index 00000000000..bb52385c8a5 --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/pr106038-1.c @@ -0,0 +1,27 @@ +/* { dg-do compile } */ +/* { dg-options "-msse2 -O2" } */ +/* { dg-final { scan-assembler-not "xmm" } } */ + +void +foo3 (char* a, char* __restrict b) +{ + a[0] &= 1; + a[1] &= 2; + a[2] &= 3; + a[3] &= 3; +} + +void +foo4 (char* a, char* __restrict b) +{ + a[0] &= 1; + a[1] &= 2; +} + + +void +foo1 (short* a, short* __restrict b) +{ + a[0] &= 1; + a[1] &= 2; +}