From patchwork Tue May 11 23:35:26 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: 1477367 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=GKNKnmKV; 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 4FfvS14jjmz9sW5 for ; Wed, 12 May 2021 09:35:44 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id CCCBF3838035; Tue, 11 May 2021 23:35:40 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org CCCBF3838035 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1620776140; bh=asnqS8i5w0qQfLqbRzQGVoAdT8zSay9KUEAeeOfxJFs=; 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=GKNKnmKV+vYYW2EX7ynVV1Hop4Gho8rfODbVckhJaXbLQzPotTwqLA/AhS//V1Bd7 VwfPsx66x79AJFOC3/mufNvNEjW8Expn0J2/SkW3Fzq5AnP2z68Oy3quZ1C9fyi7Tp FLppvmvNCXQ18HotJPoGt0UXVNBzQcFPSAWSq1yw= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-pg1-x536.google.com (mail-pg1-x536.google.com [IPv6:2607:f8b0:4864:20::536]) by sourceware.org (Postfix) with ESMTPS id 1982F3854801 for ; Tue, 11 May 2021 23:35:39 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 1982F3854801 Received: by mail-pg1-x536.google.com with SMTP id m37so16868430pgb.8 for ; Tue, 11 May 2021 16:35:39 -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=asnqS8i5w0qQfLqbRzQGVoAdT8zSay9KUEAeeOfxJFs=; b=FxNwkZOn8YRTdmEiV5rvMyLjPPPlKZGKU7k3UWjmVgkd2pPNatZfThfmwGXzkCp2SG Af0pD24poMAww4kGVdGFICSYo5NSECyhG5del1AUl1r0QCHTnmSuFoDYDXtQuiehd5tW FKxhiGpN7tHqG3kIw7CczgXreViUT8I54ON/frnt6/55EPmmcZnLw9fm9wkPXjufbNxZ lIxjm9rCpyuuUT2QB9mCsR40AHEiHw7CX9eRZNEdgkz+Dn+2etjSGCwh1MSk6ANnb9fb px+YlZFj6HeW08GOmBCB842dONJ4+rLkPokDSpqed5HNSR/epTsOryQidT+6/00FpsM+ q6iQ== X-Gm-Message-State: AOAM5307Z26I5X9azC0eeJmmUOqHS6hBXcyvwcqCBX5es42hLTeXIcBJ BwdSoug0ui2Q8AVt1X9JeoI= X-Google-Smtp-Source: ABdhPJyrr1ytN3j4KwAD+ZeaMyHCMZ+OM6Ts7QGstJMsiYRYN73+3wubh9FHPRlTxHQB5Kzg66ft6A== X-Received: by 2002:a63:b10:: with SMTP id 16mr34299171pgl.90.1620776138153; Tue, 11 May 2021 16:35:38 -0700 (PDT) Received: from gnu-cfl-2.localdomain ([172.56.39.231]) by smtp.gmail.com with ESMTPSA id x27sm15122968pfo.216.2021.05.11.16.35.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 11 May 2021 16:35:37 -0700 (PDT) Received: from gnu-cfl-2.. (localhost [IPv6:::1]) by gnu-cfl-2.localdomain (Postfix) with ESMTP id 65495C04A2; Tue, 11 May 2021 16:35:35 -0700 (PDT) To: gcc-patches@gcc.gnu.org Subject: [PATCH v2 02/11] x86: Avoid stack realignment when copying data Date: Tue, 11 May 2021 16:35:26 -0700 Message-Id: <20210511233535.4448-3-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" To avoid stack realignment, use SCRATCH_SSE_REG to copy data from one memory location to another. gcc/ * config/i386/i386-expand.c (ix86_expand_vector_move): Use SCRATCH_SSE_REG to copy data from one memory location to another. gcc/testsuite/ * gcc.target/i386/eh_return-1.c: New test. --- gcc/config/i386/i386-expand.c | 16 ++++++++++++- gcc/testsuite/gcc.target/i386/eh_return-1.c | 26 +++++++++++++++++++++ 2 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/gcc.target/i386/eh_return-1.c diff --git a/gcc/config/i386/i386-expand.c b/gcc/config/i386/i386-expand.c index 7f1dff6337c..09d5e5d88af 100644 --- a/gcc/config/i386/i386-expand.c +++ b/gcc/config/i386/i386-expand.c @@ -431,7 +431,21 @@ ix86_expand_vector_move (machine_mode mode, rtx operands[]) && !register_operand (op0, mode) && !register_operand (op1, mode)) { - emit_move_insn (op0, force_reg (GET_MODE (op0), op1)); + rtx tmp; + mode = GET_MODE (op0); + if (TARGET_SSE + && (GET_MODE_ALIGNMENT (mode) + > ix86_minimum_incoming_stack_boundary (false, true))) + { + /* NB: Don't increase stack alignment requirement by using + a scratch SSE register to copy data from one memory + location to another since it doesn't require a spill. */ + tmp = gen_rtx_REG (mode, SCRATCH_SSE_REG); + emit_move_insn (tmp, op1); + } + else + tmp = force_reg (mode, op1); + emit_move_insn (op0, tmp); return; } diff --git a/gcc/testsuite/gcc.target/i386/eh_return-1.c b/gcc/testsuite/gcc.target/i386/eh_return-1.c new file mode 100644 index 00000000000..671ba635e88 --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/eh_return-1.c @@ -0,0 +1,26 @@ +/* { dg-do compile } */ +/* { dg-options "-O2 -march=haswell -mno-avx512f" } */ + +struct _Unwind_Context +{ + void *ra; + char array[48]; +}; + +extern long uw_install_context_1 (struct _Unwind_Context *); + +void +_Unwind_RaiseException (void) +{ + struct _Unwind_Context this_context, cur_context; + long offset = uw_install_context_1 (&this_context); + __builtin_memcpy (&this_context, &cur_context, + sizeof (struct _Unwind_Context)); + void *handler = __builtin_frob_return_addr ((&cur_context)->ra); + uw_install_context_1 (&cur_context); + __builtin_eh_return (offset, handler); +} + +/* { dg-final { scan-assembler-times "vmovdqu\[ \\t\]+\[^\n\]*%ymm" 4 } } */ +/* No need to dynamically realign the stack here. */ +/* { dg-final { scan-assembler-not "and\[^\n\r]*%\[re\]sp" } } */