diff options
author | Bill Wendling <isanbard@gmail.com> | 2011-03-27 00:42:33 +0000 |
---|---|---|
committer | Bill Wendling <isanbard@gmail.com> | 2011-03-27 00:42:33 +0000 |
commit | d1b59c20e3ebe07dacc97e7bdef3c191c4596fc9 (patch) | |
tree | 1210b611029a2db000c3775a0ed6d25ebe1a3831 | |
parent | 4b28ae012749fd4c4d91213ae7f39767d48cb737 (diff) | |
download | llvm-d1b59c20e3ebe07dacc97e7bdef3c191c4596fc9.zip llvm-d1b59c20e3ebe07dacc97e7bdef3c191c4596fc9.tar.gz llvm-d1b59c20e3ebe07dacc97e7bdef3c191c4596fc9.tar.bz2 |
Merge in fix for PR9561.
llvm-svn: 128354
-rw-r--r-- | llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp | 37 |
1 files changed, 23 insertions, 14 deletions
diff --git a/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp b/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp index 867a06a..b948bed 100644 --- a/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp +++ b/llvm/lib/Transforms/Scalar/DeadStoreElimination.cpp @@ -340,24 +340,33 @@ 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. - 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 && + 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 |