@@ -340,24 +340,33 @@ static bool isCompleteOverwrite(const AliasAnalysis::Location &Later,
340
340
// Okay, we have stores to two completely different pointers. Try to
341
341
// decompose the pointer into a "base + constant_offset" form. If the base
342
342
// 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);
346
346
347
347
// If the base pointers still differ, we have two completely different stores.
348
348
if (BP1 != BP2)
349
349
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 ;
361
370
}
362
371
363
372
// / isPossibleSelfRead - If 'Inst' might be a self read (i.e. a noop copy of a
0 commit comments