Skip to content

Commit db2629e

Browse files
committed
Merge in fix for PR9561.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/branches/release_29@128354 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 59460ab commit db2629e

File tree

1 file changed

+23
-14
lines changed

1 file changed

+23
-14
lines changed

lib/Transforms/Scalar/DeadStoreElimination.cpp

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -340,24 +340,33 @@ static bool isCompleteOverwrite(const AliasAnalysis::Location &Later,
340340
// Okay, we have stores to two completely different pointers. Try to
341341
// decompose the pointer into a "base + constant_offset" form. If the base
342342
// pointers are equal, then we can reason about the two stores.
343-
int64_t Off1 = 0, Off2 = 0;
344-
const Value *BP1 = GetPointerBaseWithConstantOffset(P1, Off1, TD);
345-
const Value *BP2 = GetPointerBaseWithConstantOffset(P2, Off2, TD);
343+
int64_t EarlierOff = 0, LaterOff = 0;
344+
const Value *BP1 = GetPointerBaseWithConstantOffset(P1, EarlierOff, TD);
345+
const Value *BP2 = GetPointerBaseWithConstantOffset(P2, LaterOff, TD);
346346

347347
// If the base pointers still differ, we have two completely different stores.
348348
if (BP1 != BP2)
349349
return false;
350-
351-
// Otherwise, we might have a situation like:
352-
// store i16 -> P + 1 Byte
353-
// store i32 -> P
354-
// In this case, we see if the later store completely overlaps all bytes
355-
// stored by the previous store.
356-
if (Off1 < Off2 || // Earlier starts before Later.
357-
Off1+Earlier.Size > Off2+Later.Size) // Earlier goes beyond Later.
358-
return false;
359-
// Otherwise, we have complete overlap.
360-
return true;
350+
351+
// The later store completely overlaps the earlier store if:
352+
//
353+
// 1. Both start at the same offset and the later one's size is greater than
354+
// or equal to the earlier one's, or
355+
//
356+
// |--earlier--|
357+
// |-- later --|
358+
//
359+
// 2. The earlier store has an offset greater than the later offset, but which
360+
// still lies completely within the later store.
361+
//
362+
// |--earlier--|
363+
// |----- later ------|
364+
if (EarlierOff >= LaterOff &&
365+
EarlierOff + Earlier.Size <= LaterOff + Later.Size)
366+
return true;
367+
368+
// Otherwise, they don't completely overlap.
369+
return false;
361370
}
362371

363372
/// isPossibleSelfRead - If 'Inst' might be a self read (i.e. a noop copy of a

0 commit comments

Comments
 (0)