[llvm] [InstCombine] Fix profile propagation in intrinsic-select.ll (PR #228295)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Oct 1 18:09:57 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-transforms
Author: Aiden Grossman (boomanaiden154)
<details>
<summary>Changes</summary>
In these cases we're creating a new Select with the exact same condition, so we can just copy the metadata.
---
Full diff: https://github.com/llvm/llvm-project/pull/228295.diff
3 Files Affected:
- (modified) llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp (+4-1)
- (modified) llvm/test/Transforms/InstCombine/intrinsic-select.ll (+10-4)
- (modified) llvm/utils/profcheck-xfail.txt (-1)
``````````diff
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
index f95bd9d2ebbe4..1258b40dc4b04 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineCalls.cpp
@@ -3367,7 +3367,10 @@ 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,
+ 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
``````````
</details>
https://github.com/llvm/llvm-project/pull/228295
More information about the llvm-commits
mailing list