[PATCH] D143641: [MemorySSA] Recursively check if gep's pointer operand is a guaranteed loop invariant
luxufan via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Feb 9 05:19:29 PST 2023
StephenFan created this revision.
StephenFan added reviewers: nikic, asbirlea.
Herald added subscribers: kmitropoulou, hiraditya.
Herald added a project: All.
StephenFan requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
On the past, we just check if gep's pointer operand is a non-instruction
operand or is a alloca instruction to decide if it is guaranteed to be
a loop invariant. If the gep's pointer operand is also a gep then it would
be considered to be a non-guaranteed loop invariant. This patch makes
MemorySSA Recursively checking if gep's pointer operand is guaranteed
to be a loop invariant.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D143641
Files:
llvm/lib/Analysis/MemorySSA.cpp
llvm/test/Analysis/MemorySSA/loop-invariant.ll
Index: llvm/test/Analysis/MemorySSA/loop-invariant.ll
===================================================================
--- llvm/test/Analysis/MemorySSA/loop-invariant.ll
+++ llvm/test/Analysis/MemorySSA/loop-invariant.ll
@@ -4,7 +4,7 @@
; %p2 is a loop invariant and the MemoryLoc of load instr and store inst in
; loop block are NoAlias
;
-; CHECK: MemoryUse(2)
+; CHECK: MemoryUse(liveOnEntry)
; CHECK: %val = load i32, ptr %p2
define void @gep(ptr %ptr) {
entry:
@@ -24,7 +24,8 @@
br label %loop
}
-; CHECK: MemoryUse(2)
+; CHECK: %x = phi i32 [ 0, %tmp ], [ %x.inc, %loop ]
+; CHECK-NEXT: MemoryUse(liveOnEntry)
; CHECK-NEXT: %val = load i32, ptr %p2
define void @load_entry_block(ptr %ptr, ptr %addr) {
entry:
Index: llvm/lib/Analysis/MemorySSA.cpp
===================================================================
--- llvm/lib/Analysis/MemorySSA.cpp
+++ llvm/lib/Analysis/MemorySSA.cpp
@@ -2625,21 +2625,18 @@
}
bool upward_defs_iterator::IsGuaranteedLoopInvariant(const Value *Ptr) const {
- auto IsGuaranteedLoopInvariantBase = [](const Value *Ptr) {
- Ptr = Ptr->stripPointerCasts();
- if (!isa<Instruction>(Ptr))
- return true;
- return isa<AllocaInst>(Ptr);
- };
-
Ptr = Ptr->stripPointerCasts();
if (auto *I = dyn_cast<Instruction>(Ptr)) {
if (I->getParent()->isEntryBlock())
return true;
}
+
if (auto *GEP = dyn_cast<GEPOperator>(Ptr)) {
- return IsGuaranteedLoopInvariantBase(GEP->getPointerOperand()) &&
+ return IsGuaranteedLoopInvariant(GEP->getPointerOperand()) &&
GEP->hasAllConstantIndices();
}
- return IsGuaranteedLoopInvariantBase(Ptr);
+
+ if (!isa<Instruction>(Ptr))
+ return true;
+ return isa<AllocaInst>(Ptr);
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D143641.496097.patch
Type: text/x-patch
Size: 1732 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230209/4b417e37/attachment.bin>
More information about the llvm-commits
mailing list