[PATCH] D143409: [SCEV][IndVarSimplify] Add nsw/nuw falgs to binary ops before visiting IVUsers

Aleksandr Popov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Feb 14 04:06:41 PST 2023


aleksandr.popov added a comment.

I'll try to explain to root probrem in the 'unknown.start' test case.

- Currently we process IV's users in this order:

  %signed.cmp = icmp slt i32 %iv, %len
  %unsigned.cmp = icmp ult i32 %iv, %len
  %iv.next = add i32 %iv, 1

When we try to make %unsigned.cmp invariant, IV's SCEV doesn't have nsw/nuw flags:

  {%start,+,1}<%loop>

Therefore AddRec's MonotonicType, computed in the ScalarEvolution::getLoopInvariantPredicate, is nullopt and we can't make %unsigned.cmp invariant.

- But if we visit bin op firstly and annotate it with nsw/nuw flags, they will be propagated to IV's SCEV:

  {%start,+,1}<nuw><nsw><%loop>

And it allows us to make %unsigned.cmp invariant, since MonotonicType has value


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D143409/new/

https://reviews.llvm.org/D143409



More information about the llvm-commits mailing list