[all-commits] [llvm/llvm-project] 412eb0: [indvars] Use fact loop must exit to canonicalize ...

Philip Reames via All-commits all-commits at lists.llvm.org
Fri Oct 22 10:32:10 PDT 2021


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 412eb07edd4e83afeb1e727e91213e2cbd771f29
      https://github.com/llvm/llvm-project/commit/412eb07edd4e83afeb1e727e91213e2cbd771f29
  Author: Philip Reames <listmail at philipreames.com>
  Date:   2021-10-22 (Fri, 22 Oct 2021)

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

  Log Message:
  -----------
  [indvars] Use fact loop must exit to canonicalize to unsigned conditions

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).  D112170 explores fixing that, but - at least so far - appears to be too expensive compile time wise.

Differential Revision: https://reviews.llvm.org/D111836




More information about the All-commits mailing list