[llvm] [Transforms][Scalar] Remove ProfcheckDisableMetadataFixes checks (PR #222388)
Aiden Grossman via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 9 10:57:44 PDT 2026
https://github.com/boomanaiden154 updated https://github.com/llvm/llvm-project/pull/222388
>From 55e4d3296f4a470c49ec578d6b372e005c60d059 Mon Sep 17 00:00:00 2001
From: Aiden Grossman <aidengrossman at google.com>
Date: Wed, 9 Sep 2026 16:59:36 +0000
Subject: [PATCH] =?UTF-8?q?[=F0=9D=98=80=F0=9D=97=BD=F0=9D=97=BF]=20change?=
=?UTF-8?q?s=20to=20main=20this=20commit=20is=20based=20on?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Created using spr 1.3.7
[skip ci]
---
llvm/lib/Transforms/Utils/LoopPeel.cpp | 4 +-
llvm/lib/Transforms/Utils/LoopUtils.cpp | 5 +-
.../Transforms/Utils/LowerMemIntrinsics.cpp | 6 --
llvm/lib/Transforms/Utils/SimplifyCFG.cpp | 62 ++++++++-----------
.../peel-last-iteration.ll | 61 +++++++-----------
5 files changed, 50 insertions(+), 88 deletions(-)
diff --git a/llvm/lib/Transforms/Utils/LoopPeel.cpp b/llvm/lib/Transforms/Utils/LoopPeel.cpp
index cc45a3e09bd88..315763d442786 100644
--- a/llvm/lib/Transforms/Utils/LoopPeel.cpp
+++ b/llvm/lib/Transforms/Utils/LoopPeel.cpp
@@ -90,7 +90,6 @@ static cl::opt<bool> EnablePeelingForIV(
static const char *PeeledCountMetaData = "llvm.loop.peeled.count";
-extern cl::opt<bool> ProfcheckDisableMetadataFixes;
} // namespace llvm
// Check whether we are capable of peeling this loop.
@@ -1231,8 +1230,7 @@ void llvm::peelLoop(Loop *L, unsigned PeelCount, bool PeelLast, LoopInfo *LI,
auto *BI = B.CreateCondBr(Cond, NewPreHeader, InsertTop);
SmallVector<uint32_t> Weights;
auto *OrigLatchBr = Latch->getTerminator();
- auto HasBranchWeights = !ProfcheckDisableMetadataFixes &&
- extractBranchWeights(*OrigLatchBr, Weights);
+ auto HasBranchWeights = extractBranchWeights(*OrigLatchBr, Weights);
if (HasBranchWeights) {
// The probability that the new guard skips the loop to execute just one
// iteration is the original loop's probability of exiting at the latch
diff --git a/llvm/lib/Transforms/Utils/LoopUtils.cpp b/llvm/lib/Transforms/Utils/LoopUtils.cpp
index d3f2f0beacc6a..a2e544801b9c4 100644
--- a/llvm/lib/Transforms/Utils/LoopUtils.cpp
+++ b/llvm/lib/Transforms/Utils/LoopUtils.cpp
@@ -54,9 +54,6 @@ using namespace llvm::PatternMatch;
static const char *LLVMLoopDisableNonforced = "llvm.loop.disable_nonforced";
static const char *LLVMLoopDisableLICM = "llvm.licm.disable";
-namespace llvm {
-extern cl::opt<bool> ProfcheckDisableMetadataFixes;
-} // namespace llvm
bool llvm::formDedicatedExitBlocks(Loop *L, DominatorTree *DT, LoopInfo *LI,
MemorySSAUpdater *MSSAU,
@@ -994,7 +991,7 @@ bool llvm::setLoopEstimatedTripCount(
return true;
// Calculate taken and exit weights.
- unsigned LatchExitWeight = ProfcheckDisableMetadataFixes ? 0 : 1;
+ unsigned LatchExitWeight = 1;
unsigned BackedgeTakenWeight = 0;
if (EstimatedTripCount != 0) {
diff --git a/llvm/lib/Transforms/Utils/LowerMemIntrinsics.cpp b/llvm/lib/Transforms/Utils/LowerMemIntrinsics.cpp
index c48e173b05479..84131f6592e50 100644
--- a/llvm/lib/Transforms/Utils/LowerMemIntrinsics.cpp
+++ b/llvm/lib/Transforms/Utils/LowerMemIntrinsics.cpp
@@ -26,10 +26,6 @@
using namespace llvm;
-namespace llvm {
-extern cl::opt<bool> ProfcheckDisableMetadataFixes;
-}
-
/// \returns \p Len urem \p OpSize, checking for optimization opportunities.
/// \p OpSizeVal must be the integer value of the \c ConstantInt \p OpSize.
static Value *getRuntimeLoopRemainder(IRBuilderBase &B, Value *Len,
@@ -71,8 +67,6 @@ struct LoopExpansionInfo {
};
std::optional<uint64_t> getAverageMemOpLoopTripCount(const MemIntrinsic &I) {
- if (ProfcheckDisableMetadataFixes)
- return std::nullopt;
if (std::optional<uint64_t> EC = I.getFunction()->getEntryCount();
!EC || *EC == 0)
return std::nullopt;
diff --git a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
index ca96f2e70d810..f58fc8166ffd6 100644
--- a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
+++ b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
@@ -4206,13 +4206,12 @@ static bool performBranchToCommonDestFolding(CondBrInst *BI, CondBrInst *PBI,
Value *BICond = VMap[BI->getCondition()];
PBI->setCondition(
createLogicalOp(Builder, Opc, PBI->getCondition(), BICond, "or.cond"));
- if (!ProfcheckDisableMetadataFixes)
- if (auto *SI = dyn_cast<SelectInst>(PBI->getCondition()))
- if (!MDWeights.empty()) {
- assert(isSelectInRoleOfConjunctionOrDisjunction(SI));
- setFittedBranchWeights(*SI, {MDWeights[0], MDWeights[1]},
- /*IsExpected=*/false, /*ElideAllZero=*/true);
- }
+ if (auto *SI = dyn_cast<SelectInst>(PBI->getCondition()))
+ if (!MDWeights.empty()) {
+ assert(isSelectInRoleOfConjunctionOrDisjunction(SI));
+ setFittedBranchWeights(*SI, {MDWeights[0], MDWeights[1]},
+ /*IsExpected=*/false, /*ElideAllZero=*/true);
+ }
++NumFoldBranchToCommonDest;
return true;
@@ -4558,8 +4557,7 @@ static bool mergeConditionalStoreToAddress(
auto *T = SplitBlockAndInsertIfThen(CombinedPred, InsertPt,
/*Unreachable=*/false,
/*BranchWeights=*/nullptr, DTU);
- if (hasBranchWeightMD(*PBranch) && hasBranchWeightMD(*QBranch) &&
- !ProfcheckDisableMetadataFixes) {
+ if (hasBranchWeightMD(*PBranch) && hasBranchWeightMD(*QBranch)) {
SmallVector<uint32_t, 2> PWeights, QWeights;
extractBranchWeights(*PBranch, PWeights);
extractBranchWeights(*QBranch, QWeights);
@@ -4945,16 +4943,15 @@ static bool SimplifyCondBranchToCondBranch(CondBrInst *PBI, CondBrInst *BI,
/*ElideAllZero=*/true);
// Cond may be a select instruction with the first operand set to "true", or
// the second to "false" (see how createLogicalOp works for `and` and `or`)
- if (!ProfcheckDisableMetadataFixes)
- if (auto *SI = dyn_cast<SelectInst>(Cond)) {
- assert(isSelectInRoleOfConjunctionOrDisjunction(SI));
- // The select is predicated on PBICond
- assert(SI->getCondition() == PBICond);
- // The corresponding probabilities are what was referred to above as
- // PredCommon and PredOther.
- setFittedBranchWeights(*SI, {PredCommon, PredOther},
- /*IsExpected=*/false, /*ElideAllZero=*/true);
- }
+ if (auto *SI = dyn_cast<SelectInst>(Cond)) {
+ assert(isSelectInRoleOfConjunctionOrDisjunction(SI));
+ // The select is predicated on PBICond
+ assert(SI->getCondition() == PBICond);
+ // The corresponding probabilities are what was referred to above as
+ // PredCommon and PredOther.
+ setFittedBranchWeights(*SI, {PredCommon, PredOther},
+ /*IsExpected=*/false, /*ElideAllZero=*/true);
+ }
}
// OtherDest may have phi nodes. If so, add an entry from PBI's
@@ -5197,8 +5194,7 @@ bool SimplifyCFGOpt::simplifyIndirectBrOnSelect(IndirectBrInst *IBI,
// The select's profile becomes the profile of the conditional branch that
// replaces the indirect branch.
SmallVector<uint32_t> SelectBranchWeights(2);
- if (!ProfcheckDisableMetadataFixes)
- extractBranchWeights(*SI, SelectBranchWeights);
+ extractBranchWeights(*SI, SelectBranchWeights);
// Perform the actual simplification.
return simplifyTerminatorOnSelect(IBI, SI->getCondition(), TrueBB, FalseBB,
SelectBranchWeights[0],
@@ -5452,8 +5448,7 @@ bool SimplifyCFGOpt::simplifyBranchOnICmpChain(CondBrInst *BI,
return false;
SmallVector<uint32_t> BranchWeights;
- const bool HasProfile = !ProfcheckDisableMetadataFixes &&
- extractBranchWeights(*BI, BranchWeights);
+ const bool HasProfile = extractBranchWeights(*BI, BranchWeights);
// Figure out which block is which destination.
BasicBlock *DefaultBB = BI->getSuccessor(1);
@@ -6743,8 +6738,7 @@ static Value *foldSwitchToSelect(const SwitchCaseResultVectorTy &ResultVector,
// default: return 4; %3 = select i1 %2, i32 2, i32 %1
// }
- const bool HasBranchWeights =
- !BranchWeights.empty() && !ProfcheckDisableMetadataFixes;
+ const bool HasBranchWeights = !BranchWeights.empty();
if (ResultVector.size() == 2 && ResultVector[0].second.size() == 1 &&
ResultVector[1].second.size() == 1) {
@@ -6939,11 +6933,9 @@ static bool trySwitchToSelect(SwitchInst *SI, IRBuilder<> &Builder,
assert(PHI != nullptr && "PHI for value select not found");
Builder.SetInsertPoint(SI);
SmallVector<uint32_t, 4> BranchWeights;
- if (!ProfcheckDisableMetadataFixes) {
- [[maybe_unused]] auto HasWeights =
- extractBranchWeights(getBranchWeightMDNode(*SI), BranchWeights);
- assert(!HasWeights == (BranchWeights.empty()));
- }
+ [[maybe_unused]] auto HasWeights =
+ extractBranchWeights(getBranchWeightMDNode(*SI), BranchWeights);
+ assert(!HasWeights == (BranchWeights.empty()));
assert(BranchWeights.empty() ||
(BranchWeights.size() >=
UniqueResults.size() + (DefaultResult != nullptr)));
@@ -7820,8 +7812,8 @@ static bool simplifySwitchLookup(SwitchInst *SI, IRBuilder<> &Builder,
Updates.push_back({DominatorTree::Insert, LookupBB, CommonDest});
SmallVector<uint32_t> BranchWeights;
- const bool HasBranchWeights = CondBranch && !ProfcheckDisableMetadataFixes &&
- extractBranchWeights(*SI, BranchWeights);
+ const bool HasBranchWeights =
+ CondBranch && extractBranchWeights(*SI, BranchWeights);
uint64_t ToLookupWeight = 0;
uint64_t ToDefaultWeight = 0;
@@ -8121,8 +8113,7 @@ static bool simplifySwitchOfPowersOfTwo(SwitchInst *SI, IRBuilder<> &Builder,
BasicBlock *SplitBB = SplitBlock(OrigBB, SI, DTU);
auto It = OrigBB->getTerminator()->getIterator();
SmallVector<uint32_t> Weights;
- auto HasWeights =
- !ProfcheckDisableMetadataFixes && extractBranchWeights(*SI, Weights);
+ auto HasWeights = extractBranchWeights(*SI, Weights);
auto *BI = CondBrInst::Create(IsPow2, SplitBB, DefaultCaseBB, It);
if (HasWeights && any_of(Weights, not_equal_to(0))) {
// IsPow2 covers a subset of the cases in which we'd go to the default
@@ -8605,8 +8596,7 @@ bool SimplifyCFGOpt::simplifyIndirectBr(IndirectBrInst *IBI) {
BasicBlock *BB = IBI->getParent();
bool Changed = false;
SmallVector<uint32_t> BranchWeights;
- const bool HasBranchWeights = !ProfcheckDisableMetadataFixes &&
- extractBranchWeights(*IBI, BranchWeights);
+ const bool HasBranchWeights = extractBranchWeights(*IBI, BranchWeights);
DenseMap<const BasicBlock *, uint64_t> TargetWeight;
if (HasBranchWeights)
diff --git a/llvm/test/Transforms/LoopUnroll/branch-weights-freq/peel-last-iteration.ll b/llvm/test/Transforms/LoopUnroll/branch-weights-freq/peel-last-iteration.ll
index 43e2cd8dcd89c..8c9f7ce3be403 100644
--- a/llvm/test/Transforms/LoopUnroll/branch-weights-freq/peel-last-iteration.ll
+++ b/llvm/test/Transforms/LoopUnroll/branch-weights-freq/peel-last-iteration.ll
@@ -1,7 +1,4 @@
-; Disable this test in profcheck because the first run would cause profcheck to fail.
-; REQUIRES: !profcheck
-; RUN: opt -p "print<block-freq>,loop-unroll,print<block-freq>" -scev-cheap-expansion-budget=3 -S %s -profcheck-disable-metadata-fixes 2>&1 | FileCheck %s --check-prefixes=COMMON,BAD
-; RUN: opt -p "print<block-freq>,loop-unroll,print<block-freq>" -scev-cheap-expansion-budget=3 -S %s 2>&1 | FileCheck %s --check-prefixes=COMMON,GOOD
+; RUN: opt -p "print<block-freq>,loop-unroll,print<block-freq>" -scev-cheap-expansion-budget=3 -S %s 2>&1 | FileCheck %s
define i32 @test_expansion_cost_2(i32 %start, i32 %end) !prof !0 {
entry:
@@ -29,38 +26,24 @@ exit:
!1 = !{!"branch_weights", i32 2, i32 3}
!2 = !{!"branch_weights", i32 1, i32 50}
-; COMMON: block-frequency-info: test_expansion_cost_2
-; COMMON-NEXT: entry: float = 1.0
-; COMMON-NEXT: loop.header: float = 51.0
-; COMMON-NEXT: then: float = 20.4
-; COMMON-NEXT: loop.latch: float = 51.0
-; COMMON-NEXT: exit: float = 1.0
-
-; COMMON: block-frequency-info: test_expansion_cost_2
-; GOOD-NEXT: entry: float = 1.0
-; GOOD-NEXT: entry.split: float = 0.98039
-; GOOD-NEXT: loop.header: float = 50.0
-; GOOD-NEXT: then: float = 20.0
-; GOOD-NEXT: loop.latch: float = 50.0
-; GOOD-NEXT: exit.peel.begin.loopexit: float = 0.98039
-; GOOD-NEXT: exit.peel.begin: float = 1.0
-; GOOD-NEXT: loop.header.peel: float = 1.0
-; GOOD-NEXT: then.peel: float = 0.4
-; GOOD-NEXT: loop.latch.peel: float = 1.0
-; GOOD-NEXT: exit.peel.next: float = 1.0
-; GOOD-NEXT: loop.header.peel.next: float = 1.0
-; GOOD-NEXT: exit: float = 1.0
-
-; BAD-NEXT: entry: float = 1.0
-; BAD-NEXT: entry.split: float = 0.625
-; BAD-NEXT: loop.header: float = 31.875
-; BAD-NEXT: then: float = 12.75
-; BAD-NEXT: loop.latch: float = 31.875
-; BAD-NEXT: exit.peel.begin.loopexit: float = 0.625
-; BAD-NEXT: exit.peel.begin: float = 1.0
-; BAD-NEXT: loop.header.peel: float = 1.0
-; BAD-NEXT: then.peel: float = 0.4
-; BAD-NEXT: loop.latch.peel: float = 1.0
-; BAD-NEXT: exit.peel.next: float = 1.0
-; BAD-NEXT: loop.header.peel.next: float = 1.0
-; BAD-NEXT: exit: float = 1.0
\ No newline at end of file
+; CHECK: block-frequency-info: test_expansion_cost_2
+; CHECK-NEXT: entry: float = 1.0
+; CHECK-NEXT: loop.header: float = 51.0
+; CHECK-NEXT: then: float = 20.4
+; CHECK-NEXT: loop.latch: float = 51.0
+; CHECK-NEXT: exit: float = 1.0
+
+; CHECK: block-frequency-info: test_expansion_cost_2
+; CHECK-NEXT: entry: float = 1.0
+; CHECK-NEXT: entry.split: float = 0.98039
+; CHECK-NEXT: loop.header: float = 50.0
+; CHECK-NEXT: then: float = 20.0
+; CHECK-NEXT: loop.latch: float = 50.0
+; CHECK-NEXT: exit.peel.begin.loopexit: float = 0.98039
+; CHECK-NEXT: exit.peel.begin: float = 1.0
+; CHECK-NEXT: loop.header.peel: float = 1.0
+; CHECK-NEXT: then.peel: float = 0.4
+; CHECK-NEXT: loop.latch.peel: float = 1.0
+; CHECK-NEXT: exit.peel.next: float = 1.0
+; CHECK-NEXT: loop.header.peel.next: float = 1.0
+; CHECK-NEXT: exit: float = 1.0
\ No newline at end of file
More information about the llvm-commits
mailing list