Skip to content

Conversation

@DataCorrupted
Copy link
Member

When building our internal code, one of the function annotated with co_await (c++20) will cause inconsistancy: The function exists in CG but not FunctionLevels.

This patch fixes it by using FunctionLevels only.

When building our internal code, one of the function annotated with `co_await` (c++20) will cause inconsistancy:
The function exists in CG but not FunctionLevels.

This patch fixes it by using FunctionLevels only.

Signed-off-by: Peter Rong <[email protected]>
@DataCorrupted DataCorrupted self-assigned this Jan 14, 2025
@llvmbot llvmbot added mlgo llvm:analysis Includes value tracking, cost tables and constant folding labels Jan 14, 2025
@llvmbot
Copy link
Member

llvmbot commented Jan 14, 2025

@llvm/pr-subscribers-llvm-analysis

Author: Peter Rong (DataCorrupted)

Changes

When building our internal code, one of the function annotated with co_await (c++20) will cause inconsistancy: The function exists in CG but not FunctionLevels.

This patch fixes it by using FunctionLevels only.


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

1 Files Affected:

  • (modified) llvm/lib/Analysis/MLInlineAdvisor.cpp (+3-1)
diff --git a/llvm/lib/Analysis/MLInlineAdvisor.cpp b/llvm/lib/Analysis/MLInlineAdvisor.cpp
index 2db58d1c2578bf..68d8f794d23897 100644
--- a/llvm/lib/Analysis/MLInlineAdvisor.cpp
+++ b/llvm/lib/Analysis/MLInlineAdvisor.cpp
@@ -189,7 +189,9 @@ MLInlineAdvisor::MLInlineAdvisor(
 }
 
 unsigned MLInlineAdvisor::getInitialFunctionLevel(const Function &F) const {
-  return CG.lookup(F) ? FunctionLevels.at(CG.lookup(F)) : 0;
+  return FunctionLevels.find(CG.lookup(F)) != FunctionLevels.end()
+             ? FunctionLevels.at(CG.lookup(F))
+             : 0;
 }
 
 void MLInlineAdvisor::onPassEntry(LazyCallGraph::SCC *CurSCC) {

@llvmbot
Copy link
Member

llvmbot commented Jan 14, 2025

@llvm/pr-subscribers-mlgo

Author: Peter Rong (DataCorrupted)

Changes

When building our internal code, one of the function annotated with co_await (c++20) will cause inconsistancy: The function exists in CG but not FunctionLevels.

This patch fixes it by using FunctionLevels only.


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

1 Files Affected:

  • (modified) llvm/lib/Analysis/MLInlineAdvisor.cpp (+3-1)
diff --git a/llvm/lib/Analysis/MLInlineAdvisor.cpp b/llvm/lib/Analysis/MLInlineAdvisor.cpp
index 2db58d1c2578bf..68d8f794d23897 100644
--- a/llvm/lib/Analysis/MLInlineAdvisor.cpp
+++ b/llvm/lib/Analysis/MLInlineAdvisor.cpp
@@ -189,7 +189,9 @@ MLInlineAdvisor::MLInlineAdvisor(
 }
 
 unsigned MLInlineAdvisor::getInitialFunctionLevel(const Function &F) const {
-  return CG.lookup(F) ? FunctionLevels.at(CG.lookup(F)) : 0;
+  return FunctionLevels.find(CG.lookup(F)) != FunctionLevels.end()
+             ? FunctionLevels.at(CG.lookup(F))
+             : 0;
 }
 
 void MLInlineAdvisor::onPassEntry(LazyCallGraph::SCC *CurSCC) {

Copy link
Contributor

@boomanaiden154 boomanaiden154 left a comment

Choose a reason for hiding this comment

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

How difficult is it to construct a regression test for this?

@DataCorrupted
Copy link
Member Author

DataCorrupted commented Jan 14, 2025

How difficult is it to construct a regression test for this?

I'm happy to, but I've spent a few hours trying to create one with no luck. I don't have enough understanding of co_await nor CG to understand the root cause of the inconsistency. It appears that there will be a cleanup function that exists in CG but not FunctionLevels. Any hints?

@boomanaiden154
Copy link
Contributor

Any hints?

Have you tried llvm-reduce yet? I would probably take the translation unit/ThinLTO backend action where this is occurring, extract the bitcode/textual IR, and then run llvm-reduce over it. I would guess that gives you a much smaller test case that you can then play around with.

@DataCorrupted
Copy link
Member Author

I put the task as low priority and after three month the file that used to trigger the error compiles fine now.

Maybe it's because we moved from LLVM 17 -> 19, maybe the file structure changed. Either way I'm closing this and won't reopen until I can spot similar bugs again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

llvm:analysis Includes value tracking, cost tables and constant folding mlgo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants