Dead code elimination: Update dependences after eliminating code
authorTobias Grosser <tobias@grosser.es>
Wed, 17 Dec 2014 21:13:55 +0000 (21:13 +0000)
committerTobias Grosser <tobias@grosser.es>
Wed, 17 Dec 2014 21:13:55 +0000 (21:13 +0000)
Without updating dependences we may lose implicit transitive dependences for
which all explicit dependences have gone through the statement iterations we
have just eliminated.

No test case. We should probably implement a -verify-dependences option.

This fixes llvm.org/PR21227

llvm-svn: 224459

polly/include/polly/Dependences.h
polly/lib/Analysis/Dependences.cpp
polly/lib/Transform/DeadCodeElimination.cpp

index d0fb96d..df03d2c 100644 (file)
@@ -121,12 +121,17 @@ public:
     return ReductionDependences;
   }
 
+  /// @brief Recompute dependences from schedule and memory accesses.
+  void recomputeDependences();
+
   bool runOnScop(Scop &S);
   void printScop(raw_ostream &OS) const;
   virtual void releaseMemory();
   virtual void getAnalysisUsage(AnalysisUsage &AU) const;
 
 private:
+  Scop *S;
+
   /// @brief The different kinds of dependences we calculate.
   isl_union_map *RAW;
   isl_union_map *WAR;
index c9cc778..d4d092a 100644 (file)
@@ -432,10 +432,14 @@ void Dependences::calculateDependences(Scop &S) {
   DEBUG(printScop(dbgs()));
 }
 
-bool Dependences::runOnScop(Scop &S) {
+void Dependences::recomputeDependences() {
   releaseMemory();
-  calculateDependences(S);
+  calculateDependences(*S);
+}
 
+bool Dependences::runOnScop(Scop &ScopVar) {
+  S = &ScopVar;
+  recomputeDependences();
   return false;
 }
 
index c5cd579..497999f 100644 (file)
@@ -151,7 +151,13 @@ bool DeadCodeElim::eliminateDeadCode(Scop &S, int PreciseSteps) {
   isl_union_map_free(Dep);
   isl_union_set_free(OriginalDomain);
 
-  return S.restrictDomains(isl_union_set_coalesce(Live));
+  bool Changed = S.restrictDomains(isl_union_set_coalesce(Live));
+
+  // FIXME: We can probably avoid the recomputation of all dependences by
+  // updating them explicitly.
+  if (Changed)
+    D->recomputeDependences();
+  return Changed;
 }
 
 bool DeadCodeElim::runOnScop(Scop &S) {