Skip to content

Commit c5dbfa2

Browse files
committed
[AggressiveInstCombine] Fix memory location for alias analysis
1 parent c746edf commit c5dbfa2

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

llvm/lib/Transforms/AggressiveInstCombine/AggressiveInstCombine.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -710,9 +710,17 @@ static bool foldLoadsRecursive(Value *V, LoadOps &LOps, const DataLayout &DL,
710710
MemoryLocation Loc;
711711
if (!Start->comesBefore(End)) {
712712
std::swap(Start, End);
713-
Loc = MemoryLocation::get(End);
713+
// If LOps.RootInsert comes after LI2, since we use LI2 as the new insert
714+
// point, we should make sure whether the memory region accessed by LOps
715+
// isn't modified.
714716
if (LOps.FoundRoot)
715-
Loc = Loc.getWithNewSize(LOps.LoadSize);
717+
Loc = MemoryLocation(
718+
LOps.Root->getPointerOperand(),
719+
LocationSize::precise(DL.getTypeStoreSize(
720+
IntegerType::get(LI1->getContext(), LOps.LoadSize))),
721+
LOps.AATags);
722+
else
723+
Loc = MemoryLocation::get(End);
716724
} else
717725
Loc = MemoryLocation::get(End);
718726
unsigned NumScanned = 0;

llvm/test/Transforms/AggressiveInstCombine/X86/or-load.ll

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2512,8 +2512,14 @@ entry:
25122512
define i64 @loadcombine_consecutive_mayalias(ptr %p) {
25132513
; LE-LABEL: @loadcombine_consecutive_mayalias(
25142514
; LE-NEXT: entry:
2515-
; LE-NEXT: [[LOAD1:%.*]] = load i64, ptr [[P:%.*]], align 4
2515+
; LE-NEXT: [[LOAD3:%.*]] = load i32, ptr [[P:%.*]], align 4
2516+
; LE-NEXT: [[GEP1:%.*]] = getelementptr i8, ptr [[P]], i64 4
25162517
; LE-NEXT: store i8 0, ptr getelementptr inbounds nuw (i8, ptr @g, i64 4), align 4
2518+
; LE-NEXT: [[LOAD2:%.*]] = load i32, ptr [[GEP1]], align 4
2519+
; LE-NEXT: [[TMP0:%.*]] = zext i32 [[LOAD2]] to i64
2520+
; LE-NEXT: [[TMP1:%.*]] = shl i64 [[TMP0]], 32
2521+
; LE-NEXT: [[ZEXT3:%.*]] = zext i32 [[LOAD3]] to i64
2522+
; LE-NEXT: [[LOAD1:%.*]] = or i64 [[TMP1]], [[ZEXT3]]
25172523
; LE-NEXT: [[RES:%.*]] = lshr i64 [[LOAD1]], 32
25182524
; LE-NEXT: ret i64 [[RES]]
25192525
;

0 commit comments

Comments
 (0)