<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - Stale SCEVs still used after https://reviews.llvm.org/D87494"
   href="https://bugs.llvm.org/show_bug.cgi?id=48166">48166</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Stale SCEVs still used after https://reviews.llvm.org/D87494
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>libraries
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>PC
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>All
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>Scalar Optimizations
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>chang-sun.lin.jr@intel.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>llvm-bugs@lists.llvm.org
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Created <span class=""><a href="attachment.cgi?id=24159" name="attach_24159" title="test case">attachment 24159</a> <a href="attachment.cgi?id=24159&action=edit" title="test case">[details]</a></span>
test case

Hi! We're working on some code where we are calling getType() in
ScalarEvolution::computeConstantDifference. After
<a href="https://reviews.llvm.org/D87494">https://reviews.llvm.org/D87494</a>, this function is getting dead SCEVs that have
been deleted by phi cleanup in LoopStrengthReduce. We have fixed it locally by
guarding the getType() call, but probably the dead SCEVs should not be passed
in the first place.

I have an IR file that will reproduce the problem, if you call getType
somewhere, for example:

diff --git a/llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp
b/llvm/lib/Transf
index 2713fa6..6eed23a 100644
--- a/llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp
+++ b/llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp
@@ -5849,6 +5849,7 @@ static bool ReduceLoopStrength(Loop *L, IVUsers &IU,
Scala
         if (!SE.isSCEVable(Phi.getType()))
           continue;
         auto PhiSCEV = SE.getSCEV(&Phi);
+        auto *thing = DbgValueSCEV->getType(); // ADDED
         if (Optional<APInt> Offset =
                 SE.computeConstantDifference(DbgValueSCEV, PhiSCEV)) {
           auto &Ctx = DbgValue->getContext();

opt -S -loop-reduce lsr-null-scev.ll</pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>