[PATCH] D145894: [IndVars] Option verify-indvars is broken (and always has been), delete it

Max Kazantsev via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Mar 12 21:49:02 PDT 2023


mkazantsev created this revision.
mkazantsev added reviewers: nikic, fhahn, reames, lebedev.ri.
Herald added subscribers: StephenFan, pengfei, javed.absar, hiraditya, kristof.beyls.
Herald added a project: All.
mkazantsev requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

This option is switched off by default, and it seems that it has never worked correctly.
What it basically does is: it remembers current BECount SCEV, and after all transforms
tries to validate some facts for it. However, between these two points this SCEV may
become invalid (e.g. because some SCEVUnknown it references may be deleted as dead
code). So basically it may work with broken pointers.

Besides, its implementation does strange things (e.g. forgetLoop) which are invasive and
may affect behavior in other parts of the system (specifically verification), concealing some
other problems. Another issue is that it may use SCEVCouldNotCompute object without
checking this.

The option is not used in any unit tests, and if switched on by default, the following tests
fail:

  ********************
  Failed Tests (14):
    LLVM :: Transforms/IndVarSimplify/2005-06-15-InstMoveCrash.ll
    LLVM :: Transforms/IndVarSimplify/2007-06-06-DeleteDanglesPtr.ll
    LLVM :: Transforms/IndVarSimplify/2008-10-03-CouldNotCompute.ll
    LLVM :: Transforms/IndVarSimplify/2009-05-24-useafterfree.ll
    LLVM :: Transforms/IndVarSimplify/2011-10-27-lftrnull.ll
    LLVM :: Transforms/IndVarSimplify/ARM/code-size.ll
    LLVM :: Transforms/IndVarSimplify/X86/deterministic-scev-verify.ll
    LLVM :: Transforms/IndVarSimplify/X86/pr57187.ll
    LLVM :: Transforms/IndVarSimplify/X86/verify-scev.ll
    LLVM :: Transforms/IndVarSimplify/bbi-63564.ll
    LLVM :: Transforms/IndVarSimplify/invalidate-modified-lcssa-phi.ll
    LLVM :: Transforms/IndVarSimplify/loop-predication.ll
    LLVM :: Transforms/IndVarSimplify/post-inc-range.ll
    LLVM :: Transforms/IndVarSimplify/turn-to-invariant.ll
  
  ********************
  Unexpectedly Passed Tests (1):
    LLVM :: Transforms/IndVarSimplify/pr55689.ll

I think it all gives enough justification for its removal.


https://reviews.llvm.org/D145894

Files:
  llvm/lib/Transforms/Scalar/IndVarSimplify.cpp


Index: llvm/lib/Transforms/Scalar/IndVarSimplify.cpp
===================================================================
--- llvm/lib/Transforms/Scalar/IndVarSimplify.cpp
+++ llvm/lib/Transforms/Scalar/IndVarSimplify.cpp
@@ -93,15 +93,6 @@
 STATISTIC(NumElimExt     , "Number of IV sign/zero extends eliminated");
 STATISTIC(NumElimIV      , "Number of congruent IVs eliminated");
 
-// Trip count verification can be enabled by default under NDEBUG if we
-// implement a strong expression equivalence checker in SCEV. Until then, we
-// use the verify-indvars flag, which may assert in some cases.
-static cl::opt<bool> VerifyIndvars(
-    "verify-indvars", cl::Hidden,
-    cl::desc("Verify the ScalarEvolution result after running indvars. Has no "
-             "effect in release builds. (Note: this adds additional SCEV "
-             "queries potentially changing the analysis result)"));
-
 static cl::opt<ReplaceExitVal> ReplaceExitValue(
     "replexitval", cl::Hidden, cl::init(OnlyCheapRepl),
     cl::desc("Choose the strategy to replace exit value in IndVarSimplify"),
@@ -2023,16 +2014,6 @@
   if (!L->isLoopSimplifyForm())
     return false;
 
-#ifndef NDEBUG
-  // Used below for a consistency check only
-  // Note: Since the result returned by ScalarEvolution may depend on the order
-  // in which previous results are added to its cache, the call to
-  // getBackedgeTakenCount() may change following SCEV queries.
-  const SCEV *BackedgeTakenCount;
-  if (VerifyIndvars)
-    BackedgeTakenCount = SE->getBackedgeTakenCount(L);
-#endif
-
   bool Changed = false;
   // If there are any floating-point recurrences, attempt to
   // transform them to use integer recurrences.
@@ -2182,27 +2163,6 @@
   assert(L->isRecursivelyLCSSAForm(*DT, *LI) &&
          "Indvars did not preserve LCSSA!");
 
-  // Verify that LFTR, and any other change have not interfered with SCEV's
-  // ability to compute trip count.  We may have *changed* the exit count, but
-  // only by reducing it.
-#ifndef NDEBUG
-  if (VerifyIndvars && !isa<SCEVCouldNotCompute>(BackedgeTakenCount)) {
-    SE->forgetLoop(L);
-    const SCEV *NewBECount = SE->getBackedgeTakenCount(L);
-    if (SE->getTypeSizeInBits(BackedgeTakenCount->getType()) <
-        SE->getTypeSizeInBits(NewBECount->getType()))
-      NewBECount = SE->getTruncateOrNoop(NewBECount,
-                                         BackedgeTakenCount->getType());
-    else
-      BackedgeTakenCount = SE->getTruncateOrNoop(BackedgeTakenCount,
-                                                 NewBECount->getType());
-    assert(!SE->isKnownPredicate(ICmpInst::ICMP_ULT, BackedgeTakenCount,
-                                 NewBECount) && "indvars must preserve SCEV");
-  }
-  if (VerifyMemorySSA && MSSAU)
-    MSSAU->getMemorySSA()->verifyMemorySSA();
-#endif
-
   return Changed;
 }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D145894.504505.patch
Type: text/x-patch
Size: 2847 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230313/3a3b08ca/attachment.bin>


More information about the llvm-commits mailing list