public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/111672] New: Inappropriate function splitting during pass_split_functions
@ 2023-10-03  9:41 hkzhang455 at gmail dot com
  2023-10-03 16:37 ` [Bug ipa/111672] " pinskia at gcc dot gnu.org
                   ` (12 more replies)
  0 siblings, 13 replies; 14+ messages in thread
From: hkzhang455 at gmail dot com @ 2023-10-03  9:41 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111672

            Bug ID: 111672
           Summary: Inappropriate function splitting during
                    pass_split_functions
           Product: gcc
           Version: 12.3.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: hkzhang455 at gmail dot com
  Target Milestone: ---

Created attachment 56034
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=56034&action=edit
example C file that can trigger inappropriate function splitting

When the GCC compiler performs function splitting optimization, the shorter and
closer path is split into a new function, while the remaining more complex and
expensive code is retained, resulting in the complexity of the original
function being increased after the split, and the split new function only
performs simple operations (such as 'printf()').

You can compile the source code file I put in the attachment with the following
command, and look at the gimple corresponding to the generated fnsplit to find
the phenomenon I described.

  gcc test.c -O3 -flto -fdump-tree-fnsplit -Wall -Wextra

Of course, this is only sample code, so the resulting executable does not
reflect the efficiency gap due to the problem of inline. But in more complex
code, efficiency decreases.

Hardware: 12th Gen Intel(R) Core(TM) i9-12900KF
System: Ubuntu 22.04
Output of `gcc -v`:

Using built-in specs.
COLLECT_GCC=xxx/install/bin/gcc
COLLECT_LTO_WRAPPER=xxx/install/libexec/gcc/x86_64-pc-linux-gnu/12.3.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: ../configure --prefix=xxx/install --enable-threads=posix
--disable-checking --disable-multilib --disable-bootstrap
--enable-languages=c,c++,lto
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 12.3.0 (GCC)

^ permalink raw reply	[flat|nested] 14+ messages in thread

* [Bug ipa/111672] Inappropriate function splitting during pass_split_functions
  2023-10-03  9:41 [Bug c/111672] New: Inappropriate function splitting during pass_split_functions hkzhang455 at gmail dot com
@ 2023-10-03 16:37 ` pinskia at gcc dot gnu.org
  2023-10-04  2:00 ` hkzhang455 at gmail dot com
                   ` (11 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-10-03 16:37 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111672

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
I cannot reproduce this on the trunk (or even in 12.3.0):

Split point at BB 3
  header time: 1393.311190 header size: 33
  split time: 2.226400 split size: 2
  bbs: 3
  SSA names to pass:
  Refused: split size is smaller than call overhead
found articulation at bb 7
Split point at BB 7
  header time: 1395.537590 header size: 35
  split time: 0.000000 split size: 0
  bbs: 7
  SSA names to pass:
  Refused: split size is smaller than call overhead

^ permalink raw reply	[flat|nested] 14+ messages in thread

* [Bug ipa/111672] Inappropriate function splitting during pass_split_functions
  2023-10-03  9:41 [Bug c/111672] New: Inappropriate function splitting during pass_split_functions hkzhang455 at gmail dot com
  2023-10-03 16:37 ` [Bug ipa/111672] " pinskia at gcc dot gnu.org
