[llvm] [LV] Initial support for stores in early exit loops (PR #137774)

Graham Hunter via llvm-commits llvm-commits at lists.llvm.org
Thu Nov 6 02:49:27 PST 2025


huntergr-arm wrote:

Hi @annamthomas,

I've been working on landing pieces of this work as individual PRs. As you note, the legality checks have been committed, as has #152530 to identify the vplan recipes contributing to an uncountable exit.

The latter was split from #148626, which is now my focus and is currently awaiting review. That patch has the core transform to handle uncountable exits that would occur in the _next_ vector iteration in the scalar loop instead, which was the plan I mentioned in the RFC.

A rough idea of the resulting code would be:

```
;; after SCEV/min.iter checks
vector.ph:
  ;; Perform load for uncountable condition for _first_ vector iteration
  ;; Compare and reduce result of load, and either branch to the scalar
  ;; preheader if there would be an exit, or vector.ph.split otherwise
vector.ph.split:
  br vector.body
vector.body:
  iv = phi....
  ;; Move iv increment operation early enough for the load
  iv.next = add iv, step
  ;; Load uncountable exit data for the _next_ vector iteration
  addr = gep uncountable_base, iv.next
  uc.load = load addr
  ;; compare and reduce result of load, combine with countable
  ;; exit condition
  ;; branch back to vector body or middle block
middle.block:
  ;; Determine whether we exited due to reaching the loop upper bound
  ;; if not, branch to the scalar.ph to handle either type of exit
```

This doesn't currently support using the uncountable exit condition load value for anything beyond the exit; that requires a small follow-up to introduce a phi if there are additional uses.

After that lands, I can rebase this patch on top of it. There shouldn't be much left to do at that point for the minimum supported case, and extending the set of loops handled can be dealt with in additional PRs.

Hopefully that explains enough? Please let me know if something's not clear.

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


More information about the llvm-commits mailing list