[polly] r279047 - [BlockGenerator] Invalidate SCEV values for instructions in scop

Tobias Grosser via llvm-commits llvm-commits at lists.llvm.org
Thu Aug 18 03:45:57 PDT 2016


Author: grosser
Date: Thu Aug 18 05:45:57 2016
New Revision: 279047

URL: http://llvm.org/viewvc/llvm-project?rev=279047&view=rev
Log:
[BlockGenerator] Invalidate SCEV values for instructions in scop

We already invalidated a couple of critical values earlier on, but we now
invalidate all instructions contained in a scop after the scop has been code
generated. This is necessary as later scops may otherwise obtain SCEV
expressions that reference values in the earlier scop that before dominated
the later scop, but which had been moved into the conditional branch and
consequently do not dominate the later scop any more. If these very values are
then used during code generation of the later scop, we generate used that are
dominated by the values they use.

This fixes: http://llvm.org/PR28984

Modified:
    polly/trunk/include/polly/CodeGen/BlockGenerators.h
    polly/trunk/lib/CodeGen/BlockGenerators.cpp
    polly/trunk/test/Isl/CodeGen/hoisted_load_escapes_through_phi.ll

Modified: polly/trunk/include/polly/CodeGen/BlockGenerators.h
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/include/polly/CodeGen/BlockGenerators.h?rev=279047&r1=279046&r2=279047&view=diff
==============================================================================
--- polly/trunk/include/polly/CodeGen/BlockGenerators.h (original)
+++ polly/trunk/include/polly/CodeGen/BlockGenerators.h Thu Aug 18 05:45:57 2016
@@ -546,6 +546,18 @@ protected:
   /// @param BB The basic block code for which code has been generated.
   /// @param BBMap A local map from old to new instructions.
   void removeDeadInstructions(BasicBlock *BB, ValueMapT &BBMap);
+
+  /// @brief Invalidate the scalar evolution expressions for a scop.
+  ///
+  /// This function invalidates the scalar evolution results for all
+  /// instructions that are part of a given scop. This is necessary to ensure
+  /// that later scops do not obtain scalar evolution expressions that reference
+  /// values that earlier dominated the later scop, but have been moved in the
+  /// conditional part of an earlier scop and consequently do not any more
+  /// dominate the later scop.
+  ///
+  /// @param S The scop to invalidate.
+  void invalidateScalarEvolution(Scop &S);
 };
 
 /// @brief Generate a new vector basic block for a polyhedral statement.

Modified: polly/trunk/lib/CodeGen/BlockGenerators.cpp
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/lib/CodeGen/BlockGenerators.cpp?rev=279047&r1=279046&r2=279047&view=diff
==============================================================================
--- polly/trunk/lib/CodeGen/BlockGenerators.cpp (original)
+++ polly/trunk/lib/CodeGen/BlockGenerators.cpp Thu Aug 18 05:45:57 2016
@@ -646,11 +646,25 @@ void BlockGenerator::createExitPHINodeMe
   }
 }
 
+void BlockGenerator::invalidateScalarEvolution(Scop &S) {
+  for (auto &Stmt : S)
+    if (Stmt.isBlockStmt())
+      for (auto &Inst : *Stmt.getBasicBlock())
+        SE.forgetValue(&Inst);
+    else if (Stmt.isRegionStmt())
+      for (auto *BB : Stmt.getRegion()->blocks())
+        for (auto &Inst : *BB)
+          SE.forgetValue(&Inst);
+    else
+      llvm_unreachable("Unexpected statement type found");
+}
+
 void BlockGenerator::finalizeSCoP(Scop &S) {
   findOutsideUsers(S);
   createScalarInitialization(S);
   createExitPHINodeMerges(S);
   createScalarFinalization(S);
+  invalidateScalarEvolution(S);
 }
 
 VectorBlockGenerator::VectorBlockGenerator(BlockGenerator &BlockGen,

Modified: polly/trunk/test/Isl/CodeGen/hoisted_load_escapes_through_phi.ll
URL: http://llvm.org/viewvc/llvm-project/polly/trunk/test/Isl/CodeGen/hoisted_load_escapes_through_phi.ll?rev=279047&r1=279046&r2=279047&view=diff
==============================================================================
--- polly/trunk/test/Isl/CodeGen/hoisted_load_escapes_through_phi.ll (original)
+++ polly/trunk/test/Isl/CodeGen/hoisted_load_escapes_through_phi.ll Thu Aug 18 05:45:57 2016
@@ -1,5 +1,7 @@
 ; RUN: opt %loadPolly -S -polly-codegen \
-; RUN: -polly-invariant-load-hoisting < %s | FileCheck %s
+; RUN: -polly-invariant-load-hoisting=false < %s | FileCheck %s
+; RUN: opt %loadPolly -S -polly-codegen \
+; RUN: -polly-invariant-load-hoisting=true < %s | FileCheck %s
 ;
 ; Check that we generate valid code even if the load of cont_STACKPOINTER is
 ; hoisted in one SCoP and used (through the phi node %tmp2).




More information about the llvm-commits mailing list