From patchwork Fri Oct 7 04:03:25 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kito Cheng X-Patchwork-Id: 1802 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp110035wrs; Thu, 6 Oct 2022 21:04:26 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4qbnAgY2DH+ApqYxLCus/XzabxaFey+3cjMLUl8r/k5HfMztPYyjavq0kKqzm5vnp4/ohW X-Received: by 2002:a17:907:2bd9:b0:78b:dda1:5a45 with SMTP id gv25-20020a1709072bd900b0078bdda15a45mr2460531ejc.534.1665115466427; Thu, 06 Oct 2022 21:04:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1665115466; cv=none; d=google.com; s=arc-20160816; b=INUIgWChHaJP1EZh2GZRq0cYU5HJxc34xt7d3yGZm2cWRvz97sjpcO38tTAGhHTjvB 4m6pPVJoVXZuuP0kvJrI3ABiTzysVgBgHM6qvBXvdMBEydh3aR/EMY8m/hqH2et93EO0 8uyp5KCr3O2WGqVPej4JBNFe6Ny006A/yLB+R8oS7gy/1kkFnMfQJl3ZqmkyM3oXaa/D TazgG9sNhMbTCtjdJgJBXM8tfnavER1zdWYAYsn7Oqk1Mq4VhomQ5GxHfmvPeir+Qq89 zcB31pZVNw4NIDUuy9XwR6q6D9RcOABm4PTImY5PkvMc+ulQ5PPAk+koKb2appJ7rlb7 gjUg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:message-id:date:subject:to:from:dkim-signature :dmarc-filter:delivered-to; bh=8TgUasoTzW94qmSkYXxx1NlWUmpGqm2UMtNCEOTJNaY=; b=qvDODdecN1RA4+eumgeTyNMsmLIhP1k8Sr2YMNqQY4x982+Hn8ChqymqHsoGUfQcqd EbE1dNJDtjsolMxP1Km6F21lbj8tECPo/jqKUomFPrN+a7R89RENgYvo146e1htKKKZm /1uRbHZTtPfYdel0ww8EP2jCNmZB/F1OrAmYGYXA+VAj5so5ZX5un1iXkcM1NzfzoG26 H+6lr3CY4xaeER8O3M7fexXL6q2aqI09YuQOSoTeHxSpNft+iu9OltQnWQp8mGicwz+Y EABFyq4UUu0IF888370TiWoJyrq9//MkqEq3fiVtfyALVmp5yHjYisrf031oVI8briTF MIeg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sifive.com header.s=google header.b=SQHFijfJ; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id qf29-20020a1709077f1d00b0078bdbb52361si1359980ejc.209.2022.10.06.21.04.26 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Oct 2022 21:04:26 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@sifive.com header.s=google header.b=SQHFijfJ; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 7AFC33948A71 for ; Fri, 7 Oct 2022 04:04:22 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-pl1-x636.google.com (mail-pl1-x636.google.com [IPv6:2607:f8b0:4864:20::636]) by sourceware.org (Postfix) with ESMTPS id 5E2713898C77 for ; Fri, 7 Oct 2022 04:03:58 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 5E2713898C77 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=sifive.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=sifive.com Received: by mail-pl1-x636.google.com with SMTP id z20so3474750plb.10 for ; Thu, 06 Oct 2022 21:03:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=8TgUasoTzW94qmSkYXxx1NlWUmpGqm2UMtNCEOTJNaY=; b=SQHFijfJWfZlTDHDvhAe8VGB4lTiHFo1BUxe7I+z2WA79nTpH1ZNTaJ9aB/dm+P0rn eZBXik43vypWcxpfHg64aPqfHjiT9UeSGN8N5pPUfh/mSCOfzNT5eZVc72yHXR9VjXmy GK1BvGPDsc0DK34neH9SJJSSlQiy63Si5zWKn5cc+iG6EPde9Furg4anW8NwZ2PXAuAo Njo2QvaxLgstiR1KMdyOtwx4KszyPfOlPzgbhPYTPCWC2T3I8asECYM19E1vPuWJsDMv /48aZKxCWMoBzaj+BcK/W/A5tEWJpluvP/UCd1iK378md7sLD1OlsSpUHgmgz/nQhyHv ZWDg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=8TgUasoTzW94qmSkYXxx1NlWUmpGqm2UMtNCEOTJNaY=; b=rQFKkeaOJspF8MZBdPnqFLg259eMFYG+IUd4+u9hdUKnWcK/LMJNnkFd0OKeHXMzq8 osMpY8ywNGQEWJmKpPAPZ2rmzKa5JtSYZIYY8x9zxp8yb+UWC8UbnzXmF3WJRiAU0UJk jPlQFHoxC59JTMfDJ14Y7Fv26do4BmsUJ81ylJjilR/aja/EAPDkGGH0vSz9ZXeLpgUW faX6gNU2LpUd02T7q7P8ZePcf2Vmgj53uO/CHoiJiiHFAmBsobko1LItiiIEDV/HhpKY 1uzd7fGoR91mCegxLWDjpp0xjgeK7UI2Rie388S7cX3dEsOIsBO/XP6EOGOi1QDfavgJ U1JQ== X-Gm-Message-State: ACrzQf2yc1hG05rpvnzNKj5Evn1P5EPCdnxNA7Y1i0I/Krcu1FONPMif FSICSVBotACv+JMQ9T86FWa2aENKLD4ACkiEHVSzXTv2n4AVVkYGp+HPLOociK3rSVgahot4YH6 TlCEdFwgLP8dYr6FJ/U2kSONdyQxwGZdRLhopRT+TdxZDxv79cNZ1SJyhdcs045qAg7Bob9BpgQ == X-Received: by 2002:a17:90a:1c1:b0:20a:e745:bc30 with SMTP id 1-20020a17090a01c100b0020ae745bc30mr14245103pjd.131.1665115436709; Thu, 06 Oct 2022 21:03:56 -0700 (PDT) Received: from hsinchu02.internal.sifive.com (59-124-168-89.hinet-ip.hinet.net. [59.124.168.89]) by smtp.gmail.com with ESMTPSA id p16-20020a170903249000b0017f864355aasm416947plw.164.2022.10.06.21.03.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Oct 2022 21:03:56 -0700 (PDT) From: Kito Cheng To: gcc-patches@gcc.gnu.org, kito.cheng@gmail.com, msebor@gcc.gnu.org, jakub@gcc.gnu.org, rguenth@gcc.gnu.org, koen.zandberg@inria.fr, andy.chiu@sifive.com, guoren@kernel.org, greentime.hu@sifive.com, palmer@dabbelt.com Subject: [PATCH] PR middle-end/88345: Honor -falign-functions=N even optimized for size. Date: Fri, 7 Oct 2022 12:03:25 +0800 Message-Id: <20221007040325.21276-1-kito.cheng@sifive.com> X-Mailer: git-send-email 2.37.2 MIME-Version: 1.0 X-Spam-Status: No, score=-13.2 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=unavailable 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.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Monk Chiang Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1746000115134021670?= X-GMAIL-MSGID: =?utf-8?q?1746000115134021670?= From: Monk Chiang Currnetly setting of -falign-functions=N will be ignored if the function is optimized for size or marked as cold function. However function alignment requirement is needed even optimized for size in some situations, RISC-V target is an example, RISC-V kernel implement patchable function that require function must be align to at least 4 bytes for atomicly patch the function prologue. Here is 4 way to fix that: 1. Fix -falign-functions=N, let it work as expect on -Os and all cold functions, which is this patch. 2. Force align to 4 byte if -fpatchable-function-entry is given by adjust RISC-V's FUNCTION_BOUNDARY. 3. Adjust RISC-V's FUNCTION_BOUNDARY to let it honor to -falign-functions=N. 4. Adding a -malign-functions=N for RISC-V...which x86 already deprecated that. And this patch is the first approach. gcc/ChangeLog: PR middle-end/88345 * varasm.cc (assemble_start_function): Adjust function align even optimized for size. * doc/invoke.texi (Os): Remove -falign-functions= from the exclusion list of -Os. gcc/testsuite/ChangeLog: PR middle-end/88345 * gcc.target/i386/pr88345-1.c: New. * gcc.target/i386/pr88345-2.c: Ditto. * gcc.target/riscv/pr88345-1.c: Ditto. * gcc.target/riscv/pr88345-2.c: Ditto. Reviewed-by: Palmer Dabbelt --- gcc/doc/invoke.texi | 2 +- gcc/testsuite/gcc.target/i386/pr88345-1.c | 5 +++++ gcc/testsuite/gcc.target/i386/pr88345-2.c | 5 +++++ gcc/testsuite/gcc.target/riscv/pr88345-1.c | 5 +++++ gcc/testsuite/gcc.target/riscv/pr88345-2.c | 5 +++++ gcc/varasm.cc | 3 +-- 6 files changed, 22 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/gcc.target/i386/pr88345-1.c create mode 100644 gcc/testsuite/gcc.target/i386/pr88345-2.c create mode 100644 gcc/testsuite/gcc.target/riscv/pr88345-1.c create mode 100644 gcc/testsuite/gcc.target/riscv/pr88345-2.c diff --git a/gcc/doc/invoke.texi b/gcc/doc/invoke.texi index a2b0b9636f0..acf98c68825 100644 --- a/gcc/doc/invoke.texi +++ b/gcc/doc/invoke.texi @@ -11381,7 +11381,7 @@ results. This is the default. Optimize for size. @option{-Os} enables all @option{-O2} optimizations except those that often increase code size: -@gccoptlist{-falign-functions -falign-jumps @gol +@gccoptlist{-falign-jumps @gol -falign-labels -falign-loops @gol -fprefetch-loop-arrays -freorder-blocks-algorithm=stc} diff --git a/gcc/testsuite/gcc.target/i386/pr88345-1.c b/gcc/testsuite/gcc.target/i386/pr88345-1.c new file mode 100644 index 00000000000..226bb9ffc82 --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/pr88345-1.c @@ -0,0 +1,5 @@ +/* { dg-do compile } */ +/* { dg-options "-falign-functions=128" } */ +/* { dg-final { scan-assembler-times "\.p2align\t7" 1 } } */ + +__attribute__((__cold__)) void a() {} diff --git a/gcc/testsuite/gcc.target/i386/pr88345-2.c b/gcc/testsuite/gcc.target/i386/pr88345-2.c new file mode 100644 index 00000000000..a7fc3b162dd --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/pr88345-2.c @@ -0,0 +1,5 @@ +/* { dg-do compile } */ +/* { dg-options "-falign-functions=128 -Os" } */ +/* { dg-final { scan-assembler-times "\.p2align\t7" 1 } } */ + +void a() {} diff --git a/gcc/testsuite/gcc.target/riscv/pr88345-1.c b/gcc/testsuite/gcc.target/riscv/pr88345-1.c new file mode 100644 index 00000000000..7d5afe683eb --- /dev/null +++ b/gcc/testsuite/gcc.target/riscv/pr88345-1.c @@ -0,0 +1,5 @@ +/* { dg-do compile } */ +/* { dg-options "-falign-functions=128" } */ +/* { dg-final { scan-assembler-times "\.align\t7" 1 } } */ + +__attribute__((__cold__)) void a() {} diff --git a/gcc/testsuite/gcc.target/riscv/pr88345-2.c b/gcc/testsuite/gcc.target/riscv/pr88345-2.c new file mode 100644 index 00000000000..d4fc89d86d8 --- /dev/null +++ b/gcc/testsuite/gcc.target/riscv/pr88345-2.c @@ -0,0 +1,5 @@ +/* { dg-do compile } */ +/* { dg-options "-falign-functions=128 -Os" } */ +/* { dg-final { scan-assembler-times "\.align\t7" 1 } } */ + +void a() {} diff --git a/gcc/varasm.cc b/gcc/varasm.cc index 423f3f91af8..4001648b214 100644 --- a/gcc/varasm.cc +++ b/gcc/varasm.cc @@ -1923,8 +1923,7 @@ assemble_start_function (tree decl, const char *fnname) Note that we still need to align to DECL_ALIGN, as above, because ASM_OUTPUT_MAX_SKIP_ALIGN might not do any alignment at all. */ if (! DECL_USER_ALIGN (decl) - && align_functions.levels[0].log > align - && optimize_function_for_speed_p (cfun)) + && align_functions.levels[0].log > align) { #ifdef ASM_OUTPUT_MAX_SKIP_ALIGN int align_log = align_functions.levels[0].log;