From patchwork Tue Feb 13 21:32:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "H.J. Lu" X-Patchwork-Id: 1898521 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=JH3z67zO; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; helo=server2.sourceware.org; envelope-from=gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.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 ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4TZF1P2YnMz23j4 for ; Wed, 14 Feb 2024 08:33:12 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 142F23857B9A for ; Tue, 13 Feb 2024 21:33:09 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-pg1-x52e.google.com (mail-pg1-x52e.google.com [IPv6:2607:f8b0:4864:20::52e]) by sourceware.org (Postfix) with ESMTPS id AF08E3857C66 for ; Tue, 13 Feb 2024 21:32:47 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org AF08E3857C66 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org AF08E3857C66 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::52e ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1707859969; cv=none; b=sGrdHk2uWNCJ0KnXCCSWKtolpBnq/lxhGx5txD+EUplbAqAkGuArFTmooPfgcxyRrRioz2m7NVABsNXptfoznaFDJc3vm6b/YOFm3KlcTS4i8lyj6ptb2LfuBQIuB94RAjfDZkfeuZG70vNenEa6Yyk5uHgT2cKkEHmsuokJPmg= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1707859969; c=relaxed/simple; bh=jErq8qAXm8VuWD8CZ1j/Sqey3lUUCjaAhUxWEa1eJpg=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=DZFSZhTshSMjJW4wYMI1mqoNNZhMj1VgdVRK1Qn9NiZk9dxwa9vHheNYP7kwWiQLOICcSJs0+0nQkxf+GNkIziJtiXcMO7Vt+Zx5lPPca3+EkklRyLd+WzJiKxGs//i1Olevx2uunJZ7uExD141xjNP3/g4DYI3h9mrN0RbeHBY= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pg1-x52e.google.com with SMTP id 41be03b00d2f7-5d8df2edd29so999378a12.2 for ; Tue, 13 Feb 2024 13:32:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1707859966; x=1708464766; darn=gcc.gnu.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=AdfMVwMavmZRwz6VNK4ak2qS3IxmIfMSf/b8oB3IZYU=; b=JH3z67zO3zugDO6MmFfFxOrhLKKdFFiGeAGf5mhvV6UTMdGufiAM7tVQL2Kt/nlniS 87tbO8KEYDSnFR1S4F5vm87gz0REKcMapQCQG8Drt7uWoz3rH/CxuJthCX1cIIl1gDo7 BQSWXe/29JNEjLbzG2Q72l6teSGQVfadJ8cehJ/3PGi29pPdn1wNFB3Jn980lJuflZGy nxAlX36G3iGvo4MHhjo7HLQTtml9/vZQCEr5kM3jh/T9sqjm4sGeFwIYKPtYg223Z+R+ psj80uY9rmV6oeO1Tm8w/BQtLn5cMwXsDy0pOYDeaqb8q6x4YwJxSmD7p1tBDgveyDJu icyQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707859966; x=1708464766; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=AdfMVwMavmZRwz6VNK4ak2qS3IxmIfMSf/b8oB3IZYU=; b=ClMj4zOiMq/YiU9s5Cl70dZplgvbGrtkD/hMbLmy9p9egu2nEqc6AAAwMITm/UHGvx A8/3LPBmolzPQ6gFqlwh9z8Q0G0gQqaqV5lmkkf0XIzpUbYvNOELkff35nUzxzngeXOb OZhil5pF+ZHvB+Mj0qxNYW3o8V/laBP1yRgSti9PEPz4ZXteLYZerXu0ha2ses4c4MhK jRMhgPOfFcLhSlbi7QbtxHbJxSlIrsY5F5qV5shRg5WJeCyy/3ms/cdAXwrdaap8Kg6t U3ialESqCs0DTSiVfQTJuGftJ48TxrhpQPFId/ip9cJsaqWNYK1739lloI0HHvVEQgEn tYWg== X-Gm-Message-State: AOJu0YxvGoG9ZuP36TsuAzM0pWD6VtetSRq7COEv/nGpcx5KKLxh0QK7 NiC5bqgHD5OraS28MrrV9eCi+U3hcMQv8CX+PC2w4wnHaSBQtcERRGMLoPcY X-Google-Smtp-Source: AGHT+IH80nZ7k9sj6Nv7i3FFlX5l8cry5Axze1FM9wTd+8vDV43yrNEXQczctmZpHyKc+j3lxCSKhg== X-Received: by 2002:a05:6a21:3182:b0:19c:a202:3f96 with SMTP id za2-20020a056a21318200b0019ca2023f96mr912146pzb.51.1707859966143; Tue, 13 Feb 2024 13:32:46 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCXFU4xjbpZE3LbxUoJ2RGZv5mScPMuQ43QOYRl/jDZQQA/g/b79P0w0i7dQl/uP2R0HgmbmqyVmGOcVxOUJ3SzRYeFQh2E= Received: from gnu-cfl-3.localdomain ([172.56.168.224]) by smtp.gmail.com with ESMTPSA id f7-20020a056a00238700b006e089bb3619sm7817214pfc.112.2024.02.13.13.32.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Feb 2024 13:32:45 -0800 (PST) Received: from gnu-cfl-3.. (localhost [IPv6:::1]) by gnu-cfl-3.localdomain (Postfix) with ESMTP id BDD8F740120; Tue, 13 Feb 2024 13:32:44 -0800 (PST) From: "H.J. Lu" To: gcc-patches@gcc.gnu.org Cc: jakub@redhat.com, hongtao.liu@intel.com Subject: [PATCH] x86-64: Generate push2/pop2 only if the incoming stack is 16-byte aligned Date: Tue, 13 Feb 2024 13:32:44 -0800 Message-ID: <20240213213244.4160191-1-hjl.tools@gmail.com> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 X-Spam-Status: No, score=-3021.8 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, RCVD_IN_SBL_CSS, SPF_HELO_NONE, SPF_PASS, TXREP, T_SCC_BODY_TEXT_LINE 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.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Since push2/pop2 requires 16-byte stack alignment, don't generate them if the incoming stack isn't 16-byte aligned. gcc/ PR target/113912 * config/i386/i386.cc (ix86_can_use_push2pop2): New. (ix86_pro_and_epilogue_can_use_push2pop2): Use it. (ix86_emit_save_regs): Don't generate push2 if ix86_can_use_push2pop2 return false. (ix86_expand_epilogue): Don't generate pop2 if ix86_can_use_push2pop2 return false. gcc/testsuite/ PR target/113912 * gcc.target/i386/apx-push2pop2-2.c: New test. --- gcc/config/i386/i386.cc | 24 ++++++++++++++----- .../gcc.target/i386/apx-push2pop2-2.c | 24 +++++++++++++++++++ 2 files changed, 42 insertions(+), 6 deletions(-) create mode 100644 gcc/testsuite/gcc.target/i386/apx-push2pop2-2.c diff --git a/gcc/config/i386/i386.cc b/gcc/config/i386/i386.cc index a4e12602f70..46f238651a6 100644 --- a/gcc/config/i386/i386.cc +++ b/gcc/config/i386/i386.cc @@ -6802,16 +6802,24 @@ get_probe_interval (void) #define SPLIT_STACK_AVAILABLE 256 -/* Helper function to determine whether push2/pop2 can be used in prologue or - epilogue for register save/restore. */ +/* Return true if push2/pop2 can be generated. */ + static bool -ix86_pro_and_epilogue_can_use_push2pop2 (int nregs) +ix86_can_use_push2pop2 (void) { /* Use push2/pop2 only if the incoming stack is 16-byte aligned. */ unsigned int incoming_stack_boundary = (crtl->parm_stack_boundary > ix86_incoming_stack_boundary ? crtl->parm_stack_boundary : ix86_incoming_stack_boundary); - if (incoming_stack_boundary % 128 != 0) + return incoming_stack_boundary % 128 == 0; +} + +/* Helper function to determine whether push2/pop2 can be used in prologue or + epilogue for register save/restore. */ +static bool +ix86_pro_and_epilogue_can_use_push2pop2 (int nregs) +{ + if (!ix86_can_use_push2pop2 ()) return false; int aligned = cfun->machine->fs.sp_offset % 16 == 0; return TARGET_APX_PUSH2POP2 @@ -7401,7 +7409,9 @@ ix86_emit_save_regs (void) int regno; rtx_insn *insn; - if (!TARGET_APX_PUSH2POP2 || cfun->machine->func_type != TYPE_NORMAL) + if (!TARGET_APX_PUSH2POP2 + || !ix86_can_use_push2pop2 () + || cfun->machine->func_type != TYPE_NORMAL) { for (regno = FIRST_PSEUDO_REGISTER - 1; regno >= 0; regno--) if (GENERAL_REGNO_P (regno) && ix86_save_reg (regno, true, true)) @@ -10039,7 +10049,9 @@ ix86_expand_epilogue (int style) m->fs.cfa_reg == stack_pointer_rtx); } - if (TARGET_APX_PUSH2POP2 && m->func_type == TYPE_NORMAL) + if (TARGET_APX_PUSH2POP2 + && ix86_can_use_push2pop2 () + && m->func_type == TYPE_NORMAL) ix86_emit_restore_regs_using_pop2 (); else ix86_emit_restore_regs_using_pop (TARGET_APX_PPX); diff --git a/gcc/testsuite/gcc.target/i386/apx-push2pop2-2.c b/gcc/testsuite/gcc.target/i386/apx-push2pop2-2.c new file mode 100644 index 00000000000..975a6212b30 --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/apx-push2pop2-2.c @@ -0,0 +1,24 @@ +/* { dg-do compile { target { ! ia32 } } } */ +/* { dg-options "-O2 -mpreferred-stack-boundary=3 -mapx-features=push2pop2 -fomit-frame-pointer" } */ + +extern int bar (int); + +void foo () +{ + int a,b,c,d,e,f,i; + a = bar (5); + b = bar (a); + c = bar (b); + d = bar (c); + e = bar (d); + f = bar (e); + for (i = 1; i < 10; i++) + { + a += bar (a + i) + bar (b + i) + + bar (c + i) + bar (d + i) + + bar (e + i) + bar (f + i); + } +} + +/* { dg-final { scan-assembler-not "push2(|p)\[\\t \]*%r" } } */ +/* { dg-final { scan-assembler-not "pop2(|p)\[\\t \]*%r" } } */