[PATCH] D110060: [LoopBoundSplit] Handle the case in which exiting block is loop header

JinGu Kang via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 21 03:48:05 PDT 2021


jaykang10 added a comment.

In D110060#3011621 <https://reviews.llvm.org/D110060#3011621>, @mkazantsev wrote:

> I completely don't understand neither what happened nor the fix. Could you please give more details on how and why this bug is happening?

Sorry for poor explanation... Let me try to explain something more.

We need to update the IV's start value in post loop. In the example from https://bugs.llvm.org/show_bug.cgi?id=51866, the IV's start value in post loop is not updated correctly as below.
`%i.0.split = phi i16 [ %inc.split, %for.inc.split ], [ 0, %for.cond.split.preheader ]`.
As @uabelho mentioned, it should be `[ 5, %for.cond.split.preheader ]`.

The code has expected the `ExitingCond.AddRecValue` is `add` instruction like `%inc = add nuw nsw i16 %i.0, 1`. The `ExitingCond.AddRecValue` is calculated from exiting block's condition. For example,

  for.inc:
    %inc = add nuw nsw i64 %iv, 1
    %cond = icmp sgt i64 %inc, %n
    br i1 %cond, label %exit, label %loop

In above example, the latch is exiting block and the `ExitingCond.AddRecValue` is `%inc = add nuw nsw i64 %iv, 1`.

  for.cond:                                         ; preds = %for.inc, %entry
    %i.0 = phi i16 [ 0, %entry ], [ %inc, %for.inc ]
    %exitcond.not = icmp eq i16 %i.0, 10
    br i1 %exitcond.not, label %for.end, label %for.body

In above example, the header is exiting block and the `ExitingCond.AddRecValue` is `%i.0 = phi i16 [ 0, %entry ], [ %inc, %for.inc ]`. Previously, the code missed this case.

This patch detects this case and update the IV's start value in post loop correctly. If you feel something wrong, please let me know.


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

https://reviews.llvm.org/D110060



More information about the llvm-commits mailing list