https://github.com/snehasish updated 
https://github.com/llvm/llvm-project/pull/179755

>From bed32f8aa6bc01badc2643e775cc782e981cb3b7 Mon Sep 17 00:00:00 2001
From: Snehasish Kumar <[email protected]>
Date: Tue, 3 Feb 2026 04:19:33 +0000
Subject: [PATCH] InstCombine: Propagate profile metadata in select(ldexp) and
 ldexp(select) folding

---
 .../lib/Transforms/InstCombine/InstCombineCalls.cpp |  5 +++++
 .../Transforms/InstCombine/InstCombineSelect.cpp    | 13 +++++++++++--
 llvm/utils/profcheck-xfail.txt                      |  1 -
 3 files changed, 16 insertions(+), 3 deletions(-)

diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp 
b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
index 7b27aac1e224b..770fc568ba753 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
@@ -3263,6 +3263,11 @@ Instruction *InstCombinerImpl::visitCallInst(CallInst 
&CI) {
       }
 
       if (NewLdexp) {
+        if (!ProfcheckDisableMetadataFixes)
+          if (auto *I = dyn_cast<Instruction>(Select)) {
+            setExplicitlyUnknownBranchWeightsIfProfiled(*I, DEBUG_TYPE, &F);
+            I->copyMetadata(*II);
+          }
         Select->takeName(II);
         return replaceInstUsesWith(*II, Select);
       }
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp 
b/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
index c814b1e35c753..8c6bcc9454869 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineSelect.cpp
@@ -393,8 +393,17 @@ Instruction *InstCombinerImpl::foldSelectOpOp(SelectInst 
&SI, Instruction *TI,
           FMF &= cast<FPMathOperator>(FII)->getFastMathFlags();
           FMF |= SelectFPOp->getFastMathFlags();
 
-          Value *SelectVal = Builder.CreateSelect(Cond, LdexpVal0, LdexpVal1);
-          Value *SelectExp = Builder.CreateSelect(Cond, LdexpExp0, LdexpExp1);
+          Value *SelectVal;
+          Value *SelectExp;
+          if (!ProfcheckDisableMetadataFixes) {
+            SelectVal = Builder.CreateSelect(Cond, LdexpVal0, LdexpVal1,
+                                             "ldexp.val", &SI);
+            SelectExp = Builder.CreateSelect(Cond, LdexpExp0, LdexpExp1,
+                                             "ldexp.exp", &SI);
+          } else {
+            SelectVal = Builder.CreateSelect(Cond, LdexpVal0, LdexpVal1);
+            SelectExp = Builder.CreateSelect(Cond, LdexpExp0, LdexpExp1);
+          }
 
           CallInst *NewLdexp = Builder.CreateIntrinsic(
               TII->getType(), Intrinsic::ldexp, {SelectVal, SelectExp});
diff --git a/llvm/utils/profcheck-xfail.txt b/llvm/utils/profcheck-xfail.txt
index 2b56982729eea..85cb131f81824 100644
--- a/llvm/utils/profcheck-xfail.txt
+++ b/llvm/utils/profcheck-xfail.txt
@@ -220,7 +220,6 @@ Transforms/InstCombine/div-shift.ll
 Transforms/InstCombine/fcmp-select.ll
 Transforms/InstCombine/ffs-i16.ll
 Transforms/InstCombine/intrinsic-select.ll
-Transforms/InstCombine/ldexp.ll
 Transforms/InstCombine/load-bitcast-select.ll
 Transforms/InstCombine/load.ll
 Transforms/InstCombine/load-select.ll

_______________________________________________
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits

Reply via email to