[llvm] [ConstraintElim] Generalize IV logic to chain of exiting blocks. (PR #108031)

Yingwei Zheng via llvm-commits llvm-commits at lists.llvm.org
Tue Sep 10 08:04:38 PDT 2024


================
@@ -1048,6 +1051,28 @@ void State::addInfoForInductions(BasicBlock &BB) {
   }
 }
 
+void State::addInfoForInductions(BasicBlock &BB) {
+  auto *L = LI.getLoopFor(&BB);
+  if (!L)
+    return;
+  if (L->getHeader() != &BB)
+    return;
+
+  BasicBlock *Curr = &BB;
+  while (L->isLoopExiting(Curr)) {
+    // Don't try to add condition from latch to loop header.
+    if (L->isLoopLatch(Curr))
+      break;
+    auto *Term = dyn_cast<BranchInst>(Curr->getTerminator());
+    if (!Term)
+      break;
+    if (isa<ICmpInst>(Term->getCondition()))
+      addInfoForInduction(cast<ICmpInst>(Term->getCondition()), L);
----------------
dtcxzyw wrote:

```suggestion
    if (auto *CmpI = dyn_cast<ICmpInst>(Term->getCondition()))
      addInfoForInduction(CmpI, L);
```


https://github.com/llvm/llvm-project/pull/108031


More information about the llvm-commits mailing list