[llvm] r330577 - [LoopUnroll] Fix potentially incorrect SCEV invalidation in UnrollRuntime

Max Kazantsev via llvm-commits llvm-commits at lists.llvm.org
Mon Apr 23 03:39:38 PDT 2018


Author: mkazantsev
Date: Mon Apr 23 03:39:38 2018
New Revision: 330577

URL: http://llvm.org/viewvc/llvm-project?rev=330577&view=rev
Log:
[LoopUnroll] Fix potentially incorrect SCEV invalidation in UnrollRuntime

Current runtime unrolling invalidates parent loop saying that it might have changed
after the inner loop has changed, but it doesn't bother to do the same to its parents.
With patch rL329047, SCEV becomes much smarter about calculation of exit counts for
outer loops. We might need to invalidate not only the immediate parent, but also
any of its parents as well.

There is no clear evidence that there is some miscompile happening because of this
(at least I don't have such test), but the common sense says that the current code
is wrong.

Differential Revision: https://reviews.llvm.org/D45940
Reviewed By: chandlerc

Modified:
    llvm/trunk/lib/Transforms/Utils/LoopUnrollRuntime.cpp

Modified: llvm/trunk/lib/Transforms/Utils/LoopUnrollRuntime.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Utils/LoopUnrollRuntime.cpp?rev=330577&r1=330576&r2=330577&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Utils/LoopUnrollRuntime.cpp (original)
+++ llvm/trunk/lib/Transforms/Utils/LoopUnrollRuntime.cpp Mon Apr 23 03:39:38 2018
@@ -878,10 +878,9 @@ bool llvm::UnrollRuntimeLoopRemainder(Lo
                   NewPreHeader, VMap, DT, LI, PreserveLCSSA);
   }
 
-  // If this loop is nested, then the loop unroller changes the code in the
-  // parent loop, so the Scalar Evolution pass needs to be run again.
-  if (Loop *ParentLoop = L->getParentLoop())
-    SE->forgetLoop(ParentLoop);
+  // If this loop is nested, then the loop unroller changes the code in the any
+  // of its parent loops, so the Scalar Evolution pass needs to be run again.
+  SE->forgetTopmostLoop(L);
 
   // Canonicalize to LoopSimplifyForm both original and remainder loops. We
   // cannot rely on the LoopUnrollPass to do this because it only does




More information about the llvm-commits mailing list