diff options
author | Nikita Popov <nikita.ppv@gmail.com> | 2020-11-17 20:11:09 +0100 |
---|---|---|
committer | Nikita Popov <nikita.ppv@gmail.com> | 2020-11-26 18:39:55 +0100 |
commit | 4df8efce80e373dd1e05bd4910c796a0c91383e7 (patch) | |
tree | e0a4f36abcfcdfe8740130a4a55488648cd1800e /llvm/lib/Transforms/Scalar | |
parent | 668da8c361fef5ada092534d4d20ea450831f6f6 (diff) | |
download | llvm-project-4df8efce80e373dd1e05bd4910c796a0c91383e7.tar.gz |
[AA] Split up LocationSize::unknown()
Currently, we have some confusion in the codebase regarding the
meaning of LocationSize::unknown(): Some parts (including most of
BasicAA) assume that LocationSize::unknown() only allows accesses
after the base pointer. Some parts (various callers of AA) assume
that LocationSize::unknown() allows accesses both before and after
the base pointer (but within the underlying object).
This patch splits up LocationSize::unknown() into
LocationSize::afterPointer() and LocationSize::beforeOrAfterPointer()
to make this completely unambiguous. I tried my best to determine
which one is appropriate for all the existing uses.
The test changes in cs-cs.ll in particular illustrate a previously
clearly incorrect AA result: We were effectively assuming that
argmemonly functions were only allowed to access their arguments
after the passed pointer, but not before it. I'm pretty sure that
this was not intentional, and it's certainly not specified by
LangRef that way.
Differential Revision: https://reviews.llvm.org/D91649
Diffstat (limited to 'llvm/lib/Transforms/Scalar')
-rw-r--r-- | llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp | 15 | ||||
-rw-r--r-- | llvm/lib/Transforms/Scalar/LICM.cpp | 3 | ||||
-rw-r--r-- | llvm/lib/Transforms/Scalar/LoopIdiomRecognize.cpp | 2 |
3 files changed, 8 insertions, 12 deletions
diff --git a/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp b/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp index a1050ee63451..330d25c4dbc8 100644 --- a/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp +++ b/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp @@ -275,7 +275,7 @@ static MemoryLocation getLocForWrite(Instruction *Inst, default: return MemoryLocation(); // Unhandled intrinsic. case Intrinsic::init_trampoline: - return MemoryLocation(II->getArgOperand(0), LocationSize::unknown()); + return MemoryLocation::getAfter(II->getArgOperand(0)); case Intrinsic::masked_store: return MemoryLocation::getForArgument(II, 1, TLI); case Intrinsic::lifetime_end: { @@ -287,7 +287,7 @@ static MemoryLocation getLocForWrite(Instruction *Inst, if (auto *CB = dyn_cast<CallBase>(Inst)) // All the supported TLI functions so far happen to have dest as their // first argument. - return MemoryLocation(CB->getArgOperand(0), LocationSize::unknown()); + return MemoryLocation::getAfter(CB->getArgOperand(0)); return MemoryLocation(); } @@ -828,8 +828,7 @@ static bool handleFree(CallInst *F, AliasAnalysis *AA, MapVector<Instruction *, bool> &ThrowableInst) { bool MadeChange = false; - MemoryLocation Loc = MemoryLocation(F->getOperand(0), - LocationSize::unknown()); + MemoryLocation Loc = MemoryLocation::getAfter(F->getOperand(0)); SmallVector<BasicBlock *, 16> Blocks; Blocks.push_back(F->getParent()); @@ -1726,15 +1725,14 @@ struct DSEState { case LibFunc_strncpy: case LibFunc_strcat: case LibFunc_strncat: - return {MemoryLocation(CB->getArgOperand(0), - LocationSize::unknown())}; + return {MemoryLocation::getAfter(CB->getArgOperand(0))}; default: break; } } switch (CB->getIntrinsicID()) { case Intrinsic::init_trampoline: - return {MemoryLocation(CB->getArgOperand(0), LocationSize::unknown())}; + return {MemoryLocation::getAfter(CB->getArgOperand(0))}; case Intrinsic::masked_store: return {MemoryLocation::getForArgument(CB, 1, TLI)}; default: @@ -1829,8 +1827,7 @@ struct DSEState { if (auto *CB = dyn_cast<CallBase>(I)) { if (isFreeCall(I, &TLI)) - return {std::make_pair(MemoryLocation(CB->getArgOperand(0), - LocationSize::unknown()), + return {std::make_pair(MemoryLocation::getAfter(CB->getArgOperand(0)), true)}; } diff --git a/llvm/lib/Transforms/Scalar/LICM.cpp b/llvm/lib/Transforms/Scalar/LICM.cpp index 1885d1d9f557..9d90986c54ad 100644 --- a/llvm/lib/Transforms/Scalar/LICM.cpp +++ b/llvm/lib/Transforms/Scalar/LICM.cpp @@ -1209,8 +1209,7 @@ bool llvm::canSinkOrHoistInst(Instruction &I, AAResults *AA, DominatorTree *DT, bool Invalidated; if (CurAST) Invalidated = pointerInvalidatedByLoop( - MemoryLocation(Op, LocationSize::unknown(), AAMDNodes()), - CurAST, CurLoop, AA); + MemoryLocation::getBeforeOrAfter(Op), CurAST, CurLoop, AA); else Invalidated = pointerInvalidatedByLoopWithMSSA( MSSA, cast<MemoryUse>(MSSA->getMemoryAccess(CI)), CurLoop, I, diff --git a/llvm/lib/Transforms/Scalar/LoopIdiomRecognize.cpp b/llvm/lib/Transforms/Scalar/LoopIdiomRecognize.cpp index ef872a586965..526f1fe2388f 100644 --- a/llvm/lib/Transforms/Scalar/LoopIdiomRecognize.cpp +++ b/llvm/lib/Transforms/Scalar/LoopIdiomRecognize.cpp @@ -844,7 +844,7 @@ mayLoopAccessLocation(Value *Ptr, ModRefInfo Access, Loop *L, // Get the location that may be stored across the loop. Since the access is // strided positively through memory, we say that the modified location starts // at the pointer and has infinite size. - LocationSize AccessSize = LocationSize::unknown(); + LocationSize AccessSize = LocationSize::afterPointer(); // If the loop iterates a fixed number of times, we can refine the access size // to be exactly the size of the memset, which is (BECount+1)*StoreSize |