From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pf1-x42a.google.com (mail-pf1-x42a.google.com [IPv6:2607:f8b0:4864:20::42a]) by sourceware.org (Postfix) with ESMTPS id E48053858005 for ; Mon, 28 Jun 2021 22:16:38 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org E48053858005 Received: by mail-pf1-x42a.google.com with SMTP id c8so15437697pfp.5 for ; Mon, 28 Jun 2021 15:16:38 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=6iwBbed/OvHb3Z2v/Z1CnOHkLxJaQq5wcIrJzqgN/MA=; b=cHLS6CScS6PRAtTjnnU4skdM7eB0zJxXEHMUrRsDWTsZHpb7caD5pE8oN8TZvQDwB4 W6Ja6eqGJtnFRQ9kF88HlLZ/F5y0GkmhW7k0dtzB3H/p3wP47zPyq/wYCfXwmO6Mx3Vg GeQ+PplAZiQHYI4eh5mKpbp7qLXUvbwSXqu01ncLSwf6uBhNm8icJ6WSO2BizQ7Gz4Fn 0O+PdCtlWLTl2U4a0izY1GtE3uCfCTIcsiLFqoL2qAmzb+C1G+ZXhsiWDgrbQbuSk4XO sOEovip7iY231aFsLlc5M0/Y5P16D9uHRQfKtXFysBkajS+UHvFbTRRtBM8hnz9NV9pB uHFw== X-Gm-Message-State: AOAM5308/FzmdsF7tCx7y2pRMyYTGQuzTv2xhu+3oAwkPpRBw7j1Fino xmGrVdxG5OsPuXFVmI0NyvA= X-Google-Smtp-Source: ABdhPJzE+klRTJzP+nckfTvK1kZaqaktaOHNsRrLZKYlIjzbV/fj9HLNN1D41RAIJB3B0mibDZAO7A== X-Received: by 2002:a63:2313:: with SMTP id j19mr25028898pgj.42.1624918597948; Mon, 28 Jun 2021 15:16:37 -0700 (PDT) Received: from gnu-cfl-2.localdomain ([172.56.39.115]) by smtp.gmail.com with ESMTPSA id h1sm565668pji.14.2021.06.28.15.16.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Jun 2021 15:16:37 -0700 (PDT) Received: from gnu-tgl-2.localdomain (gnu-tgl-2 [192.168.1.34]) by gnu-cfl-2.localdomain (Postfix) with ESMTPS id 3226CC0305; Mon, 28 Jun 2021 15:16:36 -0700 (PDT) Received: from gnu-tgl-2.lan (localhost [IPv6:::1]) by gnu-tgl-2.localdomain (Postfix) with ESMTP id 0EB9C30047D; Mon, 28 Jun 2021 15:16:26 -0700 (PDT) From: "H.J. Lu" To: gcc-patches@gcc.gnu.org Cc: Uros Bizjak , Jakub Jelinek , Hongtao Liu , Richard Sandiford , Richard Biener Subject: [PATCH v6 2/2] x86: Add vec_duplicate expander Date: Mon, 28 Jun 2021 15:16:25 -0700 Message-Id: <20210628221625.109189-3-hjl.tools@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210628221625.109189-1-hjl.tools@gmail.com> References: <20210628221625.109189-1-hjl.tools@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-3032.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_BARRACUDACENTRAL, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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-List-Received-Date: Mon, 28 Jun 2021 22:16:40 -0000 Add vec_duplicate expander for SSE2 if we can move from GPR to SSE register directly. * config/i386/i386-expand.c (ix86_expand_vector_init_duplicate): Make it global. * config/i386/i386-protos.h (ix86_expand_vector_init_duplicate): New prototype. * config/i386/sse.md (INT_BROADCAST_MODE): New mode iterator. (vec_duplicate): New expander. --- gcc/config/i386/i386-expand.c | 5 +---- gcc/config/i386/i386-protos.h | 2 ++ gcc/config/i386/sse.md | 31 +++++++++++++++++++++++++++++++ 3 files changed, 34 insertions(+), 4 deletions(-) diff --git a/gcc/config/i386/i386-expand.c b/gcc/config/i386/i386-expand.c index e0e3ed4d8a4..e04019c4b79 100644 --- a/gcc/config/i386/i386-expand.c +++ b/gcc/config/i386/i386-expand.c @@ -93,9 +93,6 @@ along with GCC; see the file COPYING3. If not see #include "i386-builtins.h" #include "i386-expand.h" -static bool ix86_expand_vector_init_duplicate (bool, machine_mode, rtx, - rtx); - /* Split one or more double-mode RTL references into pairs of half-mode references. The RTL can be REG, offsettable MEM, integer constant, or CONST_DOUBLE. "operands" is a pointer to an array of double-mode RTLs to @@ -13909,7 +13906,7 @@ static bool expand_vec_perm_1 (struct expand_vec_perm_d *d); /* A subroutine of ix86_expand_vector_init. Store into TARGET a vector with all elements equal to VAR. Return true if successful. */ -static bool +bool ix86_expand_vector_init_duplicate (bool mmx_ok, machine_mode mode, rtx target, rtx val) { diff --git a/gcc/config/i386/i386-protos.h b/gcc/config/i386/i386-protos.h index 71745b9a1ea..51376fcc454 100644 --- a/gcc/config/i386/i386-protos.h +++ b/gcc/config/i386/i386-protos.h @@ -258,6 +258,8 @@ extern void ix86_expand_mul_widen_hilo (rtx, rtx, rtx, bool, bool); extern void ix86_expand_sse2_mulv4si3 (rtx, rtx, rtx); extern void ix86_expand_sse2_mulvxdi3 (rtx, rtx, rtx); extern void ix86_expand_sse2_abs (rtx, rtx); +extern bool ix86_expand_vector_init_duplicate (bool, machine_mode, rtx, + rtx); /* In i386-c.c */ extern void ix86_target_macros (void); diff --git a/gcc/config/i386/sse.md b/gcc/config/i386/sse.md index ffcc0c81964..5ededaedac7 100644 --- a/gcc/config/i386/sse.md +++ b/gcc/config/i386/sse.md @@ -24814,3 +24814,34 @@ (define_insn "*aesu8" "TARGET_WIDEKL" "aes\t{%0}" [(set_attr "type" "other")]) + +;; Modes handled by broadcast patterns. NB: Allow V64QI and V32HI with +;; TARGET_AVX512F since ix86_expand_vector_init_duplicate can expand +;; without TARGET_AVX512BW which is used by memset vector broadcast +;; expander to XI with: +;; vmovd %edi, %xmm15 +;; vpbroadcastb %xmm15, %ymm15 +;; vinserti64x4 $0x1, %ymm15, %zmm15, %zmm15 + +(define_mode_iterator INT_BROADCAST_MODE + [(V64QI "TARGET_AVX512F") (V32QI "TARGET_AVX") V16QI + (V32HI "TARGET_AVX512F") (V16HI "TARGET_AVX") V8HI + (V16SI "TARGET_AVX512F") (V8SI "TARGET_AVX") V4SI + (V8DI "TARGET_AVX512F && TARGET_64BIT") + (V4DI "TARGET_AVX && TARGET_64BIT") (V2DI "TARGET_64BIT")]) + +;; Broadcast from an integer. NB: Enable broadcast only if we can move +;; from GPR to SSE register directly. +(define_expand "vec_duplicate" + [(set (match_operand:INT_BROADCAST_MODE 0 "register_operand") + (vec_duplicate:INT_BROADCAST_MODE + (match_operand: 1 "nonimmediate_operand")))] + "TARGET_SSE2 && TARGET_INTER_UNIT_MOVES_TO_VEC" +{ + if (!ix86_expand_vector_init_duplicate (false, + GET_MODE (operands[0]), + operands[0], + operands[1])) + gcc_unreachable (); + DONE; +}) -- 2.31.1