[llvm] a3c098f - [InstCombine] Fix profile propagation in intrinsic-select.ll (#228295)

via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 1 18:57:33 PDT 2026


Author: Aiden Grossman
Date: 2026-10-02T01:57:25Z
New Revision: a3c098fec12330ec6fb7a352a56839ed9aeb082c

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

LOG: [InstCombine] Fix profile propagation in intrinsic-select.ll (#228295)

In these cases we're creating a new Select with the exact same
condition, so we can just copy the metadata.

Added: 
    

Modified: 
    llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
    llvm/test/Transforms/InstCombine/intrinsic-select.ll
    llvm/utils/profcheck-xfail.txt

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
index f95bd9d2ebbe4..071946ea13f98 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
@@ -3367,7 +3367,11 @@ Instruction *InstCombinerImpl::visitCallInst(CallInst &CI) {
                            : (isa<Constant>(TVal) && isa<Constant>(FVal))) {
         CallInst *AbsT = Builder.CreateCall(II->getCalledFunction(), {TVal});
         CallInst *AbsF = Builder.CreateCall(II->getCalledFunction(), {FVal});
-        SelectInst *SI = SelectInst::Create(Cond, AbsT, AbsF);
+        // Given the condition is the same, we pull metadata (particularly
+        // profile metadata) from the original select instruction.
+        SelectInst *SI = SelectInst::Create(
+            Cond, AbsT, AbsF, "", nullptr,
+            ProfcheckDisableMetadataFixes ? nullptr : cast<Instruction>(Arg));
         SI->setFastMathFlags(II->getFastMathFlags() |
                              cast<SelectInst>(Arg)->getFastMathFlags());
         // Can't copy nsz to select, as even with the nsz flag the fabs result

diff  --git a/llvm/test/Transforms/InstCombine/intrinsic-select.ll b/llvm/test/Transforms/InstCombine/intrinsic-select.ll
index dfe735cdb1bba..dfd275664d06e 100644
--- a/llvm/test/Transforms/InstCombine/intrinsic-select.ll
+++ b/llvm/test/Transforms/InstCombine/intrinsic-select.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
 ; RUN: opt -passes=instcombine -S < %s | FileCheck %s
 
 declare void @use(i32)
@@ -307,16 +307,16 @@ define <2 x double> @test_fabs_select1_vec(<2 x double> %a) {
   ret <2 x double> %sel2
 }
 
-define double @test_fabs_select2(double %a) {
+define double @test_fabs_select2(double %a) !prof !0 {
 ; CHECK-LABEL: @test_fabs_select2(
 ; CHECK-NEXT:    [[ABS1:%.*]] = call double @llvm.fabs.f64(double [[A:%.*]])
 ; CHECK-NEXT:    [[CMP:%.*]] = fcmp oeq double [[ABS1]], +inf
-; CHECK-NEXT:    [[ABS2:%.*]] = select i1 [[CMP]], double 0.000000e+00, double [[ABS1]]
+; CHECK-NEXT:    [[ABS2:%.*]] = select i1 [[CMP]], double 0.000000e+00, double [[ABS1]], !prof [[PROF1:![0-9]+]]
 ; CHECK-NEXT:    ret double [[ABS2]]
 ;
   %abs1 = call double @llvm.fabs.f64(double %a)
   %cmp = fcmp oeq double %abs1, +inf
-  %sel = select i1 %cmp, double -0.000000e+00, double %abs1
+  %sel = select i1 %cmp, double -0.000000e+00, double %abs1, !prof !1
   %abs2 = call double @llvm.fabs.f64(double %sel)
   ret double %abs2
 }
@@ -685,3 +685,9 @@ define i32 @select_of_abs(i1 %cond, i32 %x, i32 %y) {
   %sel = select i1 %cond, i32 %abs1, i32 %abs2
   ret i32 %sel
 }
+
+!0 = !{!"function_entry_count", i32 10}
+!1 = !{!"branch_weights", i32 2, i32 3}
+;.
+; CHECK: [[PROF1]] = !{!"branch_weights", i32 2, i32 3}
+;.

diff  --git a/llvm/utils/profcheck-xfail.txt b/llvm/utils/profcheck-xfail.txt
index 49ae32314c926..5beac19c039d5 100644
--- a/llvm/utils/profcheck-xfail.txt
+++ b/llvm/utils/profcheck-xfail.txt
@@ -37,7 +37,6 @@ Transforms/InstCombine/ffs-1.ll
 Transforms/InstCombine/ffs-i16.ll
 Transforms/InstCombine/fmul.ll
 Transforms/InstCombine/fneg.ll
-Transforms/InstCombine/intrinsic-select.ll
 Transforms/InstCombine/ldexp-ext.ll
 Transforms/InstCombine/ldexp.ll
 Transforms/InstCombine/logical-select.ll


        


More information about the llvm-commits mailing list