[all-commits] [llvm/llvm-project] e58719: [SCEV] Prove condition invariance via context, try 2

Max Kazantsev via All-commits all-commits at lists.llvm.org
Mon Aug 22 00:32:07 PDT 2022

  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: e587199a505bf517935026e878fc811a38532e4a
  Author: Max Kazantsev <mkazantsev at azul.com>
  Date:   2022-08-22 (Mon, 22 Aug 2022)

  Changed paths:
    M llvm/include/llvm/Analysis/ScalarEvolution.h
    M llvm/lib/Analysis/ScalarEvolution.cpp
    M llvm/lib/Transforms/Utils/SimplifyIndVar.cpp
    M llvm/test/Transforms/IndVarSimplify/cycled_phis.ll
    M llvm/test/Transforms/IndVarSimplify/outer_phi.ll

  Log Message:
  [SCEV] Prove condition invariance via context, try 2

Initial implementation had too weak requirements to positive/negative
range crossings. Not crossing zero with nuw is not enough for two reasons:

- If ArLHS has negative step, it may turn from positive to negative
  without crossing 0 boundary from left to right (and crossing right to
  left doesn't count for unsigned);
- If ArLHS crosses SINT_MAX boundary, it still turns from positive to

In fact we require that ArLHS always stays non-negative or negative,
which an be enforced by the following set of preconditions:

- both nuw and nsw;
- positive step (looks liftable);

Because of positive step, boundary crossing is only possible from left
part to the right part. And because of no-wrap flags, it is guaranteed
to never happen.

More information about the All-commits mailing list