[llvm] [LSR][term-fold] Ensure the simple recurrence is reachable from the current loop (PR #83085)
Philip Reames via llvm-commits
llvm-commits at lists.llvm.org
Mon Mar 4 13:22:25 PST 2024
================
@@ -6808,6 +6808,12 @@ canFoldTermCondOfLoop(Loop *L, ScalarEvolution &SE, DominatorTree &DT,
if (!matchSimpleRecurrence(LHS, ToFold, ToFoldStart, ToFoldStep))
return std::nullopt;
+ // If ToFold does not have an incoming value from LoopLatch then the simple
+ // recurrence is from a prior loop unreachable from the loop we're currently
+ // considering.
+ if (ToFold->getBasicBlockIndex(LoopLatch) == -1)
----------------
preames wrote:
A more idiomatic check here would be: L->getHeader() != ToFold->getParent(). This directly checks the property you're comment indicates.
https://github.com/llvm/llvm-project/pull/83085
More information about the llvm-commits
mailing list