[llvm] [profcheck][InstCombine] Fix missing profile data identified by not.ll test (PR #176497)
via llvm-commits
llvm-commits at lists.llvm.org
Fri Jan 16 15:37:23 PST 2026
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-ir
Author: Alan Zhao (alanzhao1)
<details>
<summary>Changes</summary>
Tracking issue: #<!-- -->147390
---
Full diff: https://github.com/llvm/llvm-project/pull/176497.diff
5 Files Affected:
- (modified) llvm/include/llvm/IR/IRBuilder.h (+4-3)
- (modified) llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp (+18-6)
- (modified) llvm/lib/Transforms/InstCombine/InstructionCombining.cpp (+3-1)
- (modified) llvm/test/Transforms/InstCombine/not.ll (+38-28)
- (modified) llvm/utils/profcheck-xfail.txt (-9)
``````````diff
diff --git a/llvm/include/llvm/IR/IRBuilder.h b/llvm/include/llvm/IR/IRBuilder.h
index 8c33f6efbe742..e515a269abc42 100644
--- a/llvm/include/llvm/IR/IRBuilder.h
+++ b/llvm/include/llvm/IR/IRBuilder.h
@@ -1738,12 +1738,13 @@ class IRBuilderBase {
}
Value *CreateLogicalOp(Instruction::BinaryOps Opc, Value *Cond1, Value *Cond2,
- const Twine &Name = "") {
+ const Twine &Name = "",
+ Instruction *MDFrom = nullptr) {
switch (Opc) {
case Instruction::And:
- return CreateLogicalAnd(Cond1, Cond2, Name);
+ return CreateLogicalAnd(Cond1, Cond2, Name, MDFrom);
case Instruction::Or:
- return CreateLogicalOr(Cond1, Cond2, Name);
+ return CreateLogicalOr(Cond1, Cond2, Name, MDFrom);
default:
break;
}
diff --git a/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp b/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
index aacb2e2a91c57..3ff79410058eb 100644
--- a/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstCombineAndOrXor.cpp
@@ -4938,11 +4938,15 @@ bool InstCombinerImpl::sinkNotIntoLogicalOp(Instruction &I) {
Builder.SetInsertPoint(*I.getInsertionPointAfterDef());
Value *NewLogicOp;
- if (IsBinaryOp)
+ if (IsBinaryOp) {
NewLogicOp = Builder.CreateBinOp(NewOpc, Op0, Op1, I.getName() + ".not");
- else
- NewLogicOp =
- Builder.CreateLogicalOp(NewOpc, Op0, Op1, I.getName() + ".not");
+ } else {
+ SelectInst *SI = cast<SelectInst>(
+ Builder.CreateLogicalOp(NewOpc, Op0, Op1, I.getName() + ".not",
+ ProfcheckDisableMetadataFixes ? nullptr : &I));
+ SI->swapProfMetadata();
+ NewLogicOp = SI;
+ }
replaceInstUsesWith(I, NewLogicOp);
// We can not just create an outer `not`, it will most likely be immediately
@@ -5020,7 +5024,11 @@ Instruction *InstCombinerImpl::foldNot(BinaryOperator &I) {
}
if (match(NotOp, m_OneUse(m_LogicalAnd(m_Not(m_Value(X)), m_Value(Y))))) {
Value *NotY = Builder.CreateNot(Y, Y->getName() + ".not");
- return SelectInst::Create(X, ConstantInt::getTrue(Ty), NotY);
+ SelectInst *SI = SelectInst::Create(
+ X, ConstantInt::getTrue(Ty), NotY, "", nullptr,
+ ProfcheckDisableMetadataFixes ? nullptr : cast<Instruction>(NotOp));
+ SI->swapProfMetadata();
+ return SI;
}
// ~(~X | Y) --> (X & ~Y)
@@ -5031,7 +5039,11 @@ Instruction *InstCombinerImpl::foldNot(BinaryOperator &I) {
}
if (match(NotOp, m_OneUse(m_LogicalOr(m_Not(m_Value(X)), m_Value(Y))))) {
Value *NotY = Builder.CreateNot(Y, Y->getName() + ".not");
- return SelectInst::Create(X, NotY, ConstantInt::getFalse(Ty));
+ SelectInst *SI = SelectInst::Create(
+ X, NotY, ConstantInt::getFalse(Ty), "", nullptr,
+ ProfcheckDisableMetadataFixes ? nullptr : cast<Instruction>(NotOp));
+ SI->swapProfMetadata();
+ return SI;
}
// Is this a 'not' (~) fed by a binary operator?
diff --git a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
index a23d121ace0a3..229f0c01a0e42 100644
--- a/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
+++ b/llvm/lib/Transforms/InstCombine/InstructionCombining.cpp
@@ -3033,7 +3033,9 @@ Value *InstCombiner::getFreelyInvertedImpl(Value *V, bool WillInvertAllUses,
if (auto *II = dyn_cast<IntrinsicInst>(V))
return Builder->CreateBinaryIntrinsic(
getInverseMinMaxIntrinsic(II->getIntrinsicID()), NotA, NotB);
- return Builder->CreateSelect(Cond, NotA, NotB);
+ return Builder->CreateSelect(
+ Cond, NotA, NotB, "",
+ ProfcheckDisableMetadataFixes ? nullptr : cast<Instruction>(V));
}
return NonNull;
}
diff --git a/llvm/test/Transforms/InstCombine/not.ll b/llvm/test/Transforms/InstCombine/not.ll
index 1acf55a50208d..a459dc1ef8b7f 100644
--- a/llvm/test/Transforms/InstCombine/not.ll
+++ b/llvm/test/Transforms/InstCombine/not.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
; RUN: opt < %s -passes=instcombine -S | FileCheck %s
declare void @use1(i1)
@@ -481,58 +481,58 @@ define i1 @not_select_bool(i1 %x, i1 %y, i1 %z) {
ret i1 %r
}
-define i1 @not_select_bool_const1(i1 %x, i1 %y) {
+define i1 @not_select_bool_const1(i1 %x, i1 %y) !prof !0 {
; CHECK-LABEL: @not_select_bool_const1(
; CHECK-NEXT: [[Y_NOT:%.*]] = xor i1 [[Y:%.*]], true
-; CHECK-NEXT: [[R:%.*]] = select i1 [[X:%.*]], i1 [[Y_NOT]], i1 false
+; CHECK-NEXT: [[R:%.*]] = select i1 [[X:%.*]], i1 [[Y_NOT]], i1 false, !prof [[PROF1:![0-9]+]]
; CHECK-NEXT: ret i1 [[R]]
;
- %sel = select i1 %x, i1 %y, i1 true
+ %sel = select i1 %x, i1 %y, i1 true, !prof !1
%r = xor i1 %sel, true
ret i1 %r
}
-define i1 @not_select_bool_const2(i1 %x, i1 %y) {
+define i1 @not_select_bool_const2(i1 %x, i1 %y) !prof !0 {
; CHECK-LABEL: @not_select_bool_const2(
-; CHECK-NEXT: [[SEL:%.*]] = select i1 [[X:%.*]], i1 [[Y:%.*]], i1 false
+; CHECK-NEXT: [[SEL:%.*]] = select i1 [[X:%.*]], i1 [[Y:%.*]], i1 false, !prof [[PROF1]]
; CHECK-NEXT: [[R:%.*]] = xor i1 [[SEL]], true
; CHECK-NEXT: ret i1 [[R]]
;
- %sel = select i1 %x, i1 %y, i1 false
+ %sel = select i1 %x, i1 %y, i1 false, !prof !1
%r = xor i1 %sel, true
ret i1 %r
}
-define i1 @not_select_bool_const3(i1 %x, i1 %y) {
+define i1 @not_select_bool_const3(i1 %x, i1 %y) !prof !0 {
; CHECK-LABEL: @not_select_bool_const3(
-; CHECK-NEXT: [[SEL:%.*]] = select i1 [[X:%.*]], i1 true, i1 [[Y:%.*]]
+; CHECK-NEXT: [[SEL:%.*]] = select i1 [[X:%.*]], i1 true, i1 [[Y:%.*]], !prof [[PROF1]]
; CHECK-NEXT: [[R:%.*]] = xor i1 [[SEL]], true
; CHECK-NEXT: ret i1 [[R]]
;
- %sel = select i1 %x, i1 true, i1 %y
+ %sel = select i1 %x, i1 true, i1 %y, !prof !1
%r = xor i1 %sel, true
ret i1 %r
}
-define i1 @not_select_bool_const4(i1 %x, i1 %y) {
+define i1 @not_select_bool_const4(i1 %x, i1 %y) !prof !0 {
; CHECK-LABEL: @not_select_bool_const4(
; CHECK-NEXT: [[Y_NOT:%.*]] = xor i1 [[Y:%.*]], true
-; CHECK-NEXT: [[R:%.*]] = select i1 [[X:%.*]], i1 true, i1 [[Y_NOT]]
+; CHECK-NEXT: [[R:%.*]] = select i1 [[X:%.*]], i1 true, i1 [[Y_NOT]], !prof [[PROF1]]
; CHECK-NEXT: ret i1 [[R]]
;
- %sel = select i1 %x, i1 false, i1 %y
+ %sel = select i1 %x, i1 false, i1 %y, !prof !1
%r = xor i1 %sel, true
ret i1 %r
}
-define <2 x i1> @not_logicalAnd_not_op0(<2 x i1> %x, <2 x i1> %y) {
+define <2 x i1> @not_logicalAnd_not_op0(<2 x i1> %x, <2 x i1> %y) !prof !0{
; CHECK-LABEL: @not_logicalAnd_not_op0(
; CHECK-NEXT: [[Y_NOT:%.*]] = xor <2 x i1> [[Y:%.*]], splat (i1 true)
-; CHECK-NEXT: [[NOTAND:%.*]] = select <2 x i1> [[X:%.*]], <2 x i1> splat (i1 true), <2 x i1> [[Y_NOT]]
+; CHECK-NEXT: [[NOTAND:%.*]] = select <2 x i1> [[X:%.*]], <2 x i1> splat (i1 true), <2 x i1> [[Y_NOT]], !prof [[PROF2:![0-9]+]]
; CHECK-NEXT: ret <2 x i1> [[NOTAND]]
;
%notx = xor <2 x i1> %x, <i1 true, i1 true>
- %and = select <2 x i1> %notx, <2 x i1> %y, <2 x i1> zeroinitializer
+ %and = select <2 x i1> %notx, <2 x i1> %y, <2 x i1> zeroinitializer, !prof !1
%notand = xor <2 x i1> %and, <i1 true, i1 true>
ret <2 x i1> %notand
}
@@ -581,14 +581,14 @@ define i1 @not_logicalAnd_not_op0_use2(i1 %x, i1 %y) {
ret i1 %notand
}
-define <2 x i1> @not_logicalOr_not_op0(<2 x i1> %x, <2 x i1> %y) {
+define <2 x i1> @not_logicalOr_not_op0(<2 x i1> %x, <2 x i1> %y) !prof !0 {
; CHECK-LABEL: @not_logicalOr_not_op0(
; CHECK-NEXT: [[Y_NOT:%.*]] = xor <2 x i1> [[Y:%.*]], splat (i1 true)
-; CHECK-NEXT: [[NOTOR:%.*]] = select <2 x i1> [[X:%.*]], <2 x i1> [[Y_NOT]], <2 x i1> zeroinitializer
+; CHECK-NEXT: [[NOTOR:%.*]] = select <2 x i1> [[X:%.*]], <2 x i1> [[Y_NOT]], <2 x i1> zeroinitializer, !prof [[PROF2]]
; CHECK-NEXT: ret <2 x i1> [[NOTOR]]
;
%notx = xor <2 x i1> %x, <i1 true, i1 true>
- %or = select <2 x i1> %notx, <2 x i1> <i1 true, i1 true>, <2 x i1> %y
+ %or = select <2 x i1> %notx, <2 x i1> <i1 true, i1 true>, <2 x i1> %y, !prof !1
%notor = xor <2 x i1> %or, <i1 true, i1 true>
ret <2 x i1> %notor
}
@@ -754,11 +754,11 @@ entry:
ret i1 %cmp
}
-define i1 @invert_both_cmp_operands_complex(i1 %x, i32 %a, i32 %b, i32 %c) {
+define i1 @invert_both_cmp_operands_complex(i1 %x, i32 %a, i32 %b, i32 %c) !prof !0 {
; CHECK-LABEL: @invert_both_cmp_operands_complex(
; CHECK-NEXT: entry:
; CHECK-NEXT: [[TMP0:%.*]] = sub i32 [[A:%.*]], [[C:%.*]]
-; CHECK-NEXT: [[TMP1:%.*]] = select i1 [[X:%.*]], i32 [[TMP0]], i32 [[B:%.*]]
+; CHECK-NEXT: [[TMP1:%.*]] = select i1 [[X:%.*]], i32 [[TMP0]], i32 [[B:%.*]], !prof [[PROF1]]
; CHECK-NEXT: [[CMP:%.*]] = icmp sge i32 [[TMP1]], [[C]]
; CHECK-NEXT: ret i1 [[CMP]]
;
@@ -767,7 +767,7 @@ entry:
%not.b = xor i32 %b, -1
%not.c = xor i32 %c, -1
%add = add i32 %c, %not.a
- %select = select i1 %x, i32 %add, i32 %not.b
+ %select = select i1 %x, i32 %add, i32 %not.b, !prof !1
%cmp = icmp sle i32 %select, %not.c
ret i1 %cmp
}
@@ -937,18 +937,18 @@ define i1 @test_invert_demorgan_or3(i32 %a, i32 %b) {
ret i1 %not
}
-define i1 @test_invert_demorgan_logical_or(i64 %x, i64 %y) {
+define i1 @test_invert_demorgan_logical_or(i64 %x, i64 %y) !prof !0 {
; CHECK-LABEL: @test_invert_demorgan_logical_or(
; CHECK-NEXT: [[CMP1:%.*]] = icmp ne i64 [[X:%.*]], 27
; CHECK-NEXT: [[CMP2:%.*]] = icmp ne i64 [[Y:%.*]], 0
-; CHECK-NEXT: [[SEL_NOT1:%.*]] = select i1 [[CMP1]], i1 [[CMP2]], i1 false
+; CHECK-NEXT: [[SEL_NOT1:%.*]] = select i1 [[CMP1]], i1 [[CMP2]], i1 false, !prof [[PROF2]]
; CHECK-NEXT: [[CMP3:%.*]] = icmp ne i64 [[X]], 0
; CHECK-NEXT: [[OR_NOT:%.*]] = and i1 [[CMP3]], [[SEL_NOT1]]
; CHECK-NEXT: ret i1 [[OR_NOT]]
;
%cmp1 = icmp eq i64 %x, 27
%cmp2 = icmp eq i64 %y, 0
- %sel = select i1 %cmp1, i1 true, i1 %cmp2
+ %sel = select i1 %cmp1, i1 true, i1 %cmp2, !prof !1
%cmp3 = icmp eq i64 %x, 0
%or = or i1 %cmp3, %sel
%not = xor i1 %or, true
@@ -1011,18 +1011,18 @@ define i1 @test_invert_demorgan_and3(i32 %a, i32 %b) {
ret i1 %cmp
}
-define i1 @test_invert_demorgan_logical_and(i64 %x, i64 %y) {
+define i1 @test_invert_demorgan_logical_and(i64 %x, i64 %y) !prof !0 {
; CHECK-LABEL: @test_invert_demorgan_logical_and(
; CHECK-NEXT: [[CMP1:%.*]] = icmp ne i64 [[X:%.*]], 27
; CHECK-NEXT: [[CMP2:%.*]] = icmp ne i64 [[Y:%.*]], 0
-; CHECK-NEXT: [[SEL_NOT1:%.*]] = select i1 [[CMP1]], i1 true, i1 [[CMP2]]
+; CHECK-NEXT: [[SEL_NOT1:%.*]] = select i1 [[CMP1]], i1 true, i1 [[CMP2]], !prof [[PROF2]]
; CHECK-NEXT: [[CMP3:%.*]] = icmp ne i64 [[X]], 0
; CHECK-NEXT: [[OR_NOT:%.*]] = and i1 [[CMP3]], [[SEL_NOT1]]
; CHECK-NEXT: ret i1 [[OR_NOT]]
;
%cmp1 = icmp eq i64 %x, 27
%cmp2 = icmp eq i64 %y, 0
- %sel = select i1 %cmp1, i1 %cmp2, i1 false
+ %sel = select i1 %cmp1, i1 %cmp2, i1 false, !prof !1
%cmp3 = icmp eq i64 %x, 0
%or = or i1 %cmp3, %sel
%not = xor i1 %or, true
@@ -1139,3 +1139,13 @@ define i8 @invert_bitcasted_fcmp_fast(<8 x float> %a, <8 x float> %b) {
%not = xor i8 %mask.as.int, 255
ret i8 %not
}
+
+!0 = !{!"function_entry_count", i64 1000}
+!1 = !{!"branch_weights", i32 2, i32 3}
+;.
+; CHECK: attributes #[[ATTR0:[0-9]+]] = { nocallback nofree nosync nounwind willreturn memory(inaccessiblemem: readwrite) }
+;.
+; CHECK: [[META0:![0-9]+]] = !{!"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 3a1a26dfd8840..56b29cf4c87fb 100644
--- a/llvm/utils/profcheck-xfail.txt
+++ b/llvm/utils/profcheck-xfail.txt
@@ -236,7 +236,6 @@ Transforms/InstCombine/canonicalize-clamp-like-pattern-between-zero-and-positive
Transforms/InstCombine/cast-mul-select.ll
Transforms/InstCombine/clamp-to-minmax.ll
Transforms/InstCombine/cttz.ll
-Transforms/InstCombine/demorgan.ll
Transforms/InstCombine/div.ll
Transforms/InstCombine/div-shift.ll
Transforms/InstCombine/fabs.ll
@@ -246,13 +245,9 @@ Transforms/InstCombine/ffs-i16.ll
Transforms/InstCombine/fmul-bool.ll
Transforms/InstCombine/fmul.ll
Transforms/InstCombine/fneg.ll
-Transforms/InstCombine/fold-ctpop-of-not.ll
-Transforms/InstCombine/free-inversion.ll
Transforms/InstCombine/icmp-and-lowbit-mask.ll
Transforms/InstCombine/icmp.ll
Transforms/InstCombine/icmp-mul-and.ll
-Transforms/InstCombine/icmp-of-and-x.ll
-Transforms/InstCombine/icmp-of-or-x.ll
Transforms/InstCombine/icmp-select-implies-common-op.ll
Transforms/InstCombine/icmp-select.ll
Transforms/InstCombine/icmp-with-selects.ll
@@ -285,10 +280,8 @@ Transforms/InstCombine/mul-masked-bits.ll
Transforms/InstCombine/mul-pow2.ll
Transforms/InstCombine/multiple-uses-load-bitcast-select.ll
Transforms/InstCombine/nested-select.ll
-Transforms/InstCombine/not.ll
Transforms/InstCombine/or-bitmask.ll
Transforms/InstCombine/or-fcmp.ll
-Transforms/InstCombine/or.ll
Transforms/InstCombine/pow-1.ll
Transforms/InstCombine/pow-3.ll
Transforms/InstCombine/pow-sqrt.ll
@@ -308,8 +301,6 @@ Transforms/InstCombine/shift.ll
Transforms/InstCombine/simplify-demanded-fpclass.ll
Transforms/InstCombine/sink-not-into-another-hand-of-logical-and.ll
Transforms/InstCombine/sink-not-into-another-hand-of-logical-or.ll
-Transforms/InstCombine/sink-not-into-logical-and.ll
-Transforms/InstCombine/sink-not-into-logical-or.ll
Transforms/InstCombine/strchr-1.ll
Transforms/InstCombine/strchr-3.ll
Transforms/InstCombine/strlen-1.ll
``````````
</details>
https://github.com/llvm/llvm-project/pull/176497
More information about the llvm-commits
mailing list