[PATCH] D118387: [U
Kevin P. Neal via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Jan 27 09:11:51 PST 2022
kpn created this revision.
Herald added a subscriber: hiraditya.
kpn requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D118387
Files:
llvm/include/llvm/Transforms/Utils/SCCPSolver.h
llvm/lib/Transforms/Scalar/SCCP.cpp
llvm/lib/Transforms/Utils/SCCPSolver.cpp
Index: llvm/lib/Transforms/Utils/SCCPSolver.cpp
===================================================================
--- llvm/lib/Transforms/Utils/SCCPSolver.cpp
+++ llvm/lib/Transforms/Utils/SCCPSolver.cpp
@@ -1616,7 +1616,8 @@
const DataLayout &DL,
std::function<const TargetLibraryInfo &(Function &)> GetTLI,
LLVMContext &Ctx)
- : Visitor(new SCCPInstVisitor(DL, std::move(GetTLI), Ctx)) {}
+ : Visitor(new SCCPInstVisitor(DL, std::move(GetTLI), Ctx)), getTLI(GetTLI) {
+}
SCCPSolver::~SCCPSolver() {}
Index: llvm/lib/Transforms/Scalar/SCCP.cpp
===================================================================
--- llvm/lib/Transforms/Scalar/SCCP.cpp
+++ llvm/lib/Transforms/Scalar/SCCP.cpp
@@ -97,6 +97,18 @@
return !LV.isUnknownOrUndef() && !isConstant(LV);
}
+static bool canSCCPRemoveInstruction(Instruction *I,
+ const TargetLibraryInfo *TLI) {
+ if (wouldInstructionBeTriviallyDead(I, TLI))
+ return true;
+
+ // Defer to wouldInstructionBeTriviallyDead() for constrained fp.
+ if (isa<ConstrainedFPIntrinsic>(I))
+ return false;
+
+ return (!isa<CallInst>(I) || !I->mayHaveSideEffects()) && !I->isTerminator();
+}
+
static bool tryToReplaceWithConstant(SCCPSolver &Solver, Value *V) {
Constant *Const = nullptr;
if (V->getType()->isStructTy()) {
@@ -127,7 +139,11 @@
// Calls with "clang.arc.attachedcall" implicitly use the return value and
// those uses cannot be updated with a constant.
CallBase *CB = dyn_cast<CallBase>(V);
- if (CB && ((CB->isMustTailCall() && !CB->isSafeToRemove()) ||
+ Function *CBF = nullptr;
+ if (CB)
+ CBF = CB->getFunction();
+ if (CB && ((CB->isMustTailCall() &&
+ !canSCCPRemoveInstruction(CB, &Solver.getTLI(*CBF))) ||
CB->getOperandBundle(LLVMContext::OB_clang_arc_attachedcall))) {
Function *F = CB->getCalledFunction();
@@ -156,7 +172,7 @@
if (Inst.getType()->isVoidTy())
continue;
if (tryToReplaceWithConstant(Solver, &Inst)) {
- if (Inst.isSafeToRemove())
+ if (canSCCPRemoveInstruction(&Inst, &Solver.getTLI(*BB.getParent())))
Inst.eraseFromParent();
MadeChanges = true;
Index: llvm/include/llvm/Transforms/Utils/SCCPSolver.h
===================================================================
--- llvm/include/llvm/Transforms/Utils/SCCPSolver.h
+++ llvm/include/llvm/Transforms/Utils/SCCPSolver.h
@@ -51,6 +51,8 @@
~SCCPSolver();
+ std::function<const TargetLibraryInfo &(Function &)> getTLI;
+
void addAnalysis(Function &F, AnalysisResultsForFn A);
/// markBlockExecutable - This method can be used by clients to mark all of
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D118387.403692.patch
Type: text/x-patch
Size: 2674 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220127/9d26b93f/attachment.bin>
More information about the llvm-commits
mailing list