]> granicus.if.org Git - llvm/commitdiff
[LoopRotate + MemorySSA] Keep an <instruction-cloned instruction> map.
authorAlina Sbirlea <asbirlea@google.com>
Wed, 10 Jul 2019 17:36:56 +0000 (17:36 +0000)
committerAlina Sbirlea <asbirlea@google.com>
Wed, 10 Jul 2019 17:36:56 +0000 (17:36 +0000)
Summary:
The map kept in loop rotate is used for instruction remapping, in order
to simplify the clones of instructions. Thus, if an instruction can be
simplified, its simplified value is placed in the map, even when the
clone is added to the IR. MemorySSA in contrast needs to know about that
clone, so it can add an access for it.
To resolve this: keep a different map for MemorySSA.

Reviewers: george.burgess.iv

Subscribers: jlebar, Prazek, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D63680

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@365672 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Transforms/Utils/LoopRotationUtils.cpp
test/Analysis/MemorySSA/loop-rotate-valuemap.ll [new file with mode: 0644]

index 88c4937cfe171ec88bb1041a8eac0d2a9a33cc5f..37389a695b455a229948f6afabc42dfcee7a366a 100644 (file)
@@ -295,7 +295,7 @@ bool LoopRotate::rotateLoop(Loop *L, bool SimplifiedLatch) {
   // Begin by walking OrigHeader and populating ValueMap with an entry for
   // each Instruction.
   BasicBlock::iterator I = OrigHeader->begin(), E = OrigHeader->end();
-  ValueToValueMapTy ValueMap;
+  ValueToValueMapTy ValueMap, ValueMapMSSA;
 
   // For PHI nodes, the value available in OldPreHeader is just the
   // incoming value from OldPreHeader.
@@ -374,6 +374,9 @@ bool LoopRotate::rotateLoop(Loop *L, bool SimplifiedLatch) {
       if (auto *II = dyn_cast<IntrinsicInst>(C))
         if (II->getIntrinsicID() == Intrinsic::assume)
           AC->registerAssumption(II);
+      // MemorySSA cares whether the cloned instruction was inserted or not, and
+      // not whether it can be remapped to a simplified value.
+      ValueMapMSSA[Inst] = C;
     }
   }
 
@@ -391,10 +394,11 @@ bool LoopRotate::rotateLoop(Loop *L, bool SimplifiedLatch) {
   LoopEntryBranch->eraseFromParent();
 
   // Update MemorySSA before the rewrite call below changes the 1:1
-  // instruction:cloned_instruction_or_value mapping in ValueMap.
+  // instruction:cloned_instruction_or_value mapping.
   if (MSSAU) {
-    ValueMap[OrigHeader] = OrigPreheader;
-    MSSAU->updateForClonedBlockIntoPred(OrigHeader, OrigPreheader, ValueMap);
+    ValueMapMSSA[OrigHeader] = OrigPreheader;
+    MSSAU->updateForClonedBlockIntoPred(OrigHeader, OrigPreheader,
+                                        ValueMapMSSA);
   }
 
   SmallVector<PHINode*, 2> InsertedPHIs;
diff --git a/test/Analysis/MemorySSA/loop-rotate-valuemap.ll b/test/Analysis/MemorySSA/loop-rotate-valuemap.ll
new file mode 100644 (file)
index 0000000..1ee5fca
--- /dev/null
@@ -0,0 +1,26 @@
+; RUN: opt -loop-rotate -enable-mssa-loop-dependency %s -S | FileCheck %s
+; REQUIRES: asserts
+
+; Check that loop rotate keeps proper mapping between cloned instructions,
+; otherwise, MemorySSA will assert.
+
+; CHECK-LABEL: @f
+define void @f() {
+entry:
+  br label %for.body16
+
+for.cond.cleanup15:                               ; preds = %for.body16
+  ret void
+
+for.body16:                                       ; preds = %for.body16.for.body16_crit_edge, %entry
+  %call.i = tail call float @expf(float 0.000000e+00) #1
+  %0 = load float*, float** undef, align 8
+  br i1 undef, label %for.cond.cleanup15, label %for.body16.for.body16_crit_edge
+
+for.body16.for.body16_crit_edge:                  ; preds = %for.body16
+  %.pre = load float, float* undef, align 8
+  br label %for.body16
+}
+
+declare float @expf(float)
+