[PATCH] D132443: [LSR] Fold terminal condition to other IV when possible

Yueh-Ting (eop) Chen via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Aug 24 02:32:24 PDT 2022


eopXD added inline comments.


================
Comment at: llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp:6608
+
+    while (V->getNumUses() == 1)
+      V = *V->user_begin();
----------------
mcberg2021 wrote:
> What happens if there is more than one use here?  Why not use hasOneUse() and return if false?
The main intention here is that the primary IV of the loop, may be transformed by multiple LLVM-IR instructions, but is only used to determine the terminal condition. In this case the use-def chain will be a long chain until the final value that is for 

1. used by the terminal condition
2. goes into the phi-node in the loop header

So loop here is to travel through the long chain until meeting value that is used exactly twice.

When the scenario 1 and 2 is satisfied, we can say that this IV (and its corresponding PHINode) is the one we are looking to fold. We will need to traverse through the chain to verify the final usage is for 1 and 2.

Here is a illustration.
{F24250756}


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D132443



More information about the llvm-commits mailing list