Index: lib/Analysis/ScopInfo.cpp =================================================================== --- lib/Analysis/ScopInfo.cpp +++ lib/Analysis/ScopInfo.cpp @@ -168,6 +168,13 @@ "Do not add parameter bounds and do no gist simplify sets accordingly"), cl::Hidden, cl::init(false), cl::cat(PollyCategory)); +static cl::opt PollyAllFunctionParametersDereferenceable( + "polly-allow-dereference-of-all-function-parameters", + cl::desc( + "Treat all parameters to functions that are pointers as dereferencible." + " This is useful for invariant load hoisting (TODO: explain why)"), + cl::Hidden, cl::init(false), cl::cat(PollyCategory)); + static cl::opt PollyPreciseFoldAccesses( "polly-precise-fold-accesses", cl::desc("Fold memory accesses to model more possible delinearizations " @@ -3840,6 +3847,14 @@ return nullptr; } +bool isAParameter(llvm::Value *maybeParam, const Function &F) { + for (const llvm::Argument &Arg : F.args()) { + if (&Arg == maybeParam) + return true; + } + return false; +}; + bool Scop::canAlwaysBeHoisted(MemoryAccess *MA, bool StmtInvalidCtxIsEmpty, bool MAInvalidCtxIsEmpty, bool NonHoistableCtxIsEmpty) { @@ -3848,7 +3863,9 @@ // TODO: We can provide more information for better but more expensive // results. if (!isDereferenceableAndAlignedPointer(LInst->getPointerOperand(), - LInst->getAlignment(), DL)) + LInst->getAlignment(), DL) && + !(PollyAllFunctionParametersDereferenceable && + isAParameter(LInst->getPointerOperand(), getFunction()))) return false; // If the location might be overwritten we do not hoist it unconditionally.