[PATCH] D52797: Clear LoopToAliasSetMap when outermost loop is deleted

Huihui Zhang via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 2 13:04:13 PDT 2018


huihuiz created this revision.
huihuiz added reviewers: hfinkel, danielcdh, dpeixott, marcello.maggioni, sanjoy, bogner, efriedma.
Herald added subscribers: dmgreen, zzheng.

If a loop is nested inside another loop, alias information is saved in
LoopToAliasSetMap. Later when processing the outer loop, this alias
information is collected and erased from LoopToAliasSetMap.

However, when outer loop is fully unrolled and deleted, the information
saved in LoopToAliasSetMap will not get erased. This patch clear the
LoopToAliasSetMap when a loop is outermost and being deleted by other
loop pass.


Repository:
  rL LLVM

https://reviews.llvm.org/D52797

Files:
  lib/Transforms/Scalar/LICM.cpp
  test/Transforms/LICM/outer-loop-fully-unrolled.ll


Index: test/Transforms/LICM/outer-loop-fully-unrolled.ll
===================================================================
--- /dev/null
+++ test/Transforms/LICM/outer-loop-fully-unrolled.ll
@@ -0,0 +1,46 @@
+; RUN: opt -S -loop-unroll -licm < %s | FileCheck %s
+
+; Check that when the outer most loop is fully unrolled, the alias information
+; saved in the LoopToAliasSetMap is cleared, without triggering an assertion in
+; doFinalizaton().
+
+; CHECK: store double %{{.+}}, double* %{{.+}}
+; CHECK: store double %{{.+}}, double* %{{.+}}
+; CHECK: store double %{{.+}}, double* %{{.+}}
+; CHECK: store double %{{.+}}, double* %{{.+}}
+; CHECK: store double %{{.+}}, double* %{{.+}}
+; CHECK: store double %{{.+}}, double* %{{.+}}
+; CHECK: store double %{{.+}}, double* %{{.+}}
+; CHECK: store double %{{.+}}, double* %{{.+}}
+
+define void @foo(double** %A) {
+entry:
+  br label %for.cond1.preheader
+
+for.cond1.preheader:
+  %i = phi i32 [ 1, %entry ], [ %inc.i, %for.cond.cleanup3 ]
+  %arrayidx1 = getelementptr inbounds double*, double** %A, i32 %i
+  %t0 = load double*, double** %arrayidx1, align 4
+  br label %for.body4
+
+for.cond.cleanup:
+  ret void
+
+for.cond.cleanup3:
+  %inc.i = add nuw nsw i32 %i, 1
+  %exitcond = icmp eq i32 %inc.i, 9
+  br i1 %exitcond, label %for.cond.cleanup, label %for.cond1.preheader
+
+for.body4:
+  %j = phi i32 [ 0, %for.cond1.preheader ], [ %inc.j, %for.body4 ]
+  %arrayidx2 = getelementptr inbounds double*, double** %A, i32 %j
+  %t1 = load double*, double** %arrayidx2, align 4
+  %arrayidx3 = getelementptr inbounds double, double* %t1, i32 %i
+  %t2 = load double, double* %arrayidx3, align 8
+  %arrayidx4 = getelementptr inbounds double, double* %t0, i32 %j
+  store double %t2, double* %arrayidx4, align 8
+  %inc.j = add nuw nsw i32 %j, 1
+  %cmp2 = icmp eq i32 %inc.j, %i
+  br i1 %cmp2, label %for.cond.cleanup3, label %for.body4
+}
+
Index: lib/Transforms/Scalar/LICM.cpp
===================================================================
--- lib/Transforms/Scalar/LICM.cpp
+++ lib/Transforms/Scalar/LICM.cpp
@@ -1596,6 +1596,9 @@
 /// Simple Analysis hook. Delete value L from alias set map.
 ///
 void LegacyLICMPass::deleteAnalysisLoop(Loop *L) {
+  if (!L->getParentLoop())
+    LICM.getLoopToAliasSetMap().clear();
+
   if (!LICM.getLoopToAliasSetMap().count(L))
     return;
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D52797.168003.patch
Type: text/x-patch
Size: 2353 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20181002/28ae6a37/attachment.bin>


More information about the llvm-commits mailing list