[llvm] 91d7ee6 - [InstCombine] Fix profile propagation for wcslen folding (#222475)

via llvm-commits llvm-commits at lists.llvm.org
Wed Sep 9 18:56:21 PDT 2026


Author: Aiden Grossman
Date: 2026-09-09T18:56:15-07:00
New Revision: 91d7ee658c9cd67a7b95df4be51be553bfd9c549

URL: https://github.com/llvm/llvm-project/commit/91d7ee658c9cd67a7b95df4be51be553bfd9c549
DIFF: https://github.com/llvm/llvm-project/commit/91d7ee658c9cd67a7b95df4be51be553bfd9c549.diff

LOG: [InstCombine] Fix profile propagation for wcslen folding (#222475)

Added: 
    

Modified: 
    llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
    llvm/test/Transforms/InstCombine/wcslen-1.ll
    llvm/utils/profcheck-xfail.txt

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp b/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
index 80621484a1629..f2b8ac606cfc1 100644
--- a/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
+++ b/llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp
@@ -88,6 +88,10 @@ static cl::opt<bool> MinExistingHotColdNewHint(
     cl::desc("Take the minimum of compiler hint and existing hint when "
              "optimizing existing hot/cold operator new library calls"));
 
+namespace llvm {
+extern cl::opt<bool> ProfcheckDisableMetadataFixes;
+} // namespace llvm
+
 namespace {
 
 // Specialized parser to ensure the hint is an 8 bit value (we can't specify
@@ -1070,7 +1074,8 @@ Value *LibCallSimplifier::optimizeStringLength(CallInst *CI, IRBuilderBase &B,
       });
       return B.CreateSelect(SI->getCondition(),
                             ConstantInt::get(CI->getType(), LenTrue - 1),
-                            ConstantInt::get(CI->getType(), LenFalse - 1));
+                            ConstantInt::get(CI->getType(), LenFalse - 1), "",
+                            ProfcheckDisableMetadataFixes ? nullptr : SI);
     }
   }
 

diff  --git a/llvm/test/Transforms/InstCombine/wcslen-1.ll b/llvm/test/Transforms/InstCombine/wcslen-1.ll
index d7f0620ac89f1..fccda5322aaa5 100644
--- a/llvm/test/Transforms/InstCombine/wcslen-1.ll
+++ b/llvm/test/Transforms/InstCombine/wcslen-1.ll
@@ -1,4 +1,4 @@
-; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --check-globals smart
 ; Test that the wcslen library call simplifier works correctly.
 ;
 ; RUN: opt < %s -passes=instcombine -S | FileCheck %s
@@ -94,12 +94,12 @@ define i1 @test_simplify8(ptr %str_p) {
   ret i1 %ne_null
 }
 
-define i64 @test_simplify9(i1 %x) {
+define i64 @test_simplify9(i1 %x) !prof !1 {
 ; CHECK-LABEL: @test_simplify9(
-; CHECK-NEXT:    [[L:%.*]] = select i1 [[X:%.*]], i64 5, i64 6
+; CHECK-NEXT:    [[L:%.*]] = select i1 [[X:%.*]], i64 5, i64 6, !prof [[PROF2:![0-9]+]]
 ; CHECK-NEXT:    ret i64 [[L]]
 ;
-  %s = select i1 %x, ptr @hello, ptr @longer
+  %s = select i1 %x, ptr @hello, ptr @longer, !prof !2
   %l = call i64 @wcslen(ptr %s)
   ret i64 %l
 }
@@ -339,3 +339,9 @@ define i64 @no_fold_wcslen_2() {
 }
 
 attributes #0 = { null_pointer_is_valid }
+
+!1 = !{!"function_entry_count", i32 10}
+!2 = !{!"branch_weights", i32 2, i32 3}
+;.
+; CHECK: [[PROF2]] = !{!"branch_weights", i32 2, i32 3}
+;.

diff  --git a/llvm/utils/profcheck-xfail.txt b/llvm/utils/profcheck-xfail.txt
index 0693d35591c8f..2014275cb89fc 100644
--- a/llvm/utils/profcheck-xfail.txt
+++ b/llvm/utils/profcheck-xfail.txt
@@ -80,8 +80,6 @@ Transforms/InstCombine/strlen-1.ll
 Transforms/InstCombine/strrchr-3.ll
 Transforms/InstCombine/truncating-saturate.ll
 Transforms/InstCombine/unordered-fcmp-select.ll
-Transforms/InstCombine/wcslen-1.ll
-Transforms/InstCombine/wcslen-3.ll
 Transforms/InstCombine/xor-and-or.ll
 Transforms/InstCombine/zext-bool-add-sub.ll
 Transforms/LoopIdiom/AArch64/byte-compare-index.ll


        


More information about the llvm-commits mailing list