[PATCH] D46045: [LoopUnswitch] Fix potentially incorrect SCEV invalidation in unswitching

Max Kazantsev via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Apr 25 00:26:18 PDT 2018


mkazantsev created this revision.
mkazantsev added reviewers: chandlerc, sanjoy, reames.
Herald added a subscriber: javed.absar.

Loop unswitching makes substantial changes to a loop that can also affect cached
SCEV info in its outer loops as well, but it only cares to invalidate SCEV cache for the
innermost loop. This patch makes it do it to the outer loops, too.

There is no clear evidence that this produces real miscompile, but having inaccurate
SCEV cache may lead us to them.


https://reviews.llvm.org/D46045

Files:
  lib/Transforms/Scalar/LoopUnswitch.cpp


Index: lib/Transforms/Scalar/LoopUnswitch.cpp
===================================================================
--- lib/Transforms/Scalar/LoopUnswitch.cpp
+++ lib/Transforms/Scalar/LoopUnswitch.cpp
@@ -1201,8 +1201,10 @@
         << " blocks] in Function " << F->getName()
         << " when '" << *Val << "' == " << *LIC << "\n");
 
+  // We are going to make modifications to loop's block which can also affect
+  // cached invariants for its parent loops.
   if (auto *SEWP = getAnalysisIfAvailable<ScalarEvolutionWrapperPass>())
-    SEWP->getSE().forgetLoop(L);
+    SEWP->getSE().forgetTopmostLoop(L);
 
   LoopBlocks.clear();
   NewBlocks.clear();


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D46045.143866.patch
Type: text/x-patch
Size: 657 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180425/12bc5c68/attachment.bin>


More information about the llvm-commits mailing list