[llvm] Fix assertion of null pointer samples in inline replay mode (PR #99378)

Lei Wang via llvm-commits llvm-commits at lists.llvm.org
Wed Jul 17 22:40:57 PDT 2024


https://github.com/wlei-llvm updated https://github.com/llvm/llvm-project/pull/99378

>From 318f8ed15053ff9178c8f2ddaff4ae4e5fe83bea Mon Sep 17 00:00:00 2001
From: wlei <wlei at fb.com>
Date: Mon, 8 Jul 2024 17:22:23 -0700
Subject: [PATCH 1/2] Fix assertion of null pointer samples in inline replay
 mode

---
 llvm/lib/Transforms/IPO/SampleProfile.cpp | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/llvm/lib/Transforms/IPO/SampleProfile.cpp b/llvm/lib/Transforms/IPO/SampleProfile.cpp
index 5cc2911a1a80e..b43fde3d4e086 100644
--- a/llvm/lib/Transforms/IPO/SampleProfile.cpp
+++ b/llvm/lib/Transforms/IPO/SampleProfile.cpp
@@ -439,7 +439,10 @@ struct CandidateComparer {
 
     const FunctionSamples *LCS = LHS.CalleeSamples;
     const FunctionSamples *RCS = RHS.CalleeSamples;
-    assert(LCS && RCS && "Expect non-null FunctionSamples");
+    // In inline replay mode, CalleeSamples may be null and the order doesn't
+    // matter.
+    if (!LCS || !RCS)
+      return false;
 
     // Tie breaker using number of samples try to favor smaller functions first
     if (LCS->getBodySamples().size() != RCS->getBodySamples().size())

>From 68d843fbd4ebe37b8d5c750dab2a8e50d1b7f92a Mon Sep 17 00:00:00 2001
From: wlei <wlei at fb.com>
Date: Wed, 17 Jul 2024 22:39:02 -0700
Subject: [PATCH 2/2] handle null vs non-null or non-null vs null case

---
 llvm/lib/Transforms/IPO/SampleProfile.cpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/llvm/lib/Transforms/IPO/SampleProfile.cpp b/llvm/lib/Transforms/IPO/SampleProfile.cpp
index b43fde3d4e086..6af284d513efc 100644
--- a/llvm/lib/Transforms/IPO/SampleProfile.cpp
+++ b/llvm/lib/Transforms/IPO/SampleProfile.cpp
@@ -442,7 +442,7 @@ struct CandidateComparer {
     // In inline replay mode, CalleeSamples may be null and the order doesn't
     // matter.
     if (!LCS || !RCS)
-      return false;
+      return LCS;
 
     // Tie breaker using number of samples try to favor smaller functions first
     if (LCS->getBodySamples().size() != RCS->getBodySamples().size())



More information about the llvm-commits mailing list