@ 2023-10-04  2:00 ` hkzhang455 at gmail dot com
  2023-10-04  2:04 ` pinskia at gcc dot gnu.org
                   ` (10 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: hkzhang455 at gmail dot com @ 2023-10-04  2:00 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111672

--- Comment #2 from Hanke Zhang <hkzhang455 at gmail dot com> ---
(In reply to Andrew Pinski from comment #1)
> I cannot reproduce this on the trunk (or even in 12.3.0):
> 
> Split point at BB 3
>   header time: 1393.311190 header size: 33
>   split time: 2.226400 split size: 2
>   bbs: 3
>   SSA names to pass:
>   Refused: split size is smaller than call overhead
> found articulation at bb 7
> Split point at BB 7
>   header time: 1395.537590 header size: 35
>   split time: 0.000000 split size: 0
>   bbs: 7
>   SSA names to pass:
>   Refused: split size is smaller than call overhead

It's still the same bug in my place, and I'm trying to compile on another
computer, and the same happens. Note that, my host is x86_64-linux-gnu. Here is
part of my output infomation about function splitting optimization.

  gcc -O3 -flto -fdumo-tree-fnsplit test.c
  cat a-test.c.050t.fnsplit

;; Function printf (printf, funcdef_no=15, decl_uid=964, cgraph_uid=16,
symbol_order=15)

Not splitting: disregarding inline limits.
__attribute__((artificial, gnu_inline, always_inline))
__attribute__((nonnull (1), format (printf, 1, 2)))
int printf (const char * restrict __fmt)
{
  int _4;

  <bb 2> [local count: 1073741824]:
  _4 = __printf_chk (1, __fmt_2(D), __builtin_va_arg_pack ());
  return _4;

}



;; Function test_split_write (test_split_write, funcdef_no=39, decl_uid=3184,
cgraph_uid=40, symbol_order=43)



Splitting function at:
Split point at BB 3
  header time: 1393.311190 header size: 33
  split time: 2.428800 split size: 3
  bbs: 3
  SSA names to pass:
;; 1 loops found
;;
;; Loop 0
;;  header 0, latch 1
;;  depth 0, outer -1
;;  nodes: 0 1
Introduced new external node (puts/53).

Symbols to be put in SSA form
{ D.3222 }
Incremental SSA update started at block: 0
Number of blocks in CFG: 5
Number of blocks to update: 4 ( 80%)


;; 1 loops found
;;
;; Loop 0
;;  header 0, latch 1
;;  depth 0, outer -1
;;  nodes: 0 1 4 2 3
;; 4 succs { 2 }
;; 2 succs { 3 }
;; 3 succs { 1 }
int test_split_write.part.0 ()

^ permalink raw reply	[flat|nested] 14+ messages in thread

* [Bug ipa/111672] Inappropriate function splitting during pass_split_functions
  2023-10-03  9:41 [Bug c/111672] New: Inappropriate function splitting during pass_split_functions hkzhang455 at gmail dot com
  2023-10-03 16:37 ` [Bug ipa/111672] " pinskia at gcc dot gnu.org
  2023-10-04  2:00 ` hkzhang455 at gmail dot com
@ 2023-10-04  2:04 ` pinskia at gcc dot gnu.org
  2023-10-04  2:08 ` hkzhang455 at gmail dot com
                   ` (9 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-10-04  2:04 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111672

--- Comment #3 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Oh I see the compiler you are testing with defaults with fortify turned on.
That is the difference.
Maybe also with pie turned on by default tlalso.

Can you provide the full output of gcc -v and also the preprocessed source?

^ permalink raw reply	[flat|nested] 14+ messages in thread

* [Bug ipa/111672] Inappropriate function splitting during pass_split_functions
  2023-10-03  9:41 [Bug c/111672] New: Inappropriate function splitting during pass_split_functions hkzhang455 at gmail dot com
                   ` (2 preceding siblings ...)
  2023-10-04  2:04 ` pinskia at gcc dot gnu.org
@ 2023-10-04  2:08 ` hkzhang455 at gmail dot com
  2023-10-04  5:24 ` pinskia at gcc dot gnu.org
                   ` (8 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: hkzhang455 at gmail dot com @ 2023-10-04  2:08 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111672

--- Comment #4 from Hanke Zhang <hkzhang455 at gmail dot com> ---
(In reply to Andrew Pinski from comment #3)
> Oh I see the compiler you are testing with defaults with fortify turned on.
> That is the difference.
> Maybe also with pie turned on by default tlalso.
> 
> Can you provide the full output of gcc -v and also the preprocessed source?

The full output of gcc -v is shown in my description where you can check. And I
known't get what the preprocessed source means here. The origin source C file
is provided already.

^ permalink raw reply	[flat|nested] 14+ messages in thread

* [Bug ipa/111672] Inappropriate function splitting during pass_split_functions
  2023-10-03  9:41 [Bug c/111672] New: Inappropriate function splitting during pass_split_functions hkzhang455 at gmail dot com
                   ` (3 preceding siblings ...)
  2023-10-04  2:08 ` hkzhang455 at gmail dot com
@ 2023-10-04  5:24 ` pinskia at gcc dot gnu.org
  2023-10-04  5:25 ` pinskia at gcc dot gnu.org
                   ` (7 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-10-04  5:24 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111672

--- Comment #5 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Add -save-temps and attach the resulting .i (or .ii) file.

^ permalink raw reply	[flat|nested] 14+ messages in thread

* [Bug ipa/111672] Inappropriate function splitting during pass_split_functions
  2023-10-03  9:41 [Bug c/111672] New: Inappropriate function splitting during pass_split_functions hkzhang455 at gmail dot com
                   ` (4 preceding siblings ...)
  2023-10-04  5:24 ` pinskia at gcc dot gnu.org
@ 2023-10-04  5:25 ` pinskia at gcc dot gnu.org
  2023-10-04 13:48 ` hkzhang455 at gmail dot com
                   ` (6 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-10-04  5:25 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111672

--- Comment #6 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to Andrew Pinski from comment #5)
> Add -save-temps and attach the resulting .i (or .ii) file.

This is documented at https://gcc.gnu.org/bugs/ under the section of `What we
need `.

^ permalink raw reply	[flat|nested] 14+ messages in thread

* [Bug ipa/111672] Inappropriate function splitting during pass_split_functions
  2023-10-03  9:41 [Bug c/111672] New: Inappropriate function splitting during pass_split_functions hkzhang455 at gmail dot com
                   ` (5 preceding siblings ...)
  2023-10-04  5:25 ` pinskia at gcc dot gnu.org
@ 2023-10-04 13:48 ` hkzhang455 at gmail dot com
  2023-10-04 13:49 ` hkzhang455 at gmail dot com
                   ` (5 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: hkzhang455 at gmail dot com @ 2023-10-04 13:48 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111672

--- Comment #7 from Hanke Zhang <hkzhang455 at gmail dot com> ---
Created attachment 56046
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=56046&action=edit
preprocessed source

^ permalink raw reply	[flat|nested] 14+ messages in thread

* [Bug ipa/111672] Inappropriate function splitting during pass_split_functions
  2023-10-03  9:41 [Bug c/111672] New: Inappropriate function splitting during pass_split_functions hkzhang455 at gmail dot com
                   ` (6 preceding siblings ...)
  2023-10-04 13:48 ` hkzhang455 at gmail dot com
@ 2023-10-04 13:49 ` hkzhang455 at gmail dot com
  2023-10-04 23:58 ` pinskia at gcc dot gnu.org
                   ` (4 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: hkzhang455 at gmail dot com @ 2023-10-04 13:49 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111672

--- Comment #8 from Hanke Zhang <hkzhang455 at gmail dot com> ---
(In reply to Andrew Pinski from comment #5)
> Add -save-temps and attach the resulting .i (or .ii) file.

Thank you. I have attached it.

^ permalink raw reply	[flat|nested] 14+ messages in thread

* [Bug ipa/111672] Inappropriate function splitting during pass_split_functions
  2023-10-03  9:41 [Bug c/111672] New: Inappropriate function splitting during pass_split_functions hkzhang455 at gmail dot com
                   ` (7 preceding siblings ...)
  2023-10-04 13:49 ` hkzhang455 at gmail dot com
@ 2023-10-04 23:58 ` pinskia at gcc dot gnu.org
  2023-10-05  0:03 ` pinskia at gcc dot gnu.org
                   ` (3 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-10-04 23:58 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111672

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
  Attachment #56046|0                           |1
        is obsolete|                            |

--- Comment #9 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Created attachment 56053
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=56053&action=edit
Real Preprocessed source

So with the preprocessed source you provided still could not reproduce the
issue but Adding `-D_FORTIFY_SOURCE=2` to the original testcase does.
Obvious this was not mentioned and makes it harder to understand what was going
wrong even.

^ permalink raw reply	[flat|nested] 14+ messages in thread

* [Bug ipa/111672] Inappropriate function splitting during pass_split_functions
  2023-10-03  9:41 [Bug c/111672] New: Inappropriate function splitting during pass_split_functions hkzhang455 at gmail dot com
                   ` (8 preceding siblings ...)
  2023-10-04 23:58 ` pinskia at gcc dot gnu.org
@ 2023-10-05  0:03 ` pinskia at gcc dot gnu.org
  2023-10-06  2:48 ` hkzhang455 at gmail dot com
                   ` (2 subsequent siblings)
  12 siblings, 0 replies; 14+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-10-05  0:03 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111672

--- Comment #10 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
The difference between the 2 is the costing of the __printf_chk/puts:
_FORTIFY_SOURCE case:
  freq:0.20 size:  3 time:2.43 __printf_chk (1, "Object code generation not
active! Forgot to call quantum_objcode_start?\n");

vs without:
  freq:0.20 size:  2 time:2.23 puts (&"Object code generation not active!
Forgot to call quantum_objcode_start?"[0]);

^ permalink raw reply	[flat|nested] 14+ messages in thread

* [Bug ipa/111672] Inappropriate function splitting during pass_split_functions
  2023-10-03  9:41 [Bug c/111672] New: Inappropriate function splitting during pass_split_functions hkzhang455 at gmail dot com
                   ` (9 preceding siblings ...)
  2023-10-05  0:03 ` pinskia at gcc dot gnu.org
@ 2023-10-06  2:48 ` hkzhang455 at gmail dot com
  2023-10-06  2:59 ` pinskia at gcc dot gnu.org
  2023-10-06 16:16 ` hkzhang455 at gmail dot com
  12 siblings, 0 replies; 14+ messages in thread
From: hkzhang455 at gmail dot com @ 2023-10-06  2:48 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111672

--- Comment #11 from Hanke Zhang <hkzhang455 at gmail dot com> ---
(In reply to Andrew Pinski from comment #10)
> The difference between the 2 is the costing of the __printf_chk/puts:
> _FORTIFY_SOURCE case:
>   freq:0.20 size:  3 time:2.43 __printf_chk (1, "Object code generation not
> active! Forgot to call quantum_objcode_start?\n");
> 
> vs without:
>   freq:0.20 size:  2 time:2.23 puts (&"Object code generation not active!
> Forgot to call quantum_objcode_start?"[0]);

But I have never seen this '_FORTIFY_SOURCE' before. So I'm a confused as well.
And when I try gcc@11.4 built in the default ubuntu 22.04, it's the same. So I
don't know how to describe now. Thanks for your help anyway.

^ permalink raw reply	[flat|nested] 14+ messages in thread

* [Bug ipa/111672] Inappropriate function splitting during pass_split_functions
  2023-10-03  9:41 [Bug c/111672] New: Inappropriate function splitting during pass_split_functions hkzhang455 at gmail dot com
                   ` (10 preceding siblings ...)
  2023-10-06  2:48 ` hkzhang455 at gmail dot com
@ 2023-10-06  2:59 ` pinskia at gcc dot gnu.org
  2023-10-06 16:16 ` hkzhang455 at gmail dot com
  12 siblings, 0 replies; 14+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-10-06  2:59 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111672

--- Comment #12 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to Hanke Zhang from comment #11)
> But I have never seen this '_FORTIFY_SOURCE' before. So I'm a confused as
> well. And when I try gcc@11.4 built in the default ubuntu 22.04, it's the
> same. So I don't know how to describe now. Thanks for your help anyway.

Well Ubuntu's compiler defaults to defining _FORTIFY_SOURCE while the upstream
GCC does not. Ubuntu's compiler also defaults to building PIE applications too.

^ permalink raw reply	[flat|nested] 14+ messages in thread

* [Bug ipa/111672] Inappropriate function splitting during pass_split_functions
  2023-10-03  9:41 [Bug c/111672] New: Inappropriate function splitting during pass_split_functions hkzhang455 at gmail dot com
                   ` (11 preceding siblings ...)
  2023-10-06  2:59 ` pinskia at gcc dot gnu.org
@ 2023-10-06 16:16 ` hkzhang455 at gmail dot com
  12 siblings, 0 replies; 14+ messages in thread
From: hkzhang455 at gmail dot com @ 2023-10-06 16:16 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=111672

--- Comment #13 from Hanke Zhang <hkzhang455 at gmail dot com> ---
(In reply to Andrew Pinski from comment #12)
> (In reply to Hanke Zhang from comment #11)
> > But I have never seen this '_FORTIFY_SOURCE' before. So I'm a confused as
> > well. And when I try gcc@11.4 built in the default ubuntu 22.04, it's the
> > same. So I don't know how to describe now. Thanks for your help anyway.
> 
> Well Ubuntu's compiler defaults to defining _FORTIFY_SOURCE while the
> upstream GCC does not. Ubuntu's compiler also defaults to building PIE
> applications too.

Thanks a lot. The _FORTIFY_SOURCE maybe the problem then.

^ permalink raw reply	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2023-10-06 16:16 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-10-03  9:41 [Bug c/111672] New: Inappropriate function splitting during pass_split_functions hkzhang455 at gmail dot com
2023-10-03 16:37 ` [Bug ipa/111672] " pinskia at gcc dot gnu.org
2023-10-04  2:00 ` hkzhang455 at gmail dot com
2023-10-04  2:04 ` pinskia at gcc dot gnu.org
2023-10-04  2:08 ` hkzhang455 at gmail dot com
2023-10-04  5:24 ` pinskia at gcc dot gnu.org
2023-10-04  5:25 ` pinskia at gcc dot gnu.org
2023-10-04 13:48 ` hkzhang455 at gmail dot com
2023-10-04 13:49 ` hkzhang455 at gmail dot com
2023-10-04 23:58 ` pinskia at gcc dot gnu.org
2023-10-05  0:03 ` pinskia at gcc dot gnu.org
2023-10-06  2:48 ` hkzhang455 at gmail dot com
2023-10-06  2:59 ` pinskia at gcc dot gnu.org
2023-10-06 16:16 ` hkzhang455 at gmail dot com

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).