Skip to content

Commit 44b44da

Browse files
Evgeniy Brevnovfhahn
authored andcommitted
[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 (cherry-picked from 47e2644)
1 parent 944f5d0 commit 44b44da

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
@@ -327,6 +327,7 @@ enum OverwriteResult {
327327
OW_End,
328328
OW_PartialEarlierWithFullLater,
329329
OW_MaybePartial,
330+
OW_None,
330331
OW_Unknown
331332
};
332333

@@ -934,6 +935,7 @@ struct DSEState {
934935
/// Return OW_MaybePartial if \p KillingI does not completely overwrite
935936
/// \p DeadI, but they both write to the same underlying object. In that
936937
/// case, use isPartialOverwrite to check if \p KillingI partially overwrites
938+
/// \p DeadI. Returns 'OR_None' if \p KillingI is known to not overwrite the
937939
/// \p DeadI. Returns 'OW_Unknown' if nothing can be determined.
938940
OverwriteResult isOverwrite(const Instruction *KillingI,
939941
const Instruction *DeadI,
@@ -996,8 +998,16 @@ struct DSEState {
996998

997999
// If we can't resolve the same pointers to the same object, then we can't
9981000
// analyze them at all.
999-
if (DeadUndObj != KillingUndObj)
1001+
if (DeadUndObj != KillingUndObj) {
1002+
// Non aliasing stores to different objects don't overlap. Note that
1003+
// if the killing store is known to overwrite whole object (out of
1004+
// bounds access overwrites whole object as well) then it is assumed to
1005+
// completely overwrite any store to the same object even if they don't
1006+
// actually alias (see next check).
1007+
if (AAR == AliasResult::NoAlias)
1008+
return OW_None;
10001009
return OW_Unknown;
1010+
}
10011011

10021012
// If the KillingI store is to a recognizable object, get its size.
10031013
uint64_t KillingUndObjSize = getPointerSize(KillingUndObj, DL, TLI, &F);
@@ -1051,9 +1061,8 @@ struct DSEState {
10511061
return OW_MaybePartial;
10521062
}
10531063

1054-
// Can reach here only if accesses are known not to overlap. There is no
1055-
// dedicated code to indicate no overlap so signal "unknown".
1056-
return OW_Unknown;
1064+
// Can reach here only if accesses are known not to overlap.
1065+
return OW_None;
10571066
}
10581067

10591068
bool isInvisibleToCallerAfterRet(const Value *V) {
@@ -1451,7 +1460,7 @@ struct DSEState {
14511460
KillingOffset, DeadOffset);
14521461
// If Current does not write to the same object as KillingDef, check
14531462
// the next candidate.
1454-
if (OR == OW_Unknown)
1463+
if (OR == OW_Unknown || OR == OW_None)
14551464
continue;
14561465
else if (OR == OW_MaybePartial) {
14571466
// If KillingDef only partially overwrites Current, check the next
@@ -1460,6 +1469,7 @@ struct DSEState {
14601469
// which are less likely to be removable in the end.
14611470
if (PartialLimit <= 1) {
14621471
WalkerStepLimit -= 1;
1472+
LLVM_DEBUG(dbgs() << " ... reached partial limit ... continue with next access\n");
14631473
continue;
14641474
}
14651475
PartialLimit -= 1;

0 commit comments

Comments
 (0)