[llvm] 9d38eba - [InstCombine][ProfCheck] Mark unknown select profiles in sub xor fold (#191192)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Apr 9 09:06:36 PDT 2026
Author: Aiden Grossman
Date: 2026-04-09T09:06:31-07:00
New Revision: 9d38eba6e73b70030518d3ed09a01bb06b36d44b
URL: https://github.com/llvm/llvm-project/commit/9d38eba6e73b70030518d3ed09a01bb06b36d44b
DIFF: https://github.com/llvm/llvm-project/commit/9d38eba6e73b70030518d3ed09a01bb06b36d44b.diff
LOG: [InstCombine][ProfCheck] Mark unknown select profiles in sub xor fold (#191192)
Mark the weights as explicitly unknown given we cannot statically infer
the weights without value profiling due to the select being synthesized
from a binary operation.
Added:
Modified:
llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
llvm/test/Transforms/InstCombine/sub-xor-cmp.ll
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp b/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
index c781c6978b275..13edf36621f0f 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineAddSub.cpp
@@ -2663,9 +2663,9 @@ Instruction *InstCombinerImpl::visitSub(BinaryOperator &I) {
(C->getType()->getScalarSizeInBits() == 1);
};
if (m_SubXorCmp(Op0, Op1))
- return SelectInst::Create(C, Builder.CreateNeg(X), X);
+ return createSelectInstWithUnknownProfile(C, Builder.CreateNeg(X), X);
if (m_SubXorCmp(Op1, Op0))
- return SelectInst::Create(C, X, Builder.CreateNeg(X));
+ return createSelectInstWithUnknownProfile(C, X, Builder.CreateNeg(X));
}
if (Instruction *R = tryFoldInstWithCtpopWithNot(&I))
diff --git a/llvm/test/Transforms/InstCombine/sub-xor-cmp.ll b/llvm/test/Transforms/InstCombine/sub-xor-cmp.ll
index acbc29db871e8..6223e974e412c 100644
--- a/llvm/test/Transforms/InstCombine/sub-xor-cmp.ll
+++ b/llvm/test/Transforms/InstCombine/sub-xor-cmp.ll
@@ -1,11 +1,11 @@
; NOTE: Assertions have been autogenerated by utils/update_test_checks.py UTC_ARGS: --version 4
; RUN: opt < %s -passes=instcombine -S | FileCheck %s
-define i64 @sext_xor_sub(i64 %a, i1 %b) {
+define i64 @sext_xor_sub(i64 %a, i1 %b) !prof !0 {
; CHECK-LABEL: define i64 @sext_xor_sub(
-; CHECK-SAME: i64 [[A:%.*]], i1 [[B:%.*]]) {
+; CHECK-SAME: i64 [[A:%.*]], i1 [[B:%.*]]) !prof [[PROF0:![0-9]+]] {
; CHECK-NEXT: [[TMP1:%.*]] = sub i64 0, [[A]]
-; CHECK-NEXT: [[R:%.*]] = select i1 [[B]], i64 [[TMP1]], i64 [[A]]
+; CHECK-NEXT: [[R:%.*]] = select i1 [[B]], i64 [[TMP1]], i64 [[A]], !prof [[PROF1:![0-9]+]]
; CHECK-NEXT: ret i64 [[R]]
;
%c = sext i1 %b to i64
@@ -27,11 +27,11 @@ define i64 @sext_xor_sub_1(i64 %a, i1 %b) {
ret i64 %r
}
-define i64 @sext_xor_sub_2(i64 %a, i1 %b) {
+define i64 @sext_xor_sub_2(i64 %a, i1 %b) !prof !0 {
; CHECK-LABEL: define i64 @sext_xor_sub_2(
-; CHECK-SAME: i64 [[A:%.*]], i1 [[B:%.*]]) {
+; CHECK-SAME: i64 [[A:%.*]], i1 [[B:%.*]]) !prof [[PROF0]] {
; CHECK-NEXT: [[TMP1:%.*]] = sub i64 0, [[A]]
-; CHECK-NEXT: [[R:%.*]] = select i1 [[B]], i64 [[A]], i64 [[TMP1]]
+; CHECK-NEXT: [[R:%.*]] = select i1 [[B]], i64 [[A]], i64 [[TMP1]], !prof [[PROF1]]
; CHECK-NEXT: ret i64 [[R]]
;
%c = sext i1 %b to i64
@@ -201,3 +201,9 @@ define i64 @abs
diff 2(i64 %a, i64 %b) {
%res = sub i64 %may.rev, %c.ext
ret i64 %res
}
+
+!0 = !{!"function_entry_count", i64 1000}
+;.
+; CHECK: [[PROF0]] = !{!"function_entry_count", i64 1000}
+; CHECK: [[PROF1]] = !{!"unknown", !"instcombine"}
+;.
More information about the llvm-commits
mailing list