diff --git a/gcc/ipa-cp.cc b/gcc/ipa-cp.cc
index c1b1f6201fd3..d68952ec8711 100644
--- a/gcc/ipa-cp.cc
+++ b/gcc/ipa-cp.cc
@@ -1443,7 +1443,18 @@ initialize_node_lattices (struct cgraph_node *node)
 						  NULL, true);
       else if (caller_count == 0)
 	{
-	  gcc_checking_assert (!opt_for_fn (node->decl, flag_toplevel_reorder));
+	  /* With -ftoplevel-reorder, a local body with no direct callers
+	     should already have been removed.  AutoFDO early-inline of a
+	     speculative call expands via gimple_ic (&target), so after all
+	     direct call edges are inlined the local can remain address-taken
+	     with unknown indirect uses; treat that as VARIABLE.  Ordinary
+	     IPA devirtualization does not need this exception: it creates
+	     speculative edges before IPA-CP, but inlines them only later, so
+	     IPA-CP still sees a direct caller.  */
+	  if (!(flag_auto_profile && flag_auto_profile_inlining
+		&& !node->can_remove_if_no_direct_calls_p (false)))
+	    gcc_checking_assert
+	      (!opt_for_fn (node->decl, flag_toplevel_reorder));
 	  variable = true;
 	}
     }
