[PATCH] D103991: [SCEV] Extend mustprogress reasoning to ne exit tests
    Max Kazantsev via Phabricator via llvm-commits 
    llvm-commits at lists.llvm.org
       
    Wed Jun  9 21:32:27 PDT 2021
    
    
  
mkazantsev requested changes to this revision.
mkazantsev added a comment.
This revision now requires changes to proceed.
Please add tests for this this exit doesn't dominate the latch.
================
Comment at: llvm/lib/Analysis/ScalarEvolution.cpp:7918
+  //   caused this exit to be taken previously.  Thus, this exit is
+  //   dynamically dead.
+  // * If this is the sole exit, then a dead exit implies the loop
----------------
It is only true if this condition dominates the latch. If not, it might exit at some point during the iteration space, but it was guarded by a volatile condition that prevented it. If my understanding is correct, please specify this requirement explicitly in function's comment.
Maybe (I'm not sure) this still holds for non-dominating exits if it is the only exit from the loop.
================
Comment at: llvm/lib/Analysis/ScalarEvolution.cpp:7931
+
+  auto *Stride = IV->getStepRecurrence(*this);
+  auto *StrideC = dyn_cast<SCEVConstant>(Stride);
----------------
Please add early bail if IV is not affine. This will save compile time for complex addrecs.
================
Comment at: llvm/lib/Analysis/ScalarEvolution.cpp:7933
+  auto *StrideC = dyn_cast<SCEVConstant>(Stride);
+  if (!StrideC || !StrideC->getAPInt().isPowerOf2())
+    return SCEV::FlagAnyWrap;
----------------
How about negative powers of 2? I think all your reasoning validly applies for them too.
================
Comment at: llvm/lib/Analysis/ScalarEvolution.cpp:7942
+
+  if (ICmpInst::isEquality(Pred))
+    return SCEV::FlagNW;
----------------
This should go before anything else to save compile time.
================
Comment at: llvm/test/Analysis/ScalarEvolution/ne-overflow.ll:10
+
+; CHECK: Determining loop execution counts for: @test
+; CHECK: Loop %for.body: backedge-taken count is ((-2 + %N) /u 2)
----------------
Please use ./utils/update_analyze_test_checks.py. It works well with SCEV.
Repository:
  rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D103991/new/
https://reviews.llvm.org/D103991
    
    
More information about the llvm-commits
mailing list