llvm.org GIT mirror llvm / 6327268
[MemorySSA] Don't use template when the clone is a simplified instruction. Summary: 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. Reviewers: george.burgess.iv Subscribers: jlebar, Prazek, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D63355 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@363597 91177308-0d34-0410-b5e6-96231b3b80d8 Alina Sbirlea a month ago
3 changed file(s) with 45 addition(s) and 4 deletion(s). Raw diff Collapse all Expand all
286286 // not necessarily be MemoryPhis themselves, they may be MemoryDefs. As such,
287287 // the map is between MemoryPhis and MemoryAccesses, where the MemoryAccesses
288288 // may be MemoryPhis or MemoryDefs and not MemoryUses.
289 // If CloneWasSimplified = true, the clone was exact. Otherwise, assume that
290 // the clone involved simplifications that may have: (1) turned a MemoryUse
291 // into an instruction that MemorySSA has no representation for, or (2) turned
292 // a MemoryDef into a MemoryUse or an instruction that MemorySSA has no
293 // representation for. No other cases are supported.
289294 void cloneUsesAndDefs(BasicBlock *BB, BasicBlock *NewBB,
290 const ValueToValueMapTy &VMap, PhiToDefMap &MPhiMap);
295 const ValueToValueMapTy &VMap, PhiToDefMap &MPhiMap,
296 bool CloneWasSimplified = false);
291297 template
292298 void privateUpdateExitBlocksForClonedLoop(ArrayRef ExitBlocks,
293299 Iter ValuesBegin, Iter ValuesEnd,
481481
482482 void MemorySSAUpdater::cloneUsesAndDefs(BasicBlock *BB, BasicBlock *NewBB,
483483 const ValueToValueMapTy &VMap,
484 PhiToDefMap &MPhiMap) {
484 PhiToDefMap &MPhiMap,
485 bool CloneWasSimplified) {
485486 auto GetNewDefiningAccess = [&](MemoryAccess *MA) -> MemoryAccess * {
486487 MemoryAccess *InsnDefining = MA;
487488 if (MemoryUseOrDef *DefMUD = dyn_cast(InsnDefining)) {
511512 // instructions. This occurs in LoopRotate when cloning instructions
512513 // from the old header to the old preheader. The cloned instruction may
513514 // also be a simplified Value, not an Instruction (see LoopRotate).
515 // Also in LoopRotate, even when it's an instruction, due to it being
516 // simplified, it may be a Use rather than a Def, so we cannot use MUD as
517 // template. Calls coming from updateForClonedBlockIntoPred, ensure this.
514518 if (Instruction *NewInsn =
515519 dyn_cast_or_null(VMap.lookup(Insn))) {
516520 MemoryAccess *NewUseOrDef = MSSA->createDefinedAccess(
517 NewInsn, GetNewDefiningAccess(MUD->getDefiningAccess()), MUD);
521 NewInsn, GetNewDefiningAccess(MUD->getDefiningAccess()),
522 CloneWasSimplified ? nullptr : MUD);
518523 MSSA->insertIntoListsForBlock(NewUseOrDef, NewBB, MemorySSA::End);
519524 }
520525 }
644649 // Defs from BB being used in BB will be replaced with the cloned defs from
645650 // VM. The uses of BB's Phi (if it exists) in BB will be replaced by the
646651 // incoming def into the Phi from P1.
652 // Instructions cloned into the predecessor are in practice sometimes
653 // simplified, so disable the use of the template, and create an access from
654 // scratch.
647655 PhiToDefMap MPhiMap;
648656 if (MemoryPhi *MPhi = MSSA->getMemoryAccess(BB))
649657 MPhiMap[MPhi] = MPhi->getIncomingValueForBlock(P1);
650 cloneUsesAndDefs(BB, P1, VM, MPhiMap);
658 cloneUsesAndDefs(BB, P1, VM, MPhiMap, /*CloneWasSimplified=*/true);
651659 }
652660
653661 template
0 ; RUN: opt -disable-output -loop-rotate -enable-mssa-loop-dependency -verify-memoryssa %s
1 ; REQUIRES: asserts
2
3 ; Function Attrs: nounwind
4 define dso_local void @bar() local_unnamed_addr #0 align 32 {
5 entry:
6 br label %looplabel.exit.i
7
8 looplabel.exit.i: ; preds = %if.end.i, %entry
9 %0 = phi i1 (i32*, i32*)* [ @foo, %entry ], [ undef, %if.end.i ]
10 %call3.i.i = call zeroext i1 %0(i32* nonnull dereferenceable(16) undef, i32* nonnull undef)
11 br i1 %call3.i.i, label %if.end.i, label %label.exit
12
13 if.end.i: ; preds = %looplabel.exit.i
14 %tobool.i = icmp eq i32* undef, null
15 br label %looplabel.exit.i
16
17 label.exit: ; preds = %looplabel.exit.i
18 ret void
19 }
20
21 ; Function Attrs: readonly
22 declare dso_local i1 @foo(i32*, i32*) #1 align 32
23
24 attributes #0 = { nounwind }
25 attributes #1 = { readonly }
26