[llvm] [LV] Add initial legality checks for early exit loops with side effects (PR #145663)
Florian Hahn via llvm-commits
llvm-commits at lists.llvm.org
Tue Sep 9 05:32:11 PDT 2025
================
@@ -1813,6 +1840,113 @@ bool LoopVectorizationLegality::isVectorizableEarlyExitLoop() {
"backedge taken count: "
<< *SymbolicMaxBTC << '\n');
UncountableExitingBB = SingleUncountableExitingBlock;
+ UncountableExitWithSideEffects = HasSideEffects;
+ return true;
+}
+
+bool LoopVectorizationLegality::canUncountableExitConditionLoadBeMoved(
+ BasicBlock *ExitingBlock) {
+ LoadInst *CriticalUncountableExitConditionLoad = nullptr;
+
+ // Try to find a load in the critical path for the uncountable exit condition.
+ // This is currently matching about the simplest form we can, expecting
+ // only one in-loop load, the result of which is directly compared against
+ // a loop-invariant value.
+ // FIXME: We're insisting on a single use for now, because otherwise we will
+ // need to make PHI nodes for other users. That can be done once the initial
+ // transform code lands.
+ auto *Br = cast<BranchInst>(ExitingBlock->getTerminator());
+
+ using namespace llvm::PatternMatch;
+ Value *L = nullptr;
+ Value *R = nullptr;
+ if (!match(Br->getCondition(),
+ m_OneUse(m_ICmp(m_OneUse(m_Value(L)), (m_Value(R)))))) {
----------------
fhahn wrote:
I think you should able to match the load directly here using something like below
```suggestion
m_OneUse(m_ICmp(m_Instruction(L, m_OneUse(m_Load(L))), (m_Value(R)))))) {
```
https://github.com/llvm/llvm-project/pull/145663
More information about the llvm-commits
mailing list