public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug gcov-profile/112806] New: Profile-Guided Optimization (PGO) policy regarding explicit user optimization hint behavior
@ 2023-12-01  9:15 zamazan4ik at tut dot by
  2023-12-01  9:20 ` [Bug gcov-profile/112806] " pinskia at gcc dot gnu.org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: zamazan4ik at tut dot by @ 2023-12-01  9:15 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 112806
           Summary: Profile-Guided Optimization (PGO) policy regarding
                    explicit user optimization hint behavior
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: gcov-profile
          Assignee: unassigned at gcc dot gnu.org
          Reporter: zamazan4ik at tut dot by
                CC: marxin at gcc dot gnu.org
  Target Milestone: ---

Hi!

Right now there is no documentation for the behavior of PGO in the presence of
user-provided optimization hints. It would be good to document how GCC's PGO
implementation handles conflicts between the hints the user explicitly wrote in
their code and the profile they're optimizing against. For example, how do the
following (non-exhaustive) hints behave: [[likely]] and other optimization
attributes, register or inline use, __builtin_expect, etc.

This will help to set user expectations - some users expect explicit
optimization hints to be ignored by PGO while other users assume the hints are
still honored (at least sometimes). If hints are honored, they should be
clearly documented as doing so if that behavior is intentional.

Similar issue in LLVM: https://github.com/llvm/llvm-project/issues/58189

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

* [Bug gcov-profile/112806] Profile-Guided Optimization (PGO) policy regarding explicit user optimization hint behavior
  2023-12-01  9:15 [Bug gcov-profile/112806] New: Profile-Guided Optimization (PGO) policy regarding explicit user optimization hint behavior zamazan4ik at tut dot by
@ 2023-12-01  9:20 ` pinskia at gcc dot gnu.org
  2023-12-01  9:20 ` pinskia at gcc dot gnu.org
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-12-01  9:20 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
[[likely]]/__builtin_expect is kinda of documented:

https://gcc.gnu.org/onlinedocs/gcc-13.2.0/gcc/Other-Builtins.html#index-fprofile-arcs-1

Everything else is just a hint.

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

* [Bug gcov-profile/112806] Profile-Guided Optimization (PGO) policy regarding explicit user optimization hint behavior
  2023-12-01  9:15 [Bug gcov-profile/112806] New: Profile-Guided Optimization (PGO) policy regarding explicit user optimization hint behavior zamazan4ik at tut dot by
  2023-12-01  9:20 ` [Bug gcov-profile/112806] " pinskia at gcc dot gnu.org
@ 2023-12-01  9:20 ` pinskia at gcc dot gnu.org
  2023-12-01  9:25 ` zamazan4ik at tut dot by
  2023-12-01 10:38 ` rguenth at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-12-01  9:20 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to Andrew Pinski from comment #1)
> [[likely]]/__builtin_expect is kinda of documented:
> 
> https://gcc.gnu.org/onlinedocs/gcc-13.2.0/gcc/Other-Builtins.html#index-
> fprofile-arcs-1
> 
> Everything else is just a hint.

I should say a hint and mostly ignored.

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

* [Bug gcov-profile/112806] Profile-Guided Optimization (PGO) policy regarding explicit user optimization hint behavior
  2023-12-01  9:15 [Bug gcov-profile/112806] New: Profile-Guided Optimization (PGO) policy regarding explicit user optimization hint behavior zamazan4ik at tut dot by
  2023-12-01  9:20 ` [Bug gcov-profile/112806] " pinskia at gcc dot gnu.org
  2023-12-01  9:20 ` pinskia at gcc dot gnu.org
@ 2023-12-01  9:25 ` zamazan4ik at tut dot by
  2023-12-01 10:38 ` rguenth at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: zamazan4ik at tut dot by @ 2023-12-01  9:25 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Alexander Zaitsev <zamazan4ik at tut dot by> ---
> https://gcc.gnu.org/onlinedocs/gcc-13.2.0/gcc/Other-Builtins.html#index-fprofile-arcs-1

I already read this and still do not understand the actual behavior. If PGO
profiles show that the branch is "cold" but a user write for this branch via
__builtin_expect/[[likely]] that the branch is "hot" - what decision will be
made by the optimizer?

On the link above there is only "In general, you should prefer to use actual
profile feedback for this (-fprofile-arcs), as programmers are notoriously bad
at predicting how their programs actually perform.". But it does not specify
the actual behavior - it's just a recommendation to use PGO instead of manual
[[likely]] hints.

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

* [Bug gcov-profile/112806] Profile-Guided Optimization (PGO) policy regarding explicit user optimization hint behavior
  2023-12-01  9:15 [Bug gcov-profile/112806] New: Profile-Guided Optimization (PGO) policy regarding explicit user optimization hint behavior zamazan4ik at tut dot by
                   ` (2 preceding siblings ...)
  2023-12-01  9:25 ` zamazan4ik at tut dot by
@ 2023-12-01 10:38 ` rguenth at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: rguenth at gcc dot gnu.org @ 2023-12-01 10:38 UTC (permalink / raw)
  To: gcc-bugs

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

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |hubicka at gcc dot gnu.org
            Version|unknown                     |14.0

--- Comment #4 from Richard Biener <rguenth at gcc dot gnu.org> ---
I think it depends on whether the code was executed at all during training
dependent on -fprofile-partial-training which does regular profile guessing
for untrained parts of the program.

In general the situation is complicated and it's difficult to document
behavior with a short description.

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

end of thread, other threads:[~2023-12-01 10:38 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-12-01  9:15 [Bug gcov-profile/112806] New: Profile-Guided Optimization (PGO) policy regarding explicit user optimization hint behavior zamazan4ik at tut dot by
2023-12-01  9:20 ` [Bug gcov-profile/112806] " pinskia at gcc dot gnu.org
2023-12-01  9:20 ` pinskia at gcc dot gnu.org
2023-12-01  9:25 ` zamazan4ik at tut dot by
2023-12-01 10:38 ` rguenth at gcc dot gnu.org

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