diff options
author | Bill Wendling <isanbard@gmail.com> | 2011-03-26 08:02:59 +0000 |
---|---|---|
committer | Bill Wendling <isanbard@gmail.com> | 2011-03-26 08:02:59 +0000 |
commit | 150c4a1a89478f36af776f9146288afd528b33da (patch) | |
tree | 06ccdd85476d621f3f43e21a08ac8512ffeb7967 | |
parent | c77a10fe0a40861bcb4bd2a0c170c948a57be688 (diff) | |
download | external_llvm-150c4a1a89478f36af776f9146288afd528b33da.zip external_llvm-150c4a1a89478f36af776f9146288afd528b33da.tar.gz external_llvm-150c4a1a89478f36af776f9146288afd528b33da.tar.bz2 |
Rework the logic that determines if a store completely overlaps an ealier store.
There are two ways that a later store can comletely overlap a previous store:
1. They both start at the same offset, but the earlier store's size is <= the
later's size, or
2. The earlier store's offset is > the later's offset, but it's offset + size
doesn't extend past the later's offset + size.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@128332 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/Transforms/Scalar/DeadStoreElimination.cpp | 38 |
1 files changed, 23 insertions, 15 deletions
diff --git a/lib/Transforms/Scalar/DeadStoreElimination.cpp b/lib/Transforms/Scalar/DeadStoreElimination.cpp index d07cf07..7d957f0 100644 --- a/lib/Transforms/Scalar/DeadStoreElimination.cpp +++ b/lib/Transforms/Scalar/DeadStoreElimination.cpp @@ -340,26 +340,34 @@ static bool isCompleteOverwrite(const AliasAnalysis::Location &Later, // Okay, we have stores to two completely different pointers. Try to // decompose the pointer into a "base + constant_offset" form. If the base // pointers are equal, then we can reason about the two stores. - int64_t Off1 = 0, Off2 = 0; - const Value *BP1 = GetPointerBaseWithConstantOffset(P1, Off1, TD); - const Value *BP2 = GetPointerBaseWithConstantOffset(P2, Off2, TD); + int64_t EarlierOff = 0, LaterOff = 0; + const Value *BP1 = GetPointerBaseWithConstantOffset(P1, EarlierOff, TD); + const Value *BP2 = GetPointerBaseWithConstantOffset(P2, LaterOff, TD); // If the base pointers still differ, we have two completely different stores. if (BP1 != BP2) return false; - - // Otherwise, we might have a situation like: - // store i16 -> P + 1 Byte - // store i32 -> P - // In this case, we see if the later store completely overlaps all bytes - // stored by the previous store. - if (Off1 < Off2 || // Earlier starts before Later. - Off2 < 0 || // Later is -. - Off1+Earlier.Size > Off2+Later.Size) // Earlier goes beyond Later. - return false; - // Otherwise, we have complete overlap. - return true; + // The later store completely overlaps the earlier store if: + // + // 1. Both start at the same offset and the later one's size is greater than + // or equal to the earlier one's, or + // + // |--earlier--| + // |-- later --| + // + // 2. The earlier store has an offset greater than the later offset, but which + // still lies completely within the later store. + // + // |--earlier--| + // |----- later ------| + if ((EarlierOff == LaterOff && Earlier.Size <= Later.Size) || + (EarlierOff > LaterOff && + EarlierOff + Earlier.Size <= LaterOff + Later.Size)) + return true; + + // Otherwise, they don't completely overlap. + return false; } /// isPossibleSelfRead - If 'Inst' might be a self read (i.e. a noop copy of a |