[llvm] [InstCombine][profcheck] More fixes for missing branch data in InstCombineCompares.cpp (PR #178084)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Jan 26 16:01:47 PST 2026
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-transforms
Author: Alan Zhao (alanzhao1)
<details>
<summary>Changes</summary>
Again, these fixes are trivial as we're creating new select instructions with predicates from existing select instructions.
In this case, we create one select instruction from two existing select instructions, but since both existing select instructions have the same predicate, their profile data should be the same, so we can reuse the profile data from either instruction. Therefore, we arbitrarily reuse the profile data from the first select instruction.
Tracking issue: #<!-- -->147390
---
Full diff: https://github.com/llvm/llvm-project/pull/178084.diff
3 Files Affected:
- (modified) llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp (+6-2)
- (modified) llvm/test/Transforms/InstCombine/icmp-with-selects.ll (+20-11)
- (modified) llvm/utils/profcheck-xfail.txt (-1)
``````````diff
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
index a07af1aae94bb..25bde5be2258b 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineCompares.cpp
@@ -7833,12 +7833,16 @@ Instruction *InstCombinerImpl::visitICmpInst(ICmpInst &I) {
// Check whether comparison of TrueValues can be simplified
if (Value *Res = simplifyICmpInst(Pred, A, C, SQ)) {
Value *NewICMP = Builder.CreateICmp(Pred, B, D);
- return SelectInst::Create(Cond, Res, NewICMP);
+ return SelectInst::Create(
+ Cond, Res, NewICMP, /*NameStr=*/"", /*InsertBefore=*/nullptr,
+ ProfcheckDisableMetadataFixes ? nullptr : cast<Instruction>(Op0));
}
// Check whether comparison of FalseValues can be simplified
if (Value *Res = simplifyICmpInst(Pred, B, D, SQ)) {
Value *NewICMP = Builder.CreateICmp(Pred, A, C);
- return SelectInst::Create(Cond, NewICMP, Res);
+ return SelectInst::Create(
+ Cond, NewICMP, Res, /*NameStr=*/"", /*InsertBefore=*/nullptr,
+ ProfcheckDisableMetadataFixes ? nullptr : cast<Instruction>(Op0));
}
}
}
diff --git a/llvm/test/Transforms/InstCombine/icmp-with-selects.ll b/llvm/test/Transforms/InstCombine/icmp-with-selects.ll
index 8bf75d0052fec..2f2f63c5e9821 100644
--- a/llvm/test/Transforms/InstCombine/icmp-with-selects.ll
+++ b/llvm/test/Transforms/InstCombine/icmp-with-selects.ll
@@ -1,4 +1,4 @@
-; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 2
+; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --check-globals --version 2
; RUN: opt < %s -passes=instcombine -S | FileCheck %s
declare void @use(i32,...)
@@ -30,33 +30,33 @@ entry:
ret i1 %cmp
}
-define i1 @one_side_fold_slt(i32 %val1, i32 %val2, i32 %param, i1 %cond) {
+define i1 @one_side_fold_slt(i32 %val1, i32 %val2, i32 %param, i1 %cond) !prof !0 {
; CHECK-LABEL: define i1 @one_side_fold_slt
-; CHECK-SAME: (i32 [[VAL1:%.*]], i32 [[VAL2:%.*]], i32 [[PARAM:%.*]], i1 [[COND:%.*]]) {
+; CHECK-SAME: (i32 [[VAL1:%.*]], i32 [[VAL2:%.*]], i32 [[PARAM:%.*]], i1 [[COND:%.*]]) !prof [[PROF0:![0-9]+]] {
; CHECK-NEXT: entry:
; CHECK-NEXT: [[TMP0:%.*]] = icmp slt i32 [[VAL2]], [[VAL1]]
-; CHECK-NEXT: [[CMP:%.*]] = select i1 [[COND]], i1 [[TMP0]], i1 false
+; CHECK-NEXT: [[CMP:%.*]] = select i1 [[COND]], i1 [[TMP0]], i1 false, !prof [[PROF1:![0-9]+]]
; CHECK-NEXT: ret i1 [[CMP]]
;
entry:
- %cond1 = select i1 %cond, i32 %val1, i32 %param
- %cond6 = select i1 %cond, i32 %val2, i32 %param
+ %cond1 = select i1 %cond, i32 %val1, i32 %param, !prof !1
+ %cond6 = select i1 %cond, i32 %val2, i32 %param, !prof !1
%cmp = icmp slt i32 %cond6, %cond1
ret i1 %cmp
}
-define i1 @one_side_fold_sgt(i32 %val1, i32 %val2, i32 %param, i1 %cond) {
+define i1 @one_side_fold_sgt(i32 %val1, i32 %val2, i32 %param, i1 %cond) !prof !0 {
; CHECK-LABEL: define i1 @one_side_fold_sgt
-; CHECK-SAME: (i32 [[VAL1:%.*]], i32 [[VAL2:%.*]], i32 [[PARAM:%.*]], i1 [[COND:%.*]]) {
+; CHECK-SAME: (i32 [[VAL1:%.*]], i32 [[VAL2:%.*]], i32 [[PARAM:%.*]], i1 [[COND:%.*]]) !prof [[PROF0]] {
; CHECK-NEXT: entry:
; CHECK-NEXT: [[TMP0:%.*]] = icmp sgt i32 [[VAL2]], [[VAL1]]
; CHECK-NEXT: [[NOT_COND:%.*]] = xor i1 [[COND]], true
-; CHECK-NEXT: [[CMP:%.*]] = select i1 [[NOT_COND]], i1 [[TMP0]], i1 false
+; CHECK-NEXT: [[CMP:%.*]] = select i1 [[NOT_COND]], i1 [[TMP0]], i1 false, !prof [[PROF2:![0-9]+]]
; CHECK-NEXT: ret i1 [[CMP]]
;
entry:
- %cond1 = select i1 %cond, i32 %param, i32 %val1
- %cond6 = select i1 %cond, i32 %param, i32 %val2
+ %cond1 = select i1 %cond, i32 %param, i32 %val1, !prof !1
+ %cond6 = select i1 %cond, i32 %param, i32 %val2, !prof !1
%cmp = icmp sgt i32 %cond6, %cond1
ret i1 %cmp
}
@@ -174,3 +174,12 @@ entry:
%cmp = icmp sgt <8 x i32> %cond6, %cond1
ret <8 x i1> %cmp
}
+
+!0 = !{!"function_entry_count", i64 1000}
+!1 = !{!"branch_weights", i32 2, i32 3}
+
+;.
+; CHECK: [[PROF0]] = !{!"function_entry_count", i64 1000}
+; CHECK: [[PROF1]] = !{!"branch_weights", i32 2, i32 3}
+; CHECK: [[PROF2]] = !{!"branch_weights", i32 3, i32 2}
+;.
diff --git a/llvm/utils/profcheck-xfail.txt b/llvm/utils/profcheck-xfail.txt
index 5654de5e9872e..023c79a4a6ae2 100644
--- a/llvm/utils/profcheck-xfail.txt
+++ b/llvm/utils/profcheck-xfail.txt
@@ -249,7 +249,6 @@ Transforms/InstCombine/fmul-bool.ll
Transforms/InstCombine/fmul.ll
Transforms/InstCombine/fneg.ll
Transforms/InstCombine/icmp-mul-and.ll
-Transforms/InstCombine/icmp-with-selects.ll
Transforms/InstCombine/intrinsic-select.ll
Transforms/InstCombine/ldexp-ext.ll
Transforms/InstCombine/ldexp.ll
``````````
</details>
https://github.com/llvm/llvm-project/pull/178084
More information about the llvm-commits
mailing list