[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
Mon Oct 4 05:27:44 PDT 2021


jaykang10 added inline comments.


================
Comment at: llvm/lib/Transforms/Scalar/LoopBoundSplit.cpp:390
+    if (ExitingCond.NonPHIAddRecValue ==
+        PN.getIncomingValueForBlock(L.getLoopLatch()))
+      ExitingCondLCSSAPhi = LCSSAPhi;
----------------
jaykang10 wrote:
> mkazantsev wrote:
> > What happens if there is more than one phi that will fit?
> um... you are right. It will pick up just last phi node which could be wrong... Let me update the code.
I have added code to check whether the phi node is `SCEVAddRecExpr` or not.  After that, we can see below expected output.
```
; CHECK-NEXT:    [[EXITCOND_NOT_SPLIT:%.*]] = icmp eq i16 [[I_0_SPLIT]], 10
```
Previously, it was `I_1_SPLIT` intead of `I_0_SPLIT`.

The PHIs can have same incoming value from backedge but only one can be `SCEVAddRecExpr` as below.
```
for.cond:                                         ; preds = %for.inc, %entry
  %i.0 = phi i16 [ 0, %entry ], [ %inc.0, %for.inc ]
  %i.1 = phi i16 [ 10, %entry ], [ %inc.0, %for.inc ]
...
for.inc:                                          ; preds = %if.else, %if.then
  %inc.0 = add nuw nsw i16 %i.0, 1
...
```
@mkazantsev if you feel something wrong, please let me know. If it is correct, let me push this patch.


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

https://reviews.llvm.org/D110060



More information about the llvm-commits mailing list