[llvm] [InstCombine][profcheck] Preserve !prof data when creating select. (PR #178484)

Snehasish Kumar via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 28 11:00:18 PST 2026


https://github.com/snehasish created https://github.com/llvm/llvm-project/pull/178484

None

>From 073772401c7f7708785479c17fb7e9ad7292c077 Mon Sep 17 00:00:00 2001
From: Snehasish Kumar <snehasishk at google.com>
Date: Wed, 28 Jan 2026 18:23:54 +0000
Subject: [PATCH] [InstCombine][profcheck] Preserve !prof data when creating
 select.

---
 .../InstCombine/InstructionCombining.cpp           |  3 ++-
 llvm/test/Transforms/InstCombine/select_frexp.ll   | 14 ++++++++++----
 2 files changed, 12 insertions(+), 5 deletions(-)

diff --git a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
index a9904f7867e94..3eeb2a551890d 100644
--- a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
@@ -4650,7 +4650,8 @@ static Value *foldFrexpOfSelect(ExtractValueInst &EV, IntrinsicInst *FrexpCall,
 
   Value *NewSel = Builder.CreateSelectFMF(
       Cond, ConstIsTrue ? ConstantMantissa : NewEV,
-      ConstIsTrue ? NewEV : ConstantMantissa, SelectInst, "select.frexp");
+      ConstIsTrue ? NewEV : ConstantMantissa, SelectInst, "select.frexp",
+      ProfcheckDisableMetadataFixes ? nullptr : SelectInst);
   return NewSel;
 }
 Instruction *InstCombinerImpl::visitExtractValueInst(ExtractValueInst &EV) {
diff --git a/llvm/test/Transforms/InstCombine/select_frexp.ll b/llvm/test/Transforms/InstCombine/select_frexp.ll
index ccfcca1fe7cb5..e2e9f31d4e6f7 100644
--- a/llvm/test/Transforms/InstCombine/select_frexp.ll
+++ b/llvm/test/Transforms/InstCombine/select_frexp.ll
@@ -10,10 +10,10 @@ define float @test_select_frexp_basic(float %x, i1 %cond) {
 ; CHECK-SAME: float [[X:%.*]], i1 [[COND:%.*]]) {
 ; CHECK-NEXT:    [[FREXP:%.*]] = call { float, i32 } @llvm.frexp.f32.i32(float [[X]])
 ; CHECK-NEXT:    [[FREXP_0:%.*]] = extractvalue { float, i32 } [[FREXP]], 0
-; CHECK-NEXT:    [[SELECT_FREXP:%.*]] = select i1 [[COND]], float 5.000000e-01, float [[FREXP_0]]
+; CHECK-NEXT:    [[SELECT_FREXP:%.*]] = select i1 [[COND]], float 5.000000e-01, float [[FREXP_0]], !prof [[PROF0:![0-9]+]]
 ; CHECK-NEXT:    ret float [[SELECT_FREXP]]
 ;
-  %sel = select i1 %cond, float 1.000000e+00, float %x
+  %sel = select i1 %cond, float 1.000000e+00, float %x, !prof !0
   %frexp = call { float, i32 } @llvm.frexp.f32.i32(float %sel)
   %frexp.0 = extractvalue { float, i32 } %frexp, 0
   ret float %frexp.0
@@ -117,10 +117,10 @@ define i32 @test_select_frexp_extract_exp(float %x, i1 %cond) {
 ; CHECK-SAME: float [[X:%.*]], i1 [[COND:%.*]]) {
 ; CHECK-NEXT:    [[FREXP:%.*]] = call { float, i32 } @llvm.frexp.f32.i32(float [[X]])
 ; CHECK-NEXT:    [[FREXP_1:%.*]] = extractvalue { float, i32 } [[FREXP]], 1
-; CHECK-NEXT:    [[FREXP_2:%.*]] = select i1 [[COND]], i32 1, i32 [[FREXP_1]]
+; CHECK-NEXT:    [[FREXP_2:%.*]] = select i1 [[COND]], i32 1, i32 [[FREXP_1]], !prof [[PROF0]]
 ; CHECK-NEXT:    ret i32 [[FREXP_2]]
 ;
-  %sel = select i1 %cond, float 1.000000e+00, float %x
+  %sel = select i1 %cond, float 1.000000e+00, float %x, !prof !0
   %frexp = call { float, i32 } @llvm.frexp.f32.i32(float %sel)
   %frexp.1 = extractvalue { float, i32 } %frexp, 1
   ret i32 %frexp.1
@@ -187,5 +187,11 @@ define <vscale x 2 x float> @test_select_frexp_scalable_vec1(<vscale x 2 x float
   ret <vscale x 2 x float> %frexp.0
 }
 
+
 declare { <2 x float>, <2 x i32> } @llvm.frexp.v2f32.v2i32(<2 x float>)
 declare { <vscale x 2 x float>, <vscale x 2 x i32> } @llvm.frexp.nxv2f32.nxv2i32(<vscale x 2 x float>)
+
+!0 = !{!"branch_weights", i32 10, i32 20}
+;.
+; CHECK: [[PROF0]] = !{!"branch_weights", i32 10, i32 20}
+;.



More information about the llvm-commits mailing list