public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
From: Hanke Zhang <hkzhang455@gmail.com>
To: gcc@gcc.gnu.org
Subject: Question about function splitting
Date: Mon, 2 Oct 2023 23:59:55 +0800	[thread overview]
Message-ID: <CAM_DAs-dEJ8Ao+0EOiKDc7CGDCx8v9o+2yrBg3fVbNQwD0dE+Q@mail.gmail.com> (raw)

Hi, I have some questions about the strategy and behavior of function
splitting in gcc, like the following code:

int glob;
void f() {
  if (glob) {
    printf("short path\n");
    return;
  }
  // do lots of expensive things
  // ...
}

I hope it can be broken down like below, so that the whole function
can perhaps be inlined, which is more efficient.

int glob;
void f() {
  if (glob) {
    printf("short path\n");
    return;
  }
  f_part();
}

void f_part() {
  // do lots of expensive things
  // ...
}


But on the contrary, gcc splits it like these, which not only does not
bring any benefits, but may increase the time consumption, because the
function call itself is a more resource-intensive thing.

int glob;
void f() {
  if (glob) {
    f_part();
    return;
  }
  // do lots of expensive things
  // ...
}

void f_part() {
  printf("short path\n"); // just do this????
}

Are there any options I can offer to gcc to change this behavior? Or
do I need to make some changes in ipa-split.cc?

             reply	other threads:[~2023-10-02 16:00 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-02 15:59 Hanke Zhang [this message]
2023-10-02 16:34 ` Martin Jambor
2023-10-02 17:13   ` Hanke Zhang
2023-10-04  8:17     ` Richard Biener
2023-10-04 14:22       ` Hanke Zhang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAM_DAs-dEJ8Ao+0EOiKDc7CGDCx8v9o+2yrBg3fVbNQwD0dE+Q@mail.gmail.com \
    --to=hkzhang455@gmail.com \
    --cc=gcc@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).