From patchwork Thu Jul 22 12:31:39 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "H.J. Lu" X-Patchwork-Id: 1508693 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=Ly7TM1qh; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4GVsN13hmFz9sXJ for ; Thu, 22 Jul 2021 22:34:41 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id F40153839437 for ; Thu, 22 Jul 2021 12:34:38 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org F40153839437 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1626957279; bh=bBdl23UvVjqd1wAWn2GYbl6sb+06eVhidjRWHW3gL/U=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=Ly7TM1qhF559nwdBR78aTn2v05Gjr13Arqawhs2TY6e0bPD7IzAAY0V+biLqRm0sZ F8dxefoKDMI9CMUfQXJUP63DrV3KuD4RqW13Lar/o6ot8CzDTaRomoIL384r/gqp32 MNXVXuGEigMd3mtmkc8stye0ACXWd4aI9+fnf+Po= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-pj1-x102c.google.com (mail-pj1-x102c.google.com [IPv6:2607:f8b0:4864:20::102c]) by sourceware.org (Postfix) with ESMTPS id E3EEA3839416 for ; Thu, 22 Jul 2021 12:31:52 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org E3EEA3839416 Received: by mail-pj1-x102c.google.com with SMTP id nt18-20020a17090b2492b02901765d605e14so4311391pjb.5 for ; Thu, 22 Jul 2021 05:31:52 -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:mime-version :content-transfer-encoding; bh=bBdl23UvVjqd1wAWn2GYbl6sb+06eVhidjRWHW3gL/U=; b=ILrp6CIFrZ1WsRCAwaZhjpxkWaR4ybIxI/BJC6o3Im5JWz/uF1isBbIjdZdRfUizYJ EaX+lw8b/P3biRBntrtoBL6ETL3OO3whirp1YSDXfV37EWxy1ij4ReqDLsCODEalz/J8 YBPH5UgSfYTbLkXBQm/q68rBAHHgKT4VtmSt6zWutwOCycOjkWcXpJiKgP6DgamAt2Ai qnPR+9kUGMwPJt99/K3x9aHh5wp0zxTVaEb+ars4+v6G/iRkmOpeV2ALwbv8x5LO+BbL zN9pjiw1L/l8PaERMw/Fy4ErGKkoVqB7xQJWEQZEVn/r46d9m3fFxk4c/8HYxCkaD5ZM qvNw== X-Gm-Message-State: AOAM531RW1EMzWdGOIh4AGTF6Hz/+HGDlVrst2wxnN7KIWGh5Bv6iaev 3HXqqJ5Fsa/4F49J69kMwlLjx9TyypE= X-Google-Smtp-Source: ABdhPJyMoPUlp/MYr3Gy753WAzfueLJJhkUDjJII1H1ButXSN+Yhv7Uatjt4LYVTU6OOByQZz+n+Cg== X-Received: by 2002:a17:90a:c092:: with SMTP id o18mr8722879pjs.3.1626957111883; Thu, 22 Jul 2021 05:31:51 -0700 (PDT) Received: from gnu-cfl-2.localdomain ([172.58.38.240]) by smtp.gmail.com with ESMTPSA id t17sm30583494pfg.93.2021.07.22.05.31.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Jul 2021 05:31:51 -0700 (PDT) Received: from gnu-tgl-2.localdomain (gnu-tgl-2 [192.168.1.34]) by gnu-cfl-2.localdomain (Postfix) with ESMTPS id 450B8C02C7; Thu, 22 Jul 2021 05:31:50 -0700 (PDT) Received: from gnu-tgl-2.lan (localhost [IPv6:::1]) by gnu-tgl-2.localdomain (Postfix) with ESMTP id 0E5493004FA; Thu, 22 Jul 2021 05:31:40 -0700 (PDT) To: gcc-patches@gcc.gnu.org Subject: [PATCH] x86: Convert load from constand pool to SSE constant load Date: Thu, 22 Jul 2021 05:31:39 -0700 Message-Id: <20210722123139.1529202-1-hjl.tools@gmail.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 X-Spam-Status: No, score=-3033.3 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, SCC_5_SHORT_WORD_LINES, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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: "H.J. Lu via Gcc-patches" From: "H.J. Lu" Reply-To: "H.J. Lu" Cc: liuhongt Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" For (set (reg:V32QI 108) (const_vector:V32QI [ (const_int -1 [0xffffffffffffffff]) repeated x32 ])) "x.c":15:5 1573 {movv32qi_internal} (expr_list:REG_EQUIV (const_vector:V32QI [ (const_int -1 [0xffffffffffffffff]) repeated x32 ]) (nil)) LRA may generate #6 0x0000000001077c8a in lra_emit_move (x=0x7ffff7f81b58, y=0x7ffff7f81b40) at /export/gnu/import/git/gitlab/x86-gcc/gcc/lra.c:502 502 ? emit_move_insn (x, y) : emit_insn (gen_rtx_SET (x, y))); (gdb) call debug_rtx (x) (reg:V32QI 326) (gdb) call debug_rtx (y) (mem/u/c:V32QI (symbol_ref/u:DI ("*.LC0") [flags 0x2]) [0 S32 A256]) (gdb) Convert load from constand pool to SSE constant load: (set (reg:V32QI 24 xmm4 [327]) (const_vector:V32QI [ (const_int -1 [0xffffffffffffffff]) repeated x32 ])) "x.c":15:5 1573 {movv32qi_internal} gcc/ PR target/101504 * config/i386/i386-expand.c (ix86_broadcast_from_constant): Return the standard SSE constant. (ix86_expand_vector_move): Handle standard SSE constants. gcc/testsuite/ PR target/101504 * gcc.target/i386/pr101504.c: New test. --- gcc/config/i386/i386-expand.c | 11 +++++++++++ gcc/testsuite/gcc.target/i386/pr101504.c | 23 +++++++++++++++++++++++ 2 files changed, 34 insertions(+) create mode 100644 gcc/testsuite/gcc.target/i386/pr101504.c diff --git a/gcc/config/i386/i386-expand.c b/gcc/config/i386/i386-expand.c index 896bd685b1f..7b6055bbf83 100644 --- a/gcc/config/i386/i386-expand.c +++ b/gcc/config/i386/i386-expand.c @@ -493,6 +493,10 @@ ix86_broadcast_from_constant (machine_mode mode, rtx op) if (GET_CODE (constant) != CONST_VECTOR) return nullptr; + /* Return the standard SSE constant. */ + if (standard_sse_constant_p (constant, mode)) + return constant; + /* There could be some rtx like (mem/u/c:V16QI (symbol_ref/u:DI ("*.LC1"))) but with "*.LC1" refer to V2DI constant vector. */ @@ -577,6 +581,13 @@ ix86_expand_vector_move (machine_mode mode, rtx operands[]) rtx first = ix86_broadcast_from_constant (mode, op1); if (first != nullptr) { + if (GET_CODE (first) == CONST_VECTOR) + { + /* This is a standard SSE constant. */ + emit_move_insn (op0, first); + return; + } + /* Broadcast to XMM/YMM/ZMM register from an integer constant or scalar mem. */ /* Hard registers are used for 2 purposes: diff --git a/gcc/testsuite/gcc.target/i386/pr101504.c b/gcc/testsuite/gcc.target/i386/pr101504.c new file mode 100644 index 00000000000..2ad0405dd7b --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/pr101504.c @@ -0,0 +1,23 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -march=skylake" } */ + +typedef unsigned int __attribute__((__vector_size__ (32))) U; +typedef unsigned char __attribute__((__vector_size__ (64))) V; + +V g; + +U +foo (void) +{ + V v = __builtin_shufflevector (g, g, + 0, 1, 2, 0, 5, 1, 0, 1, 3, 2, 3, 0, 4, 3, 1, 2, + 2, 0, 4, 2, 3, 1, 1, 2, 3, 4, 1, 1, 0, 0, 5, 2, + 0, 3, 3, 3, 3, 4, 5, 0, 1, 5, 2, 1, 0, 1, 1, 2, + 3, 2, 0, 5, 4, 5, 1, 0, 1, 4, 4, 3, 4, 5, 2, 0); + v ^= 255; + V w = v + g; + U u = ((union { V a; U b; }) w).b + ((union { V a; U b; }) w).b[1]; + return u; +} + +/* { dg-final { scan-assembler-not "\.byte\[ \t\]+-1\n" } } */