From 5234841af37d5ff0270f8c608f6f4934453cbe56 Mon Sep 17 00:00:00 2001
From: Kugan Vivekanandarajah <kvivekananda@nvidia.com>
Date: Thu, 4 Sep 2025 11:13:43 +1000
Subject: [PATCH 2/3] [AutoFDO] Check count initialization to fix ICE with
 AutoFDO

Fix ICE with AutoFDO by adding initialization check
before accessing IPA counts to avoid issues with uninitialized profile
counts in self-recursive clone processing.

gcc/ChangeLog:

2025-09-02  Kugan Vivekanandarajah  <kvivekananda@nvidia.com>

	* ipa-cp.cc (gather_count_of_non_rec_edges): Check count
	initialization before adding to total.

Signed-off-by: Kugan Vivekanandarajah <kvivekananda@nvidia.com>
---
 gcc/ipa-cp.cc | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/gcc/ipa-cp.cc b/gcc/ipa-cp.cc
index 480cf48786c..21e2983743f 100644
--- a/gcc/ipa-cp.cc
+++ b/gcc/ipa-cp.cc
@@ -4555,7 +4555,8 @@ gather_count_of_non_rec_edges (cgraph_node *node, void *data)
   gather_other_count_struct *desc = (gather_other_count_struct *) data;
   for (cgraph_edge *cs = node->callers; cs; cs = cs->next_caller)
     if (cs->caller != desc->orig && cs->caller->clone_of != desc->orig)
-      desc->other_count += cs->count.ipa ();
+      if (cs->count.ipa ().initialized_p ())
+        desc->other_count += cs->count.ipa ();
   return false;
 }
 
-- 
2.39.5 (Apple Git-154)

