[PATCH] D128827: [WIP][SCCP] Don't track specialized functions unless they are recursive.
Alexandros Lamprineas via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Jun 29 07:42:04 PDT 2022
labrinea created this revision.
Herald added subscribers: snehasish, ormris, hiraditya.
Herald added a project: All.
labrinea requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
An attempt to fix a crash when compiling MultiSource from the llvm test suite with `FuncSpecializationMaxIters > 1`
llvm/include/llvm/Analysis/ValueLattice.h:
bool llvm::ValueLatticeElement::markConstant(llvm::Constant*, bool):
Assertion `getConstant() == V && "Marking constant with different value"'
llvm::ValueLatticeElement::markConstant(llvm::Constant*, bool)
llvm::SCCPInstVisitor::markConstant(llvm::Value*, llvm::Constant*)
llvm::SCCPInstVisitor::visitCastInst(llvm::CastInst&)
llvm::SCCPInstVisitor::solve()
llvm::FunctionSpecializer::specialize(llvm::SmallVectorImpl<llvm::Function*>&)
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D128827
Files:
llvm/lib/Transforms/IPO/FunctionSpecialization.cpp
Index: llvm/lib/Transforms/IPO/FunctionSpecialization.cpp
===================================================================
--- llvm/lib/Transforms/IPO/FunctionSpecialization.cpp
+++ llvm/lib/Transforms/IPO/FunctionSpecialization.cpp
@@ -438,6 +438,14 @@
return true;
}
+static bool isRecursive(Function *F) {
+ return any_of(F->users(), [F](User *U) {
+ if (auto *CS = dyn_cast<CallBase>(U))
+ return CS->getFunction() == F;
+ return false;
+ });
+}
+
void FunctionSpecializer::specializeFunction(Function *F, SpecializationInfo &S,
FuncList &WorkList) {
ValueToValueMapTy Mappings;
@@ -451,6 +459,15 @@
// with the given value.
Solver.markArgInFuncSpecialization(Clone, S.Args);
+ if (isRecursive(F) && FuncSpecializationMaxIters > 1) {
+ // Initialize the state of the newly created functions, marking them
+ // argument-tracked and executable.
+ if (F->hasExactDefinition() && !F->hasFnAttribute(Attribute::Naked))
+ Solver.addTrackedFunction(Clone);
+ Solver.addArgumentTrackedFunction(Clone);
+ Solver.markBlockExecutable(&Clone->front());
+ }
+
// Mark all the specialized functions
WorkList.push_back(Clone);
NbFunctionsSpecialized++;
@@ -736,15 +753,7 @@
FuncList &WorkList) {
for (auto *F : WorkList) {
SpecializedFuncs.insert(F);
-
- // Initialize the state of the newly created functions, marking them
- // argument-tracked and executable.
- if (F->hasExactDefinition() && !F->hasFnAttribute(Attribute::Naked))
- Solver.addTrackedFunction(F);
-
- Solver.addArgumentTrackedFunction(F);
Candidates.push_back(F);
- Solver.markBlockExecutable(&F->front());
// Replace the function arguments for the specialized functions.
for (Argument &Arg : F->args())
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D128827.441010.patch
Type: text/x-patch
Size: 1895 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220629/49205ea6/attachment.bin>
More information about the llvm-commits
mailing list