From patchwork Tue May 11 23:35:35 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: 1477377 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=8.43.85.97; helo=sourceware.org; envelope-from=gcc-patches-bounces@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=VQcftBAu; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (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 4FfvSs0Qnyz9sW5 for ; Wed, 12 May 2021 09:36:29 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id A6E45388F020; Tue, 11 May 2021 23:35:51 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A6E45388F020 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1620776151; bh=i9lme9YuYayt6WZG7O3xFuhYC6Cn3yl2vJu2YREcx4Y=; h=To:Subject:Date:In-Reply-To:References:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=VQcftBAuANb64HQf2D+S0gj0Bt9fcn/kvDidyhYa5o+1A19kAJgPqRtlUtX55RL70 xUHuQTBNieMmOXvg6ucwmj7vlXrf6Mm2uGWGuMb8JyrH/9exd+9dDT/H0y6ugeyn/v R7lm28/rm2SzX6HuT6rgxAI8yyvL4F2d4DbLvK2o= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-pl1-x62c.google.com (mail-pl1-x62c.google.com [IPv6:2607:f8b0:4864:20::62c]) by sourceware.org (Postfix) with ESMTPS id BEE29388C022 for ; Tue, 11 May 2021 23:35:44 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org BEE29388C022 Received: by mail-pl1-x62c.google.com with SMTP id h20so11606755plr.4 for ; Tue, 11 May 2021 16:35:44 -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=i9lme9YuYayt6WZG7O3xFuhYC6Cn3yl2vJu2YREcx4Y=; b=VxxyOM8esXFO1G8qpqwF8660vVrMKPEAnWOQiVPO/Z2kuggwP2eJ68j091mRt3aeoc /ZLyLgwG3s8bAMn5wVkt5SFbU3xEUZDSi9cwczK/npl6ld1sVhs3A3k6ZEeqzZbdDWK0 3WldmRhHKPMjJnmxEm3BF1CD2vjadt0My+AniVjD5OqmDS6loRLq5FncHkkhw3GHoCK+ uL+VV8iUlzd8qKImXzQ06yFo8NA6rhpq3llUVq4GRbTbnBiiLSZ7RTlWdCSBPIUX9Cz+ pRjiCN1Ur4iJ7l8eiI0jxgEplUNv5Nzfk9Nkp18uSW6qFlJmQBiwVPi7JE86tV/OmgKW lV1Q== X-Gm-Message-State: AOAM530j9m9DtFSTdjtAWKVwfXousqvesr6zYVND2r84bw15tykEXbvW C+9P5E8gfzerLkCu30ncx18= X-Google-Smtp-Source: ABdhPJxG2pw9IWMASZ9NOXUBi0SWtOFUYx+ApQ/gWazjKYyV7S7oFBz+rzOJHvAYmdvnmPs3/035Dg== X-Received: by 2002:a17:90b:604:: with SMTP id gb4mr7759421pjb.178.1620776143904; Tue, 11 May 2021 16:35:43 -0700 (PDT) Received: from gnu-cfl-2.localdomain ([172.56.39.231]) by smtp.gmail.com with ESMTPSA id z7sm12485172pfb.93.2021.05.11.16.35.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 May 2021 16:35:43 -0700 (PDT) Received: from gnu-cfl-2.. (localhost [IPv6:::1]) by gnu-cfl-2.localdomain (Postfix) with ESMTP id AEDDDC055B; Tue, 11 May 2021 16:35:35 -0700 (PDT) To: gcc-patches@gcc.gnu.org Subject: [PATCH v2 11/11] constructor: Check if it is faster to load constant from memory Date: Tue, 11 May 2021 16:35:35 -0700 Message-Id: <20210511233535.4448-12-hjl.tools@gmail.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210511233535.4448-1-hjl.tools@gmail.com> References: <20210511233535.4448-1-hjl.tools@gmail.com> MIME-Version: 1.0 X-Spam-Status: No, score=-3035.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, 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-Patchwork-Original-From: "H.J. Lu via Gcc-patches" From: "H.J. Lu" Reply-To: "H.J. Lu" Cc: Richard Sandiford Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" When expanding a constant constructor, don't call expand_constructor if it is more efficient to load the data from the memory via move by pieces. gcc/ PR middle-end/90773 * expr.c (expand_expr_real_1): Don't call expand_constructor if it is more efficient to load the data from the memory. gcc/testsuite/ PR middle-end/90773 * gcc.target/i386/pr90773-24.c: New test. * gcc.target/i386/pr90773-25.c: Likewise. --- gcc/expr.c | 10 ++++++++++ gcc/testsuite/gcc.target/i386/pr90773-24.c | 22 ++++++++++++++++++++++ gcc/testsuite/gcc.target/i386/pr90773-25.c | 20 ++++++++++++++++++++ 3 files changed, 52 insertions(+) create mode 100644 gcc/testsuite/gcc.target/i386/pr90773-24.c create mode 100644 gcc/testsuite/gcc.target/i386/pr90773-25.c diff --git a/gcc/expr.c b/gcc/expr.c index 42ef5bdf5d5..6ad7265702e 100644 --- a/gcc/expr.c +++ b/gcc/expr.c @@ -10885,6 +10885,16 @@ expand_expr_real_1 (tree exp, rtx target, machine_mode tmode, unsigned HOST_WIDE_INT ix; tree field, value; + /* Check if it is more efficient to load the data from + the memory directly. FIXME: How many stores do we + need here if not moved by pieces? */ + unsigned HOST_WIDE_INT bytes + = tree_to_uhwi (TYPE_SIZE_UNIT (type)); + if ((bytes / UNITS_PER_WORD) > 2 + && MOVE_MAX_PIECES > UNITS_PER_WORD + && can_move_by_pieces (bytes, TYPE_ALIGN (type))) + goto normal_inner_ref; + FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (init), ix, field, value) if (tree_int_cst_equal (field, index)) diff --git a/gcc/testsuite/gcc.target/i386/pr90773-24.c b/gcc/testsuite/gcc.target/i386/pr90773-24.c new file mode 100644 index 00000000000..4a4b62533dc --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/pr90773-24.c @@ -0,0 +1,22 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -march=x86-64" } */ + +struct S +{ + long long s1 __attribute__ ((aligned (8))); + unsigned s2, s3, s4, s5, s6, s7, s8, s9, s10, s11, s12, s13, s14; +}; + +const struct S array[] = { + { 0, 60, 640, 2112543726, 39682, 48, 16, 33, 10, 96, 2, 0, 0, 4 } +}; + +void +foo (struct S *x) +{ + x[0] = array[0]; +} +/* { dg-final { scan-assembler-times "movups\[\\t \]%xmm\[0-9\]+, \\(%\[\^,\]+\\)" 1 } } */ +/* { dg-final { scan-assembler-times "movups\[\\t \]%xmm\[0-9\]+, 16\\(%\[\^,\]+\\)" 1 } } */ +/* { dg-final { scan-assembler-times "movups\[\\t \]%xmm\[0-9\]+, 32\\(%\[\^,\]+\\)" 1 } } */ +/* { dg-final { scan-assembler-times "movups\[\\t \]%xmm\[0-9\]+, 48\\(%\[\^,\]+\\)" 1 } } */ diff --git a/gcc/testsuite/gcc.target/i386/pr90773-25.c b/gcc/testsuite/gcc.target/i386/pr90773-25.c new file mode 100644 index 00000000000..2520b670989 --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/pr90773-25.c @@ -0,0 +1,20 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -march=skylake" } */ + +struct S +{ + long long s1 __attribute__ ((aligned (8))); + unsigned s2, s3, s4, s5, s6, s7, s8, s9, s10, s11, s12, s13, s14; +}; + +const struct S array[] = { + { 0, 60, 640, 2112543726, 39682, 48, 16, 33, 10, 96, 2, 0, 0, 4 } +}; + +void +foo (struct S *x) +{ + x[0] = array[0]; +} +/* { dg-final { scan-assembler-times "vmovdqu\[\\t \]%ymm\[0-9\]+, \\(%\[\^,\]+\\)" 1 } } */ +/* { dg-final { scan-assembler-times "vmovdqu\[\\t \]%ymm\[0-9\]+, 32\\(%\[\^,\]+\\)" 1 } } */