[llvm] [SCEV] Require that addrec operands dominate the loop (PR #67030)

Danila Malyutin via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 17 10:31:38 PDT 2023


================
@@ -3670,9 +3670,12 @@ ScalarEvolution::getAddRecExpr(SmallVectorImpl<const SCEV *> &Operands,
            "SCEVAddRecExpr operand types don't match!");
     assert(!Operands[i]->getType()->isPointerTy() && "Step must be integer");
   }
-  for (unsigned i = 0, e = Operands.size(); i != e; ++i)
+  for (unsigned i = 0, e = Operands.size(); i != e; ++i) {
     assert(isLoopInvariant(Operands[i], L) &&
            "SCEVAddRecExpr operand is not loop-invariant!");
+    assert(properlyDominates(Operands[i], L->getHeader()) &&
----------------
danilaml wrote:

Hm, after investigating more, it looks like it might so happen that some loop will get it's Backage taken count computed using cached SCEV value from another loop (which is properly dominating at the time), but then loop unswitch could unswitch this (or some other related) loop making that so that value used in a cached SCEV is no longer dominating the loop which leads to assert. Was unable to reduce the test case, since it proved to be highly dependent on the order BBs are stored inside the Loop structure among other things. Don't think that this PR is buggy, it probably just exposed a bug/potential issue, similar to the one described in https://github.com/llvm/llvm-project/issues/63970 .

https://github.com/llvm/llvm-project/pull/67030


More information about the llvm-commits mailing list