From patchwork Fri Aug 9 01:53:10 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: 1970777 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=ag7S59S0; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; 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 [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 ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Wg6QH5JVYz1ydk for ; Fri, 9 Aug 2024 11:53:43 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 70B903858414 for ; Fri, 9 Aug 2024 01:53:41 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-il1-x12d.google.com (mail-il1-x12d.google.com [IPv6:2607:f8b0:4864:20::12d]) by sourceware.org (Postfix) with ESMTPS id 256C33858D20 for ; Fri, 9 Aug 2024 01:53:18 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 256C33858D20 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 256C33858D20 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::12d ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1723168402; cv=none; b=LTlhOM7LHYavtlXQjYg7vD8L0V9134/N8JjhD6m+Q8k9I7huc0oGJ/gdcpkdl+ahvEaNwQRkFi3QEKakIsR9BX+vpx/18Tp8H0Szl1cbN6ImfHSd3riartku1bssy+tJX0bmnEerdiRpsiO765oZZv9Ouvj6hPv0js1rtZ64b3s= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1723168402; c=relaxed/simple; bh=poidrD5WwEQBTJorWzLLzmgU46YTKgdX8xyQwc7458A=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=sBCkNWrwPuOhdEs1F26s4vWjYIeV/sEGGyL9hRjHwc1EdankSTPhof2RTRUo0z0Nf1+AS0WwMjJFGzLXu7WaydMrd7vuqKH9mdiF6gDDKeU5xWiVHXI3owzqmv92MBa+EHLRGfgenKWGSlOxLW/1tww+ScSJnfu7iAxsZNmenCs= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-il1-x12d.google.com with SMTP id e9e14a558f8ab-39aeccc6377so6417945ab.1 for ; Thu, 08 Aug 2024 18:53:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1723168397; x=1723773197; 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=XXx+6Egv4y6eE+630dPNv0E229kIXnndX8ppW+l+EMg=; b=ag7S59S0JbE+Q2C42e+2F8YmG7oPqx2fPHPobxlQJOYhUe3FTXNEohB4B2uV6fDWB3 gdyHAb/YILyf+SBIBOU9oKUqooHTHPXBExmgwZQSbvjR2HHTEBnVROhbaQqenRURY33r JFmLkFyojts0UcGV1YtJ/Z4UFqVP2HSDR3VggrsEAm4kVtTBQpCLpJxqUJdBR+ubyWob O9zLKw5JTa9gQ5/7uPfi5O/t0UQJqlfqnYuqVv2H4tPMh946Xm0x2wCUFT1yi7dj9zmW k99kiSPQOTuB/g4rDTw7wm7ktx0HctegeYPPQqMpscXrYzHZa2KePO2BW59Kxe1ZMO0/ +FWw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1723168397; x=1723773197; 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=XXx+6Egv4y6eE+630dPNv0E229kIXnndX8ppW+l+EMg=; b=nUV3LzZI5qwQHp9+jgd8KZu5hfFe9+OtHboJ5Q1Cnpmzpn7Re50RTJNx/w5zEfTV+A LMMvoeKzZE8wTF1gk4QSFnxkchp9mtBiX2Rp0n8nTuYwZXU6J8bTpPDgLXXAvY8fkR4I 31iWPVMq9DhQ6IWV30agqEuvu5G6xo9DeH1ysx9Ila/4mbA403vREJY5Wf1Y9l9HMWnC pLxgrEAWgqY8r6teEBUFQMEourevz5N/94iBxQx31o/PduXoccqafP8ZSxSlezK4u/H1 ojKmV5v8WwS9RV+ezrWg2kuw+fWwTgsvgq1QBckdsDy8Rr8F78+azN26OEKoLT3zrnTg joLg== X-Gm-Message-State: AOJu0Yw6AYwvAaTTyWU1DUYki4b+E7klUvbQDur1xOupdkYMbQnS3CB/ 7ghzYjcdwQSeMOqU+ESOZxA5H+FjUjbK90JxtGKRexSuModhESXrpgfjwrxW7GU= X-Google-Smtp-Source: AGHT+IHT2XWLAnJ26F3BMPxFG6Ow+v2BWL5vdCPseW1QpFpUJD6HZDcXmKsReVjLIcXE9qwCC88F1g== X-Received: by 2002:a05:6e02:1c42:b0:39b:25de:8093 with SMTP id e9e14a558f8ab-39b7a443d5dmr2796535ab.17.1723168397032; Thu, 08 Aug 2024 18:53:17 -0700 (PDT) Received: from gnu-tgl-3.localdomain ([172.58.142.217]) by smtp.gmail.com with ESMTPSA id e9e14a558f8ab-39b37ccf220sm45118715ab.79.2024.08.08.18.53.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Aug 2024 18:53:16 -0700 (PDT) Received: from gnu-tgl-3.. (localhost [IPv6:::1]) by gnu-tgl-3.localdomain (Postfix) with ESMTP id 131E1C00D2; Thu, 8 Aug 2024 18:53:11 -0700 (PDT) From: "H.J. Lu" To: gcc-patches@gcc.gnu.org Cc: ubizjak@gmail.com, hongtao.liu@intel.com Subject: [PATCH] x86: Update BB_HEAD when aligning BB_HEAD Date: Thu, 8 Aug 2024 18:53:10 -0700 Message-ID: <20240809015310.673857-1-hjl.tools@gmail.com> X-Mailer: git-send-email 2.45.2 MIME-Version: 1.0 X-Spam-Status: No, score=-3021.4 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, SPF_HELO_NONE, SPF_PASS, TXREP 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 When we emit .p2align to align BB_HEAD, we must update BB_HEAD. Otherwise ENDBR will be inserted as the wrong place. gcc/ PR target/116174 * config/i386/i386.cc (ix86_align_loops): Update BB_HEAD when aligning BB_HEAD gcc/testsuite/ PR target/116174 * gcc.target/i386/pr116174.c: New test. Signed-off-by: H.J. Lu --- gcc/config/i386/i386.cc | 7 +++++-- gcc/testsuite/gcc.target/i386/pr116174.c | 12 ++++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/gcc.target/i386/pr116174.c diff --git a/gcc/config/i386/i386.cc b/gcc/config/i386/i386.cc index 77c441893b4..ec6cc5e3548 100644 --- a/gcc/config/i386/i386.cc +++ b/gcc/config/i386/i386.cc @@ -23528,8 +23528,11 @@ ix86_align_loops () if (padding_p && detect_tight_loop_p) { - emit_insn_before (gen_max_skip_align (GEN_INT (ceil_log2 (size)), - GEN_INT (0)), label); + rtx_insn *align = + emit_insn_before (gen_max_skip_align (GEN_INT (ceil_log2 (size)), + GEN_INT (0)), label); + if (BB_HEAD (bb) == label) + BB_HEAD (bb) = align; /* End of function. */ if (!tbb || tbb == EXIT_BLOCK_PTR_FOR_FN (cfun)) break; diff --git a/gcc/testsuite/gcc.target/i386/pr116174.c b/gcc/testsuite/gcc.target/i386/pr116174.c new file mode 100644 index 00000000000..8877d0b51af --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/pr116174.c @@ -0,0 +1,12 @@ +/* { dg-do compile { target *-*-linux* } } */ +/* { dg-options "-O2 -fcf-protection=branch" } */ + +char * +foo (char *dest, const char *src) +{ + while ((*dest++ = *src++) != '\0') + /* nothing */; + return --dest; +} + +/* { dg-final { scan-assembler "\t\.cfi_startproc\n\tendbr(32|64)\n" } } */