Skip to content

Commit 47e2644

Browse files
author
Evgeniy Brevnov
committed
[DSE][NFC] Introduce "doesn't overwrite" return code for isOverwrite
Add OR_None code to indicate that there is no overwrite. This has no any effect for current uses but will be used in one of the next patches building support for PHI translation. Reviewed By: fhahn Differential Revision: https://reviews.llvm.org/D105098
1 parent a5fff58 commit 47e2644

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,7 @@ enum OverwriteResult {
256256
OW_End,
257257
OW_PartialEarlierWithFullLater,
258258
OW_MaybePartial,
259+
OW_None,
259260
OW_Unknown
260261
};
261262

@@ -849,6 +850,7 @@ struct DSEState {
849850
/// Return OW_MaybePartial if \p KillingI does not completely overwrite
850851
/// \p DeadI, but they both write to the same underlying object. In that
851852
/// case, use isPartialOverwrite to check if \p KillingI partially overwrites
853+
/// \p DeadI. Returns 'OR_None' if \p KillingI is known to not overwrite the
852854
/// \p DeadI. Returns 'OW_Unknown' if nothing can be determined.
853855
OverwriteResult isOverwrite(const Instruction *KillingI,
854856
const Instruction *DeadI,
@@ -911,8 +913,16 @@ struct DSEState {
911913

912914
// If we can't resolve the same pointers to the same object, then we can't
913915
// analyze them at all.
914-
if (DeadUndObj != KillingUndObj)
916+
if (DeadUndObj != KillingUndObj) {
917+
// Non aliasing stores to different objects don't overlap. Note that
918+
// if the killing store is known to overwrite whole object (out of
919+
// bounds access overwrites whole object as well) then it is assumed to
920+
// completely overwrite any store to the same object even if they don't
921+
// actually alias (see next check).
922+
if (AAR == AliasResult::NoAlias)
923+
return OW_None;
915924
return OW_Unknown;
925+
}
916926

917927
// If the KillingI store is to a recognizable object, get its size.
918928
uint64_t KillingUndObjSize = getPointerSize(KillingUndObj, DL, TLI, &F);
@@ -966,9 +976,8 @@ struct DSEState {
966976
return OW_MaybePartial;
967977
}
968978

969-
// Can reach here only if accesses are known not to overlap. There is no
970-
// dedicated code to indicate no overlap so signal "unknown".
971-
return OW_Unknown;
979+
// Can reach here only if accesses are known not to overlap.
980+
return OW_None;
972981
}
973982

974983
bool isInvisibleToCallerAfterRet(const Value *V) {
@@ -1368,7 +1377,7 @@ struct DSEState {
13681377
KillingOffset, DeadOffset);
13691378
// If Current does not write to the same object as KillingDef, check
13701379
// the next candidate.
1371-
if (OR == OW_Unknown)
1380+
if (OR == OW_Unknown || OR == OW_None)
13721381
continue;
13731382
else if (OR == OW_MaybePartial) {
13741383
// If KillingDef only partially overwrites Current, check the next
@@ -1377,6 +1386,7 @@ struct DSEState {
13771386
// which are less likely to be removable in the end.
13781387
if (PartialLimit <= 1) {
13791388
WalkerStepLimit -= 1;
1389+
LLVM_DEBUG(dbgs() << " ... reached partial limit ... continue with next access\n");
13801390
continue;
13811391
}
13821392
PartialLimit -= 1;

0 commit comments

Comments
 (0)