forked from OSchip/llvm-project
[DSE] Assert analyzable write in isRemovable() (NFC)
As requested on D116210. The function is not necessarily well-defined without this precondition.
This commit is contained in:
parent
2b8a703858
commit
034e66e76c
|
@ -175,30 +175,6 @@ static cl::opt<bool>
|
||||||
using OverlapIntervalsTy = std::map<int64_t, int64_t>;
|
using OverlapIntervalsTy = std::map<int64_t, int64_t>;
|
||||||
using InstOverlapIntervalsTy = DenseMap<Instruction *, OverlapIntervalsTy>;
|
using InstOverlapIntervalsTy = DenseMap<Instruction *, OverlapIntervalsTy>;
|
||||||
|
|
||||||
/// If the value of this instruction and the memory it writes to is unused, may
|
|
||||||
/// we delete this instruction?
|
|
||||||
static bool isRemovable(Instruction *I) {
|
|
||||||
// Don't remove volatile/atomic stores.
|
|
||||||
if (StoreInst *SI = dyn_cast<StoreInst>(I))
|
|
||||||
return SI->isUnordered();
|
|
||||||
|
|
||||||
// Note: only get here for calls with analyzable writes.
|
|
||||||
if (auto *CB = dyn_cast<CallBase>(I)) {
|
|
||||||
// Don't remove volatile memory intrinsics.
|
|
||||||
if (auto *MI = dyn_cast<MemIntrinsic>(CB))
|
|
||||||
return !MI->isVolatile();
|
|
||||||
|
|
||||||
// Never remove dead lifetime intrinsics, e.g. because they are followed by
|
|
||||||
// a free.
|
|
||||||
if (CB->isLifetimeStartOrEnd())
|
|
||||||
return false;
|
|
||||||
|
|
||||||
return CB->use_empty() && CB->willReturn() && CB->doesNotThrow();
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Returns true if the end of this instruction can be safely shortened in
|
/// Returns true if the end of this instruction can be safely shortened in
|
||||||
/// length.
|
/// length.
|
||||||
static bool isShortenableAtTheEnd(Instruction *I) {
|
static bool isShortenableAtTheEnd(Instruction *I) {
|
||||||
|
@ -1024,6 +1000,31 @@ struct DSEState {
|
||||||
return MemoryLocation::getOrNone(I);
|
return MemoryLocation::getOrNone(I);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Assuming this instruction has a dead analyzable write, can we delete
|
||||||
|
/// this instruction?
|
||||||
|
bool isRemovable(Instruction *I) {
|
||||||
|
assert(getLocForWriteEx(I) && "Must have analyzable write");
|
||||||
|
|
||||||
|
// Don't remove volatile/atomic stores.
|
||||||
|
if (StoreInst *SI = dyn_cast<StoreInst>(I))
|
||||||
|
return SI->isUnordered();
|
||||||
|
|
||||||
|
if (auto *CB = dyn_cast<CallBase>(I)) {
|
||||||
|
// Don't remove volatile memory intrinsics.
|
||||||
|
if (auto *MI = dyn_cast<MemIntrinsic>(CB))
|
||||||
|
return !MI->isVolatile();
|
||||||
|
|
||||||
|
// Never remove dead lifetime intrinsics, e.g. because they are followed
|
||||||
|
// by a free.
|
||||||
|
if (CB->isLifetimeStartOrEnd())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return CB->use_empty() && CB->willReturn() && CB->doesNotThrow();
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/// Returns true if \p UseInst completely overwrites \p DefLoc
|
/// Returns true if \p UseInst completely overwrites \p DefLoc
|
||||||
/// (stored by \p DefInst).
|
/// (stored by \p DefInst).
|
||||||
bool isCompleteOverwrite(const MemoryLocation &DefLoc, Instruction *DefInst,
|
bool isCompleteOverwrite(const MemoryLocation &DefLoc, Instruction *DefInst,
|
||||||
|
|
Loading…
Reference in New Issue