From patchwork Thu Jan 7 23:49:20 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: 1423589 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; dmarc=pass (p=none dis=none) header.from=gcc.gnu.org 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=i0hphewE; 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 4DBjdB2ycZz9sWh for ; Fri, 8 Jan 2021 10:49:31 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id C595F3844061; Thu, 7 Jan 2021 23:49:27 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C595F3844061 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1610063367; bh=A4HtH/2tVxcF76RvN4oIZAPod1Yf3+I9q7MYnWn0dOk=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=i0hphewEgviWxcAiWSqxxzI4OF6/Be+XmP/UgiPl2c0PisOGptUh3uwVa2M2On0xd +A+8IFmzx18dQF3XucgioR9E5K8cnjlxEwBpcpyXJudjVwCN7/HeIfRbRZkrl1mMik wnk1rnWRVwoP11Ic7ZpEvR/07me3Z8InEMnb7rTg= 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 AEF8D386101C for ; Thu, 7 Jan 2021 23:49:25 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org AEF8D386101C Received: by mail-pl1-x62c.google.com with SMTP id x18so4714283pln.6 for ; Thu, 07 Jan 2021 15:49:25 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=A4HtH/2tVxcF76RvN4oIZAPod1Yf3+I9q7MYnWn0dOk=; b=r/D62T9faeJtIyljyMzwapAjg9xR4zW04LLzwb1HmR5ejttywEQkwJy0O05qJdmGes GmQ3aszmgyvqbH+3C7m+zc8kdrZJTg8Kbwe4eWkpZM5avTuTPajWm5KXPUE5L8QKcpFL WRe4zS9TmLTq5wxriL3qjTKt/Hqyp1mCTwLePxFlJY3TG66BvrwAvf+6vbB58cGOH4LT sV3ntvXlTr5d/q3UBCbwQHMRR0jGQXBZKSE5h+hYr6vbJ99187CZfzwck7W20DQUq76J kYdKCtBFtju3G8qBX4sGTZXzzh7o2TmslAcGIcxynFDG/q+YY5iQjNqvUSIBY9GQUscy pyUw== X-Gm-Message-State: AOAM533brqQJWuaPk+R6+kr0sMP9TDPRnEZDDfNWHxuCfyjdsIMxH2Md cYklHZf5TIPTvu19XIdlNul8TT0bUTc= X-Google-Smtp-Source: ABdhPJyyiehsg5ZvlhJiQq0PIATaexK2Wcmm0b6XTC6TY8X5K3k+hL+C/1coTkPkOFtpBG8361tZug== X-Received: by 2002:a17:90b:2092:: with SMTP id hb18mr849488pjb.63.1610063364421; Thu, 07 Jan 2021 15:49:24 -0800 (PST) Received: from gnu-cfl-2.localdomain (c-69-181-90-243.hsd1.ca.comcast.net. [69.181.90.243]) by smtp.gmail.com with ESMTPSA id j14sm3054891pjm.10.2021.01.07.15.49.23 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 07 Jan 2021 15:49:23 -0800 (PST) Received: from gnu-cfl-2.localdomain (localhost [IPv6:::1]) by gnu-cfl-2.localdomain (Postfix) with ESMTP id 2D3F61A022B for ; Thu, 7 Jan 2021 15:49:22 -0800 (PST) To: gcc-patches@gcc.gnu.org Subject: [PATCH] x86-64: Use R10 for profiling large model Date: Thu, 7 Jan 2021 15:49:20 -0800 Message-Id: <20210107234920.2212441-1-hjl.tools@gmail.com> X-Mailer: git-send-email 2.29.2 MIME-Version: 1.0 X-Spam-Status: No, score=-3039.6 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" Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" Since R10 is preserved when calling mcount, R10 can be used a scratch register to call mcount in large model. gcc/ PR target/98482 * config/i386/i386.c (x86_function_profiler): Use R10 to call mcount in large model. Sorry for large model with PIC. gcc/testsuite/ PR target/98482 * gcc.target/i386/pr98482-1.c: New test. * gcc.target/i386/pr98482-1.c: Likewise. --- gcc/config/i386/i386.c | 25 +++++++++++++++++++++-- gcc/testsuite/gcc.target/i386/pr98482-1.c | 9 ++++++++ gcc/testsuite/gcc.target/i386/pr98482-2.c | 9 ++++++++ 3 files changed, 41 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/gcc.target/i386/pr98482-1.c create mode 100644 gcc/testsuite/gcc.target/i386/pr98482-2.c diff --git a/gcc/config/i386/i386.c b/gcc/config/i386/i386.c index fad50e7e537..7a07ab8b5f5 100644 --- a/gcc/config/i386/i386.c +++ b/gcc/config/i386/i386.c @@ -20794,8 +20794,29 @@ x86_function_profiler (FILE *file, int labelno ATTRIBUTE_UNUSED) fprintf (file, "\tleaq\t%sP%d(%%rip),%%r11\n", LPREFIX, labelno); #endif - if (!TARGET_PECOFF && flag_pic) - fprintf (file, "1:\tcall\t*%s@GOTPCREL(%%rip)\n", mcount_name); + if (!TARGET_PECOFF) + { + switch (ix86_cmodel) + { + case CM_LARGE: + /* NB: R10 can be used as a scratch register here since + R10 is preserved when calling mcount. */ + fprintf (file, "1:\tmovabsq\t$%s, %%r10\n\tcall\t*%%r10\n", + mcount_name); + break; + case CM_LARGE_PIC: + sorry ("profiling %<-mcmodel=large%> with PIC is not supported"); + break; + case CM_SMALL_PIC: + case CM_MEDIUM_PIC: + fprintf (file, "1:\tcall\t*%s@GOTPCREL(%%rip)\n", + mcount_name); + break; + default: + x86_print_call_or_nop (file, mcount_name); + break; + } + } else x86_print_call_or_nop (file, mcount_name); } diff --git a/gcc/testsuite/gcc.target/i386/pr98482-1.c b/gcc/testsuite/gcc.target/i386/pr98482-1.c new file mode 100644 index 00000000000..72d5ccb269c --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/pr98482-1.c @@ -0,0 +1,9 @@ +/* { dg-do compile { target { *-*-linux* && { ! ia32 } } } } */ +/* { dg-require-effective-target mfentry } */ +/* { dg-options "-fprofile -mfentry -O2 -mcmodel=large" } */ +/* { dg-final { scan-assembler "movabsq\t\\\$__fentry__, %r10\n\tcall\t\\*%r10" } } */ + +void +func (void) +{ +} diff --git a/gcc/testsuite/gcc.target/i386/pr98482-2.c b/gcc/testsuite/gcc.target/i386/pr98482-2.c new file mode 100644 index 00000000000..aed3ca4b6ff --- /dev/null +++ b/gcc/testsuite/gcc.target/i386/pr98482-2.c @@ -0,0 +1,9 @@ +/* { dg-do compile { target { *-*-linux* && { ! ia32 } } } } */ +/* { dg-require-effective-target mfentry } */ +/* { dg-require-effective-target fpic } */ +/* { dg-options "-fpic -fprofile -mfentry -O2 -mcmodel=large" } */ + +void +func (void) +{ +} /* { dg-message "sorry, unimplemented: profiling '-mcmodel=large' with PIC is not supported" } */