Skip to content

Conversation

@mtrofin
Copy link
Member

@mtrofin mtrofin commented Nov 10, 2025

We don't have enough information to infer the probability of a weak function pointer being nullptr or not (open question if we could propagate this from the linker)

Issue #147390

Copy link
Member Author

mtrofin commented Nov 10, 2025

This stack of pull requests is managed by Graphite. Learn more about stacking.

@github-actions
Copy link

github-actions bot commented Nov 10, 2025

✅ With the latest revision this PR passed the C/C++ code formatter.

@mtrofin mtrofin marked this pull request as ready for review November 10, 2025 22:57
@mtrofin mtrofin requested a review from pcc November 10, 2025 22:57
@llvmbot
Copy link
Member

llvmbot commented Nov 10, 2025

@llvm/pr-subscribers-llvm-transforms

Author: Mircea Trofin (mtrofin)

Changes

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

2 Files Affected:

  • (modified) llvm/lib/Transforms/IPO/LowerTypeTests.cpp (+3)
  • (modified) llvm/test/Transforms/LowerTypeTests/function-weak.ll (+3-2)
diff --git a/llvm/lib/Transforms/IPO/LowerTypeTests.cpp b/llvm/lib/Transforms/IPO/LowerTypeTests.cpp
index 961a2ba2f58e5..6c5045f7c84ff 100644
--- a/llvm/lib/Transforms/IPO/LowerTypeTests.cpp
+++ b/llvm/lib/Transforms/IPO/LowerTypeTests.cpp
@@ -1494,6 +1494,9 @@ void LowerTypeTestsModule::replaceWeakDeclarationWithJumpTablePtr(
                                      Constant::getNullValue(F->getType()));
     Value *Select = Builder.CreateSelect(ICmp, JT,
                                          Constant::getNullValue(F->getType()));
+    
+    if (auto *SI = dyn_cast<SelectInst>(Select))
+      setExplicitlyUnknownBranchWeightsIfProfiled(*SI, DEBUG_TYPE);
     // For phi nodes, we need to update the incoming value for all operands
     // with the same predecessor.
     if (PN)
diff --git a/llvm/test/Transforms/LowerTypeTests/function-weak.ll b/llvm/test/Transforms/LowerTypeTests/function-weak.ll
index 4ea03b6c2c1fa..dbbe8fa4a0a9a 100644
--- a/llvm/test/Transforms/LowerTypeTests/function-weak.ll
+++ b/llvm/test/Transforms/LowerTypeTests/function-weak.ll
@@ -32,10 +32,10 @@ target triple = "x86_64-unknown-linux-gnu"
 declare !type !0 extern_weak void @f()
 
 ; CHECK: define zeroext i1 @check_f()
