[llvm] [LoopVectorize] Enable vectorisation of early exit loops with live-outs (PR #120567)
David Sherwood via llvm-commits
llvm-commits at lists.llvm.org
Wed Jan 22 01:55:10 PST 2025
================
@@ -9086,19 +9092,38 @@ addUsersInExitBlocks(VPlan &Plan,
if (Op->isLiveIn())
continue;
- // Currently only live-ins can be used by exit values from blocks not
- // exiting via the vector latch through to the middle block.
- if (ExitIRI->getParent()->getSinglePredecessor() != MiddleVPBB)
- return false;
-
LLVMContext &Ctx = ExitIRI->getInstruction().getContext();
- VPValue *Ext = B.createNaryOp(VPInstruction::ExtractFromEnd,
- {Op, Plan.getOrAddLiveIn(ConstantInt::get(
- IntegerType::get(Ctx, 32), 1))});
+ VPValue *Ext;
+ VPBasicBlock *PredVPBB =
+ cast<VPBasicBlock>(ExitIRI->getParent()->getPredecessors()[Idx]);
----------------
david-arm wrote:
I am specifically worried about this code, which I always seem to trip over during a rebase:
```
void VPIRInstruction::execute(VPTransformState &State) {
assert((isa<PHINode>(&I) || getNumOperands() == 0) &&
"Only PHINodes can have extra operands");
for (const auto &[Idx, Op] : enumerate(operands())) {
```
which specifically assumes:
1. The number of operands exactly matches the number of predecessors, and
2. The operands are added in exactly the same order as the order of predecessors.
Anything in the code that breaks these assumptions also breaks early exit loops. By splitting out the code to deal with live-outs in handleUncountableEarlyExit I am worried that we have break 2.
https://github.com/llvm/llvm-project/pull/120567
More information about the llvm-commits
mailing list