-
Notifications
You must be signed in to change notification settings - Fork 15.4k
[WholeProgramDevirt] Add check for AvailableExternal and give up icall.branch.funnel #143468
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
Merged
tianleliu
merged 5 commits into
llvm:main
from
tianleliu:AvailExternCheck4WholeProgDevirt
Jun 20, 2025
Merged
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
49b51cf
[WholeProgramDevirt] Add checking for AvailableExternal and gives up …
tianleliu 0725ff3
Fix case and simplify test file.
tianleliu fd5e7a1
Fix issue in test file.
tianleliu 14ee5ff
Postpone check in tryICallBranchFunnel and tighten condition to any AE.
tianleliu a133a21
Add detailed comment.
tianleliu File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
llvm/test/Transforms/WholeProgramDevirt/availableexternal-check.ll
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| ; RUN: opt -S -passes=wholeprogramdevirt -whole-program-visibility %s | FileCheck %s | ||
|
|
||
| ; This test is reduced from C++ code like this: | ||
| ; class A :public std::exception { | ||
| ; public: | ||
| ; A() {}; | ||
| ; const char* what () const throw () {return "A";} | ||
| ; }; | ||
| ; long test(std::exception *p) { | ||
| ; const char* ch = p->what(); | ||
| ; ...; | ||
| ; } | ||
| ; | ||
| ; Build command is "clang++ -O2 -target x86_64-unknown-linux -flto=full \ | ||
| ; -fwhole-program-vtables -static-libstdc++ -Wl,-plugin-opt=-whole-program-visibility" | ||
| ; | ||
| ; _ZTVSt9exception's visibility is 1 (Linkage Unit), and available_externally. | ||
| ; If any GV is available_externally, icall.branch.funnel should not be generated. | ||
|
|
||
| target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128" | ||
| target triple = "x86_64-unknown-linux" | ||
|
|
||
| @_ZTVSt9exception = available_externally constant { [5 x ptr] } { [5 x ptr] [ptr null, ptr null, ptr null, ptr null, ptr @_ZNKSt9exception4whatEv] }, !type !0, !type !1 | ||
| @_ZTV1A.0 = constant [5 x ptr] [ptr null, ptr null, ptr null, ptr null, ptr @_ZNK1A4whatEv], !type !3, !type !4, !type !5, !type !6 | ||
|
|
||
| declare ptr @_ZNKSt9exception4whatEv() | ||
|
|
||
| define ptr @_Z4testPSt9exception() { | ||
| %1 = load ptr, ptr null, align 8 | ||
| %2 = call i1 @llvm.type.test(ptr %1, metadata !"_ZTSSt9exception") | ||
| tail call void @llvm.assume(i1 %2) | ||
| %3 = getelementptr i8, ptr %1, i64 16 | ||
| %4 = load ptr, ptr %3, align 8 | ||
| %5 = tail call ptr %4(ptr null) | ||
| ret ptr %5 | ||
| } | ||
|
|
||
| ; Function Attrs: nocallback nofree nosync nounwind willreturn memory(inaccessiblemem: write) | ||
| declare void @llvm.assume(i1 noundef) #0 | ||
|
|
||
| declare ptr @_ZNK1A4whatEv() | ||
|
|
||
| ; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none) | ||
| declare i1 @llvm.type.test(ptr, metadata) #1 | ||
|
|
||
| ; CHECK-NOT: call void (...) @llvm.icall.branch.funnel | ||
|
|
||
| attributes #0 = { nocallback nofree nosync nounwind willreturn memory(inaccessiblemem: write) } | ||
| attributes #1 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) } | ||
|
|
||
| !0 = !{i64 16, !"_ZTSSt9exception"} | ||
| !1 = !{i64 32, !"_ZTSMSt9exceptionKDoFPKcvE.virtual"} | ||
| !3 = !{i32 16, !"_ZTS1A"} | ||
| !4 = !{i32 32, !"_ZTSM1AKDoFPKcvE.virtual"} | ||
| !5 = !{i32 16, !"_ZTSSt9exception"} | ||
| !6 = !{i32 32, !"_ZTSMSt9exceptionKDoFPKcvE.virtual"} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change "drop to generate" to "do not generate". Also, please add a note that this avoids a crash in LowerTypeTest due to the GV being dropped resulting in a null GlobalTypeMember.