[PATCH] D91711: SCEV add function to see if SCEVUnknown is null

Markus Lavin via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Nov 18 07:27:52 PST 2020


markus created this revision.
markus added a project: LLVM.
Herald added subscribers: llvm-commits, javed.absar, hiraditya.
markus requested review of this revision.

I tried raising the question if a SCEV expression should be analyzable even if part of the underlaying IR has been removed on llvm-dev without much response.

http://lists.llvm.org/pipermail/llvm-dev/2020-November/146636.html

This review is to take it one step further to see if that gives some reaction.

So my, possibly controversial, suggestion is that yes SCEV expressions should be analyzable even though part of the IR that was analyzed to build it has later been removed. Obviously the IR that can be removed is only the part that SCEV has already successfully "analyzed through" so if any SCEVUnknown points at IR that has been removed (i.e. the value pointer has been nulled) then the SCEV expression can no longer be analyzed.

This review adds a function `ScalarEvolution::hasNulledUnknown` to determine if a SCEV expression can still be analyzed or not.

For background see the llvm-dev post above.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D91711

Files:
  llvm/include/llvm/Analysis/ScalarEvolution.h
  llvm/lib/Analysis/ScalarEvolution.cpp
  llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp


Index: llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp
===================================================================
--- llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp
+++ llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp
@@ -5843,6 +5843,8 @@
       auto DbgDIExpr = std::get<DIExpression *>(D);
       if (!isa<UndefValue>(DbgValue->getVariableLocation()))
         continue;
+      if (SE.hasNulledUnknown(DbgValueSCEV))
+        continue;
       for (PHINode &Phi : L->getHeader()->phis()) {
         if (DbgValueType != Phi.getType())
           continue;
Index: llvm/lib/Analysis/ScalarEvolution.cpp
===================================================================
--- llvm/lib/Analysis/ScalarEvolution.cpp
+++ llvm/lib/Analysis/ScalarEvolution.cpp
@@ -12461,6 +12461,13 @@
   return SCEVExprContains(S, [&](const SCEV *Expr) { return Expr == Op; });
 }
 
+bool ScalarEvolution::hasNulledUnknown(const SCEV *S) const {
+  return SCEVExprContains(S, [&](const SCEV *Expr) {
+    auto U = dyn_cast<SCEVUnknown>(Expr);
+    return U && !U->getValPtr();
+  });
+}
+
 bool ScalarEvolution::ExitLimit::hasOperand(const SCEV *S) const {
   auto IsS = [&](const SCEV *X) { return S == X; };
   auto ContainsS = [&](const SCEV *X) {
Index: llvm/include/llvm/Analysis/ScalarEvolution.h
===================================================================
--- llvm/include/llvm/Analysis/ScalarEvolution.h
+++ llvm/include/llvm/Analysis/ScalarEvolution.h
@@ -1032,6 +1032,9 @@
   /// Test whether the given SCEV has Op as a direct or indirect operand.
   bool hasOperand(const SCEV *S, const SCEV *Op) const;
 
+  /// Test whether the given SCEV has a SCEVUnknown that has been nulled.
+  bool hasNulledUnknown(const SCEV *S) const;
+
   /// Return the size of an element read or written by Inst.
   const SCEV *getElementSize(Instruction *Inst);
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D91711.306101.patch
Type: text/x-patch
Size: 1856 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20201118/bb8d14f0/attachment.bin>


More information about the llvm-commits mailing list