[PATCH] D111836: [indvars] Use fact loop must exit to canonicalize to unsigned conditions

Philip Reames via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Oct 14 13:53:15 PDT 2021


reames created this revision.
reames added reviewers: nikic, mkazantsev, fhahn, efriedma.
Herald added subscribers: javed.absar, bollu, hiraditya, mcrosier.
reames requested review of this revision.
Herald added a project: LLVM.

The logic in this patch is that if we find a comparison which would be unsigned except for when the loop is infinite, and we can prove that an infinite loop must be ill defined, we can still make the predicate unsigned.

The eventual goal (combined with a follow on patch) is to use the fact the loop exits to remove the zext (see tests) entirely.

A couple of points worth noting:

- We loose the ability to prove the loop unreachable by committing to the must exit interpretation.  If instead, we later proved that rhs was definitely outside the range required for finiteness, we could have killed the loop entirely.  (We don't currently implement this transform, but could in theory, do so.)
- simplifyAndExtend has a very limited list of users it walks.  In particular, in the examples is stops at the zext and never visits the icmp.   (Because we can't fold the zext to an addrec yet in SCEV.)  Being willing to visit when we haven't simplified regresses multiple tests (seemingly because of less optimal results when computing trip counts).
- D109457 <https://reviews.llvm.org/D109457> is geared at the same basic problem, but handles a non-fully overlapping set of cases.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D111836

Files:
  llvm/include/llvm/Analysis/ScalarEvolution.h
  llvm/lib/Transforms/Scalar/IndVarSimplify.cpp
  llvm/test/Transforms/IndVarSimplify/finite-exit-comparisons.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D111836.379831.patch
Type: text/x-patch
Size: 8982 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20211014/3dbf8fd7/attachment.bin>


More information about the llvm-commits mailing list