aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
diff options
context:
space:
mode:
authorNikita Popov <npopov@redhat.com>2022-09-19 14:44:39 +0200
committerNikita Popov <npopov@redhat.com>2022-09-19 14:46:43 +0200
commitdd61726d5bf30ee603fd2c471401d9b8107958d9 (patch)
tree4707bdc426f9284a0b1e945b2d626aa69ef0c849 /llvm/lib/Transforms/Utils/SimplifyCFG.cpp
parent4973eee1228674c80f9441a36019c8a83ee3458a (diff)
downloadllvm-dd61726d5bf30ee603fd2c471401d9b8107958d9.zip
llvm-dd61726d5bf30ee603fd2c471401d9b8107958d9.tar.gz
llvm-dd61726d5bf30ee603fd2c471401d9b8107958d9.tar.bz2
Revert "[SimplifyCFG] accumulate bonus insts cost"
This reverts commit e5581df60a35fffb0c69589777e4e126c849405f. This causes major compile-time regressions, about 2-3% end-to-end on CTMark.
Diffstat (limited to 'llvm/lib/Transforms/Utils/SimplifyCFG.cpp')
-rw-r--r--llvm/lib/Transforms/Utils/SimplifyCFG.cpp63
1 files changed, 19 insertions, 44 deletions
diff --git a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
index 755f4be..fcdd858 100644
--- a/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
+++ b/llvm/lib/Transforms/Utils/SimplifyCFG.cpp
@@ -207,21 +207,6 @@ STATISTIC(NumInvokes,
STATISTIC(NumInvokesMerged, "Number of invokes that were merged together");
STATISTIC(NumInvokeSetsFormed, "Number of invoke sets that were formed");
-namespace llvm {
-
-void SimplifyCFGCostTracker::updateNumBonusInsts(BasicBlock *BB,
- unsigned InstCount) {
- auto Loc = NumBonusInsts.find(BB);
- if (Loc == NumBonusInsts.end())
- Loc = NumBonusInsts.insert({BB, 0}).first;
- Loc->second = Loc->second + InstCount;
-}
-unsigned SimplifyCFGCostTracker::getNumBonusInsts(BasicBlock *BB) {
- return NumBonusInsts.lookup(BB);
-}
-
-} // namespace llvm
-
namespace {
// The first field contains the value that the switch produces when a certain
@@ -258,10 +243,6 @@ class SimplifyCFGOpt {
ArrayRef<WeakVH> LoopHeaders;
const SimplifyCFGOptions &Options;
bool Resimplify;
- // Accumulates number of bonus instructions due to merging basic blocks
- // of common destination.
- SimplifyCFGCostTracker *CostTracker;
- SimplifyCFGCostTracker LocalCostTracker;
Value *isValueEqualityComparison(Instruction *TI);
BasicBlock *GetValueEqualityComparisonCases(
@@ -305,10 +286,8 @@ class SimplifyCFGOpt {
public:
SimplifyCFGOpt(const TargetTransformInfo &TTI, DomTreeUpdater *DTU,
const DataLayout &DL, ArrayRef<WeakVH> LoopHeaders,
- const SimplifyCFGOptions &Opts,
- SimplifyCFGCostTracker *CostTracker_)
- : TTI(TTI), DTU(DTU), DL(DL), LoopHeaders(LoopHeaders), Options(Opts),
- CostTracker(CostTracker_ ? CostTracker_ : &LocalCostTracker) {
+ const SimplifyCFGOptions &Opts)
+ : TTI(TTI), DTU(DTU), DL(DL), LoopHeaders(LoopHeaders), Options(Opts) {
assert((!DTU || !DTU->hasPostDomTree()) &&
"SimplifyCFG is not yet capable of maintaining validity of a "
"PostDomTree, so don't ask for it.");
@@ -3645,9 +3624,8 @@ static bool isVectorOp(Instruction &I) {
/// If this basic block is simple enough, and if a predecessor branches to us
/// and one of our successors, fold the block into the predecessor and use
/// logical operations to pick the right destination.
-bool llvm::FoldBranchToCommonDest(BranchInst *BI,
- SimplifyCFGCostTracker &CostTracker,
- DomTreeUpdater *DTU, MemorySSAUpdater *MSSAU,
+bool llvm::FoldBranchToCommonDest(BranchInst *BI, DomTreeUpdater *DTU,
+ MemorySSAUpdater *MSSAU,
const TargetTransformInfo *TTI,
unsigned BonusInstThreshold) {
// If this block ends with an unconditional branch,
@@ -3719,6 +3697,7 @@ bool llvm::FoldBranchToCommonDest(BranchInst *BI,
// as "bonus instructions", and only allow this transformation when the
// number of the bonus instructions we'll need to create when cloning into
// each predecessor does not exceed a certain threshold.
+ unsigned NumBonusInsts = 0;
bool SawVectorOp = false;
const unsigned PredCount = Preds.size();
for (Instruction &I : *BB) {
@@ -3737,13 +3716,12 @@ bool llvm::FoldBranchToCommonDest(BranchInst *BI,
// predecessor. Ignore free instructions.
if (!TTI || TTI->getInstructionCost(&I, CostKind) !=
TargetTransformInfo::TCC_Free) {
- for (auto PredBB : Preds) {
- CostTracker.updateNumBonusInsts(PredBB, PredCount);
- // Early exits once we reach the limit.
- if (CostTracker.getNumBonusInsts(PredBB) >
- BonusInstThreshold * BranchFoldToCommonDestVectorMultiplier)
- return false;
- }
+ NumBonusInsts += PredCount;
+
+ // Early exits once we reach the limit.
+ if (NumBonusInsts >
+ BonusInstThreshold * BranchFoldToCommonDestVectorMultiplier)
+ return false;
}
auto IsBCSSAUse = [BB, &I](Use &U) {
@@ -3757,12 +3735,10 @@ bool llvm::FoldBranchToCommonDest(BranchInst *BI,
if (!all_of(I.uses(), IsBCSSAUse))
return false;
}
- for (auto PredBB : Preds) {
- if (CostTracker.getNumBonusInsts(PredBB) >
- BonusInstThreshold *
- (SawVectorOp ? BranchFoldToCommonDestVectorMultiplier : 1))
- return false;
- }
+ if (NumBonusInsts >
+ BonusInstThreshold *
+ (SawVectorOp ? BranchFoldToCommonDestVectorMultiplier : 1))
+ return false;
// Ok, we have the budget. Perform the transformation.
for (BasicBlock *PredBlock : Preds) {
@@ -6913,7 +6889,7 @@ bool SimplifyCFGOpt::simplifyUncondBranch(BranchInst *BI,
// branches to us and our successor, fold the comparison into the
// predecessor and use logical operations to update the incoming value
// for PHI nodes in common successor.
- if (FoldBranchToCommonDest(BI, *CostTracker, DTU, /*MSSAU=*/nullptr, &TTI,
+ if (FoldBranchToCommonDest(BI, DTU, /*MSSAU=*/nullptr, &TTI,
Options.BonusInstThreshold))
return requestResimplify();
return false;
@@ -6982,7 +6958,7 @@ bool SimplifyCFGOpt::simplifyCondBranch(BranchInst *BI, IRBuilder<> &Builder) {
// If this basic block is ONLY a compare and a branch, and if a predecessor
// branches to us and one of our successors, fold the comparison into the
// predecessor and use logical operations to pick the right destination.
- if (FoldBranchToCommonDest(BI, *CostTracker, DTU, /*MSSAU=*/nullptr, &TTI,
+ if (FoldBranchToCommonDest(BI, DTU, /*MSSAU=*/nullptr, &TTI,
Options.BonusInstThreshold))
return requestResimplify();
@@ -7281,9 +7257,8 @@ bool SimplifyCFGOpt::run(BasicBlock *BB) {
bool llvm::simplifyCFG(BasicBlock *BB, const TargetTransformInfo &TTI,
DomTreeUpdater *DTU, const SimplifyCFGOptions &Options,
- ArrayRef<WeakVH> LoopHeaders,
- SimplifyCFGCostTracker *CostTracker) {
+ ArrayRef<WeakVH> LoopHeaders) {
return SimplifyCFGOpt(TTI, DTU, BB->getModule()->getDataLayout(), LoopHeaders,
- Options, CostTracker)
+ Options)
.run(BB);
}