Skip to content

Commit f4db142

Browse files
committed
[SCCP] Move logic for removing ssa.copy into Solver (NFC)
So it can be reused between IPSCCP and SCCP. Make the implementation a bit more efficient by only lookup the PredicateInfo once.
1 parent 36af734 commit f4db142

File tree

3 files changed

+27
-13
lines changed

3 files changed

+27
-13
lines changed

llvm/include/llvm/Transforms/Utils/SCCPSolver.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ class SCCPSolver {
7777
LLVM_ABI void addPredicateInfo(Function &F, DominatorTree &DT,
7878
AssumptionCache &AC);
7979

80+
LLVM_ABI void removeSSACopies(Function &F);
81+
8082
/// markBlockExecutable - This method can be used by clients to mark all of
8183
/// the blocks that are known to be intrinsically live in the processed unit.
8284
/// This returns true if the block was not considered live before.

llvm/lib/Transforms/IPO/SCCP.cpp

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -250,19 +250,7 @@ static bool runIPSCCP(
250250
if (!DeadBB->hasAddressTaken())
251251
DTU.deleteBB(DeadBB);
252252

253-
for (BasicBlock &BB : F) {
254-
for (Instruction &Inst : llvm::make_early_inc_range(BB)) {
255-
if (Solver.getPredicateInfoFor(&Inst)) {
256-
if (auto *II = dyn_cast<IntrinsicInst>(&Inst)) {
257-
if (II->getIntrinsicID() == Intrinsic::ssa_copy) {
258-
Value *Op = II->getOperand(0);
259-
Inst.replaceAllUsesWith(Op);
260-
Inst.eraseFromParent();
261-
}
262-
}
263-
}
264-
}
265-
}
253+
Solver.removeSSACopies(F);
266254
}
267255

268256
// If we inferred constant or undef return values for a function, we replaced

llvm/lib/Transforms/Utils/SCCPSolver.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -764,6 +764,26 @@ class SCCPInstVisitor : public InstVisitor<SCCPInstVisitor> {
764764
FnPredicateInfo.insert({&F, std::make_unique<PredicateInfo>(F, DT, AC)});
765765
}
766766

767+
void removeSSACopies(Function &F) {
768+
auto It = FnPredicateInfo.find(&F);
769+
if (It == FnPredicateInfo.end())
770+
return;
771+
772+
for (BasicBlock &BB : F) {
773+
for (Instruction &Inst : llvm::make_early_inc_range(BB)) {
774+
if (It->second->getPredicateInfoFor(&Inst)) {
775+
if (auto *II = dyn_cast<IntrinsicInst>(&Inst)) {
776+
if (II->getIntrinsicID() == Intrinsic::ssa_copy) {
777+
Value *Op = II->getOperand(0);
778+
Inst.replaceAllUsesWith(Op);
779+
Inst.eraseFromParent();
780+
}
781+
}
782+
}
783+
}
784+
}
785+
}
786+
767787
void visitCallInst(CallInst &I) { visitCallBase(I); }
768788

769789
bool markBlockExecutable(BasicBlock *BB);
@@ -2168,6 +2188,10 @@ void SCCPSolver::addPredicateInfo(Function &F, DominatorTree &DT,
21682188
Visitor->addPredicateInfo(F, DT, AC);
21692189
}
21702190

2191+
void SCCPSolver::removeSSACopies(Function &F) {
2192+
Visitor->removeSSACopies(F);
2193+
}
2194+
21712195
bool SCCPSolver::markBlockExecutable(BasicBlock *BB) {
21722196
return Visitor->markBlockExecutable(BB);
21732197
}

0 commit comments

Comments
 (0)