[llvm] r290427 - [LICM] Work around LICM needs to maintain state across loops.

Davide Italiano via llvm-commits llvm-commits at lists.llvm.org
Fri Dec 23 05:12:50 PST 2016


Author: davide
Date: Fri Dec 23 07:12:50 2016
New Revision: 290427

URL: http://llvm.org/viewvc/llvm-project?rev=290427&view=rev
Log:
[LICM] Work around LICM needs to maintain state across loops.

The pass creates some state which expects to be cleaned up by
a later instance of the same pass. opt-bisect happens to expose
this not ideal design because calling skipLoop() will result in
this state not being cleaned up at times and an assertion firing
in `doFinalization()`. Chandler tells me the new pass manager will
give us options to avoid these design traps, but until it's not ready,
we need a workaround for the current pass infrastructure. Fix provided
by Andy Kaylor, see the review for a complete discussion.

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

Added:
    llvm/trunk/test/Transforms/LICM/bisect-state.ll
Modified:
    llvm/trunk/lib/Transforms/Scalar/LICM.cpp

Modified: llvm/trunk/lib/Transforms/Scalar/LICM.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/LICM.cpp?rev=290427&r1=290426&r2=290427&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/LICM.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/LICM.cpp Fri Dec 23 07:12:50 2016
@@ -124,8 +124,13 @@ struct LegacyLICMPass : public LoopPass
   }
 
   bool runOnLoop(Loop *L, LPPassManager &LPM) override {
-    if (skipLoop(L))
+    if (skipLoop(L)) {
+      // If we have run LICM on a previous loop but now we are skipping
+      // (because we've hit the opt-bisect limit), we need to clear the
+      // loop alias information.
+      LICM.getLoopToAliasSetMap().clear();
       return false;
+    }
 
     auto *SE = getAnalysisIfAvailable<ScalarEvolutionWrapperPass>();
     return LICM.runOnLoop(L,

Added: llvm/trunk/test/Transforms/LICM/bisect-state.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/LICM/bisect-state.ll?rev=290427&view=auto
==============================================================================
--- llvm/trunk/test/Transforms/LICM/bisect-state.ll (added)
+++ llvm/trunk/test/Transforms/LICM/bisect-state.ll Fri Dec 23 07:12:50 2016
@@ -0,0 +1,15 @@
+; Make sure we don't crash in LICM.
+; RUN: opt %s -licm -opt-bisect-limit=1
+
+define void @patatino() {
+for.cond1:
+  br label %for.body
+for.body:
+  br label %for.cond5
+for.cond5:
+  br i1 true, label %if.end, label %for.end
+if.end:
+  br label %for.cond5
+for.end:
+  br label %for.body
+}




More information about the llvm-commits mailing list