Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix assertion of null pointer samples in inline replay mode #99378

Merged
merged 2 commits into from
Jul 18, 2024

Conversation

wlei-llvm
Copy link
Contributor

Fix #97108. In inline replay mode, CalleeSamples may be null and the order doesn't matter.

@llvmbot llvmbot added PGO Profile Guided Optimizations llvm:transforms labels Jul 17, 2024
@llvmbot
Copy link
Collaborator

llvmbot commented Jul 17, 2024

@llvm/pr-subscribers-llvm-transforms

@llvm/pr-subscribers-pgo

Author: Lei Wang (wlei-llvm)

Changes

Fix #97108. In inline replay mode, CalleeSamples may be null and the order doesn't matter.


Full diff: https://github.com/llvm/llvm-project/pull/99378.diff

1 Files Affected:

  • (modified) llvm/lib/Transforms/IPO/SampleProfile.cpp (+4-1)
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())

Comment on lines 442 to 445
// In inline replay mode, CalleeSamples may be null and the order doesn't
// matter.
if (!LCS || !RCS)
return false;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we should give a deterministic order when only one side is null. With the current change, "non-null" vs "null" and "null" vs "non-null" both are false..

Copy link
Member

@WenleiHe WenleiHe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm, thanks.

@wlei-llvm wlei-llvm merged commit ce8c43f into llvm:main Jul 18, 2024
7 checks passed
@wlei-llvm wlei-llvm deleted the fix-null-sample branch July 18, 2024 17:16
Harini0924 pushed a commit to Harini0924/llvm-project that referenced this pull request Jul 22, 2024
Fix llvm#97108. In inline replay
mode, `CalleeSamples` may be null and the order doesn't matter.
sgundapa pushed a commit to sgundapa/upstream_effort that referenced this pull request Jul 23, 2024
Fix llvm#97108. In inline replay
mode, `CalleeSamples` may be null and the order doesn't matter.
yuxuanchen1997 pushed a commit that referenced this pull request Jul 25, 2024
Summary:
Fix #97108. In inline replay
mode, `CalleeSamples` may be null and the order doesn't matter.

Test Plan: 

Reviewers: 

Subscribers: 

Tasks: 

Tags: 


Differential Revision: https://phabricator.intern.facebook.com/D60250889
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
llvm:transforms PGO Profile Guided Optimizations
Projects
None yet
Development

Successfully merging this pull request may close these issues.

llvm/test/Transforms/SampleProfile/csspgo-import-list.ll fails in -DLLVM_ENABLE_EXPENSIVE_CHECKS=on builds
4 participants