[PATCH] D63355: [MemorySSA] Don't use template when the clone is a simplified instruction.
Alina Sbirlea via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Jun 14 12:14:39 PDT 2019
asbirlea created this revision.
asbirlea added a reviewer: george.burgess.iv.
Herald added subscribers: Prazek, jlebar.
Herald added a project: LLVM.
LoopRotate doesn't create a faithful clone of an instruction, it may
simplify it beforehand. Hence the clone of an instruction that has a
MemoryDef associated may not be a definition, but a use or not a memory
alternig instruction.
Don't rely on the template when the clone may be simplified.
Repository:
rL LLVM
https://reviews.llvm.org/D63355
Files:
include/llvm/Analysis/MemorySSAUpdater.h
lib/Analysis/MemorySSAUpdater.cpp
test/Analysis/MemorySSA/loop-rotate-inv-template.ll
Index: test/Analysis/MemorySSA/loop-rotate-inv-template.ll
===================================================================
--- /dev/null
+++ test/Analysis/MemorySSA/loop-rotate-inv-template.ll
@@ -0,0 +1,27 @@
+; RUN: opt -disable-output -loop-rotate -enable-mssa-loop-dependency -verify-memoryssa %s
+; REQUIRES: asserts
+
+; Function Attrs: nounwind
+define dso_local void @bar() local_unnamed_addr #0 align 32 {
+entry:
+ br label %looplabel.exit.i
+
+looplabel.exit.i: ; preds = %if.end.i, %entry
+ %0 = phi i1 (i32*, i32*)* [ @foo, %entry ], [ undef, %if.end.i ]
+ %call3.i.i = call zeroext i1 %0(i32* nonnull dereferenceable(16) undef, i32* nonnull undef)
+ br i1 %call3.i.i, label %if.end.i, label %label.exit
+
+if.end.i: ; preds = %looplabel.exit.i
+ %tobool.i = icmp eq i32* undef, null
+ br label %looplabel.exit.i
+
+label.exit: ; preds = %looplabel.exit.i
+ ret void
+}
+
+; Function Attrs: readonly
+declare dso_local i1 @foo(i32*, i32*) #1 align 32
+
+attributes #0 = { nounwind }
+attributes #1 = { readonly }
+
Index: lib/Analysis/MemorySSAUpdater.cpp
===================================================================
--- lib/Analysis/MemorySSAUpdater.cpp
+++ lib/Analysis/MemorySSAUpdater.cpp
@@ -482,7 +482,8 @@
void MemorySSAUpdater::cloneUsesAndDefs(BasicBlock *BB, BasicBlock *NewBB,
const ValueToValueMapTy &VMap,
- PhiToDefMap &MPhiMap) {
+ PhiToDefMap &MPhiMap,
+ bool useTemplateMUD) {
auto GetNewDefiningAccess = [&](MemoryAccess *MA) -> MemoryAccess * {
MemoryAccess *InsnDefining = MA;
if (MemoryUseOrDef *DefMUD = dyn_cast<MemoryUseOrDef>(InsnDefining)) {
@@ -512,10 +513,14 @@
// instructions. This occurs in LoopRotate when cloning instructions
// from the old header to the old preheader. The cloned instruction may
// also be a simplified Value, not an Instruction (see LoopRotate).
+ // Also in LoopRotate, even when it's an instruction, due to it being
+ // simplified, it may be a Use rather than a Def, so we cannot use MUD as
+ // template. Calls coming from updateForClonedBlockIntoPred, ensure this.
if (Instruction *NewInsn =
dyn_cast_or_null<Instruction>(VMap.lookup(Insn))) {
MemoryAccess *NewUseOrDef = MSSA->createDefinedAccess(
- NewInsn, GetNewDefiningAccess(MUD->getDefiningAccess()), MUD);
+ NewInsn, GetNewDefiningAccess(MUD->getDefiningAccess()),
+ useTemplateMUD ? MUD : nullptr);
MSSA->insertIntoListsForBlock(NewUseOrDef, NewBB, MemorySSA::End);
}
}
@@ -645,10 +650,13 @@
// Defs from BB being used in BB will be replaced with the cloned defs from
// VM. The uses of BB's Phi (if it exists) in BB will be replaced by the
// incoming def into the Phi from P1.
+ // Instructions cloned into the predecessor are in practice sometimes
+ // simplified, so disable the use of the template, and create an access from
+ // scratch.
PhiToDefMap MPhiMap;
if (MemoryPhi *MPhi = MSSA->getMemoryAccess(BB))
MPhiMap[MPhi] = MPhi->getIncomingValueForBlock(P1);
- cloneUsesAndDefs(BB, P1, VM, MPhiMap);
+ cloneUsesAndDefs(BB, P1, VM, MPhiMap, false);
}
template <typename Iter>
Index: include/llvm/Analysis/MemorySSAUpdater.h
===================================================================
--- include/llvm/Analysis/MemorySSAUpdater.h
+++ include/llvm/Analysis/MemorySSAUpdater.h
@@ -288,7 +288,8 @@
// the map is between MemoryPhis and MemoryAccesses, where the MemoryAccesses
// may be MemoryPhis or MemoryDefs and not MemoryUses.
void cloneUsesAndDefs(BasicBlock *BB, BasicBlock *NewBB,
- const ValueToValueMapTy &VMap, PhiToDefMap &MPhiMap);
+ const ValueToValueMapTy &VMap, PhiToDefMap &MPhiMap,
+ bool useTemplateMUD = true);
template <typename Iter>
void privateUpdateExitBlocksForClonedLoop(ArrayRef<BasicBlock *> ExitBlocks,
Iter ValuesBegin, Iter ValuesEnd,
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D63355.204828.patch
Type: text/x-patch
Size: 4217 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190614/5e91b6a5/attachment.bin>
More information about the llvm-commits
mailing list