https://gcc.gnu.org/bugzilla/show_bug.cgi?id=113765
--- Comment #3 from Andi Kleen <andi-gcc at firstfloor dot org> ---
-O1 fixes it, so an easy patch would be
diff --git a/gcc/auto-profile.cc b/gcc/auto-profile.cc
index 63d0c3dc36df..180ed7a8260f 100644
--- a/gcc/auto-profile.cc
+++ b/gcc/auto-profile.cc
@@ -1758,7 +1758,7 @@ public:
bool
gate (function *) final override
{
- return flag_auto_profile;
+ return flag_auto_profile && optimize > 0;
}
unsigned int
execute (function *) final override