-define zeroext i1 @check_f() {
+define zeroext i1 @check_f() !prof !{!"function_entry_count", i32 10} {
 entry:
 ; CHECK: [[CMP:%.*]] = icmp ne ptr @f, null
-; CHECK: [[SEL:%.*]] = select i1 [[CMP]], ptr @[[JT:.*]], ptr null
+; CHECK: [[SEL:%.*]] = select i1 [[CMP]], ptr @[[JT:.*]], ptr null, !prof ![[SELPROF:[0-9]+]]
 ; CHECK: [[PTI:%.*]] = ptrtoint ptr [[SEL]] to i1
 ; CHECK: ret i1 [[PTI]]
   ret i1 ptrtoint (ptr @f to i1)
@@ -165,3 +165,4 @@ define i1 @foo(ptr %p) {
 ; CHECK-NEXT: }
 
 !0 = !{i32 0, !"typeid1"}
+; CHECK: ![[SELPROF]] = !{!"unknown", !"lowertypetests"}
\ No newline at end of file

@mtrofin mtrofin force-pushed the users/mtrofin/11-10-_ltt_mark_as_unkown_weak_function_tests branch from 0c5994b to 660888e Compare November 10, 2025 22:58
@mtrofin mtrofin force-pushed the users/mtrofin/11-07-_ltt_profcheck_set_branch_weights_for_complex_llvm.type.test_lowering branch from a6bc19f to 2bc1823 Compare November 13, 2025 20:28
@mtrofin mtrofin force-pushed the users/mtrofin/11-10-_ltt_mark_as_unkown_weak_function_tests branch from 660888e to 473fd29 Compare November 13, 2025 20:28
@mtrofin mtrofin force-pushed the users/mtrofin/11-10-_ltt_mark_as_unkown_weak_function_tests branch from 473fd29 to e7a9788 Compare November 13, 2025 20:47
@mtrofin mtrofin force-pushed the users/mtrofin/11-07-_ltt_profcheck_set_branch_weights_for_complex_llvm.type.test_lowering branch from 2bc1823 to 9a54c8d Compare November 13, 2025 20:47
Copy link
Contributor

@teresajohnson teresajohnson left a comment

Choose a reason for hiding this comment

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

lgtm

@mtrofin mtrofin force-pushed the users/mtrofin/11-07-_ltt_profcheck_set_branch_weights_for_complex_llvm.type.test_lowering branch from 9a54c8d to 8bb5144 Compare November 15, 2025 00:30
@mtrofin mtrofin force-pushed the users/mtrofin/11-10-_ltt_mark_as_unkown_weak_function_tests branch from e7a9788 to 43a2620 Compare November 15, 2025 00:30
@mtrofin mtrofin force-pushed the users/mtrofin/11-07-_ltt_profcheck_set_branch_weights_for_complex_llvm.type.test_lowering branch from 8bb5144 to 30386f3 Compare November 15, 2025 01:32
@mtrofin mtrofin force-pushed the users/mtrofin/11-10-_ltt_mark_as_unkown_weak_function_tests branch from 43a2620 to 39c5123 Compare November 15, 2025 01:32
@mtrofin mtrofin marked this pull request as draft November 15, 2025 02:50
@mtrofin mtrofin force-pushed the users/mtrofin/11-10-_ltt_mark_as_unkown_weak_function_tests branch from 39c5123 to 1401b45 Compare November 15, 2025 17:04
@mtrofin mtrofin force-pushed the users/mtrofin/11-07-_ltt_profcheck_set_branch_weights_for_complex_llvm.type.test_lowering branch 2 times, most recently from 53e30e0 to 1ca5b00 Compare November 15, 2025 17:06
@mtrofin mtrofin force-pushed the users/mtrofin/11-10-_ltt_mark_as_unkown_weak_function_tests branch 2 times, most recently from 35aeb99 to aca5e76 Compare November 15, 2025 17:14
@mtrofin mtrofin force-pushed the users/mtrofin/11-07-_ltt_profcheck_set_branch_weights_for_complex_llvm.type.test_lowering branch from 1ca5b00 to 4ff4cc1 Compare November 15, 2025 17:14
@mtrofin mtrofin force-pushed the users/mtrofin/11-10-_ltt_mark_as_unkown_weak_function_tests branch from aca5e76 to f5a5711 Compare November 17, 2025 17:59
@mtrofin mtrofin force-pushed the users/mtrofin/11-07-_ltt_profcheck_set_branch_weights_for_complex_llvm.type.test_lowering branch from 4ff4cc1 to ea1942f Compare November 17, 2025 18:00
@mtrofin mtrofin marked this pull request as ready for review November 17, 2025 18:01
@mtrofin mtrofin changed the base branch from users/mtrofin/11-07-_ltt_profcheck_set_branch_weights_for_complex_llvm.type.test_lowering to main November 17, 2025 18:01
@mtrofin mtrofin force-pushed the users/mtrofin/11-10-_ltt_mark_as_unkown_weak_function_tests branch from f5a5711 to b4835b4 Compare November 17, 2025 18:02
@github-actions
Copy link

🐧 Linux x64 Test Results

  • 186274 tests passed
  • 4852 tests skipped

Copy link
Member Author

mtrofin commented Nov 19, 2025

Merge activity

  • Nov 19, 12:51 AM UTC: A user started a stack merge that includes this pull request via Graphite.
  • Nov 19, 12:53 AM UTC: @mtrofin merged this pull request with Graphite.

@mtrofin mtrofin merged commit 88efd0e into main Nov 19, 2025
10 checks passed
@mtrofin mtrofin deleted the users/mtrofin/11-10-_ltt_mark_as_unkown_weak_function_tests branch November 19, 2025 00:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants