[PATCH] D115238: [LoopInterchange] Remove a limitation in legality

Congzhe Cao via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Dec 29 14:54:12 PST 2021


congzhe added a comment.

In D115238#3208653 <https://reviews.llvm.org/D115238#3208653>, @bmahjour wrote:

>> Right now we split at the branch instruction of for2, and we duplicate %j.next = add nuw nsw i64 %j, 1 and %exitcond = icmp eq i64 %j, 99 into for2.split which becomes the new outer latch. Instructions in the original inner latch stay where they are. Hence the limitation can be removed.
>
> Do we check to make sure duplicating instructions is safe (eg we are not duplicating side effects, etc)?

Thanks for the comment!

Yes we did. The check is at line 1314:

  assert(!NewI->mayHaveSideEffects() &&
                 "Moving instructions with side-effects may change behavior of "
                 "the loop nest!");

Relevant comment: https://reviews.llvm.org/D67367?vs=219418&id=219529#1664596.

It is not very easy to come up with a test case that involves duplicating unsafe instructions though, because the instructions we duplicate are involved in the loop exit condition or the induction variable increment. If an unsafe instruction was involved in loop exit condition or the induction variable increment, SCEV would say it cannot compute the backedge count and we would bail out at the first place, not even reach this piece of code.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D115238



More information about the llvm-commits mailing list