[PATCH] D98557: [MemorySSA] Don't bail on phi starting access
Nikita Popov via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Mar 12 14:12:41 PST 2021
nikic created this revision.
nikic added reviewers: asbirlea, fhahn.
Herald added subscribers: jfb, george.burgess.iv, hiraditya, Prazek.
nikic requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
When calling `getClobberingMemoryAccess()` with MemoryLocation on a MemoryPHI starting access, the walker currently immediately bails and returns the starting access. This makes sense for the API that does not accept a location (as we wouldn't know what clobber we should be checking for), but doesn't make sense for the MemoryLocation-based API. This means that it can't look through a MemoryPHI if it's the starting access, but can if there is one more non-clobbering def in between. This patch removes the limitation.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D98557
Files:
llvm/lib/Analysis/MemorySSA.cpp
llvm/test/Transforms/MemCpyOpt/memcpy-in-loop.ll
Index: llvm/test/Transforms/MemCpyOpt/memcpy-in-loop.ll
===================================================================
--- llvm/test/Transforms/MemCpyOpt/memcpy-in-loop.ll
+++ llvm/test/Transforms/MemCpyOpt/memcpy-in-loop.ll
@@ -12,7 +12,6 @@
; CHECK: loop:
; CHECK-NEXT: [[CURRENT:%.*]] = phi [1000 x i32]* [ [[BEGIN]], [[START:%.*]] ], [ [[NEXT:%.*]], [[LOOP]] ]
; CHECK-NEXT: [[CURRENT_I8:%.*]] = bitcast [1000 x i32]* [[CURRENT]] to i8*
-; CHECK-NEXT: call void @llvm.memcpy.p0i8.p0i8.i64(i8* nonnull align 4 dereferenceable(4000) [[CURRENT_I8]], i8* nonnull align 4 dereferenceable(4000) [[ALLOCA_I8]], i64 4000, i1 false)
; CHECK-NEXT: [[NEXT]] = getelementptr inbounds [1000 x i32], [1000 x i32]* [[CURRENT]], i64 1
; CHECK-NEXT: [[COND:%.*]] = icmp eq [1000 x i32]* [[NEXT]], [[END]]
; CHECK-NEXT: br i1 [[COND]], label [[EXIT:%.*]], label [[LOOP]]
@@ -50,7 +49,7 @@
; CHECK: loop:
; CHECK-NEXT: [[CURRENT:%.*]] = phi [1000 x i32]* [ [[BEGIN]], [[START:%.*]] ], [ [[NEXT:%.*]], [[LOOP]] ]
; CHECK-NEXT: [[CURRENT_I8:%.*]] = bitcast [1000 x i32]* [[CURRENT]] to i8*
-; CHECK-NEXT: call void @llvm.memcpy.p0i8.p0i8.i64(i8* nonnull align 4 dereferenceable(4000) [[CURRENT_I8]], i8* nonnull align 4 dereferenceable(4000) [[ALLOCA_I8]], i64 4000, i1 false)
+; CHECK-NEXT: call void @llvm.memset.p0i8.i64(i8* align 4 [[CURRENT_I8]], i8 0, i64 4000, i1 false)
; CHECK-NEXT: [[NEXT]] = getelementptr inbounds [1000 x i32], [1000 x i32]* [[CURRENT]], i64 1
; CHECK-NEXT: [[COND:%.*]] = icmp eq [1000 x i32]* [[NEXT]], [[END]]
; CHECK-NEXT: br i1 [[COND]], label [[EXIT:%.*]], label [[LOOP]]
Index: llvm/lib/Analysis/MemorySSA.cpp
===================================================================
--- llvm/lib/Analysis/MemorySSA.cpp
+++ llvm/lib/Analysis/MemorySSA.cpp
@@ -2402,22 +2402,23 @@
MemorySSA::ClobberWalkerBase<AliasAnalysisType>::getClobberingMemoryAccessBase(
MemoryAccess *StartingAccess, const MemoryLocation &Loc,
unsigned &UpwardWalkLimit) {
- if (isa<MemoryPhi>(StartingAccess))
- return StartingAccess;
+ assert(!isa<MemoryUse>(StartingAccess) && "Use cannot be defining access");
- auto *StartingUseOrDef = cast<MemoryUseOrDef>(StartingAccess);
- if (MSSA->isLiveOnEntryDef(StartingUseOrDef))
- return StartingUseOrDef;
+ Instruction *I = nullptr;
+ if (auto *StartingUseOrDef = dyn_cast<MemoryUseOrDef>(StartingAccess)) {
+ if (MSSA->isLiveOnEntryDef(StartingUseOrDef))
+ return StartingUseOrDef;
- Instruction *I = StartingUseOrDef->getMemoryInst();
+ I = StartingUseOrDef->getMemoryInst();
- // Conservatively, fences are always clobbers, so don't perform the walk if we
- // hit a fence.
- if (!isa<CallBase>(I) && I->isFenceLike())
- return StartingUseOrDef;
+ // Conservatively, fences are always clobbers, so don't perform the walk if
+ // we hit a fence.
+ if (!isa<CallBase>(I) && I->isFenceLike())
+ return StartingUseOrDef;
+ }
UpwardsMemoryQuery Q;
- Q.OriginalAccess = StartingUseOrDef;
+ Q.OriginalAccess = StartingAccess;
Q.StartingLoc = Loc;
Q.Inst = nullptr;
Q.IsCall = false;
@@ -2425,16 +2426,14 @@
// Unlike the other function, do not walk to the def of a def, because we are
// handed something we already believe is the clobbering access.
// We never set SkipSelf to true in Q in this method.
- MemoryAccess *DefiningAccess = isa<MemoryUse>(StartingUseOrDef)
- ? StartingUseOrDef->getDefiningAccess()
- : StartingUseOrDef;
-
MemoryAccess *Clobber =
- Walker.findClobber(DefiningAccess, Q, UpwardWalkLimit);
- LLVM_DEBUG(dbgs() << "Starting Memory SSA clobber for " << *I << " is ");
- LLVM_DEBUG(dbgs() << *StartingUseOrDef << "\n");
- LLVM_DEBUG(dbgs() << "Final Memory SSA clobber for " << *I << " is ");
- LLVM_DEBUG(dbgs() << *Clobber << "\n");
+ Walker.findClobber(StartingAccess, Q, UpwardWalkLimit);
+ LLVM_DEBUG({
+ dbgs() << "Clobber starting at access " << *StartingAccess << "\n";
+ if (I)
+ dbgs() << " for instruction " << *I << "\n";
+ dbgs() << " is " << *Clobber << "\n";
+ });
return Clobber;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D98557.330370.patch
Type: text/x-patch
Size: 4223 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210312/6eb096d5/attachment.bin>
More information about the llvm-commits
mailing list