[llvm] [VPlan] Don't bail creating interleave group if it has dead members (PR #208415)
Luke Lau via llvm-commits
llvm-commits at lists.llvm.org
Mon Jul 13 00:43:49 PDT 2026
================
@@ -3815,27 +3815,29 @@ void VPlanTransforms::createInterleaveGroups(
// single VPInterleaveRecipe at its insertion point.
VPDominatorTree VPDT(Plan);
for (const auto *IG : InterleaveGroups) {
- // Skip interleave groups where members don't have recipes. This can happen
- // when removeDeadRecipes removes recipes that are part of interleave groups
- // but have no users.
- if (llvm::any_of(IG->members(), [&IRMemberToRecipe](Instruction *Member) {
- return !IRMemberToRecipe.contains(Member);
- }))
+ VPWidenMemoryRecipe *Start = nullptr;
+ Instruction *StartMember = nullptr;
+ for (auto *Member : IG->members())
+ if (VPWidenMemoryRecipe *R = IRMemberToRecipe.lookup(Member)) {
+ StartMember = Member;
+ Start = R;
+ break;
+ }
+ if (!StartMember) // All member recipes are dead, so the group is dead.
continue;
-
- auto *Start = IRMemberToRecipe.lookup(IG->getMember(0));
VPIRMetadata InterleaveMD(*Start);
SmallVector<VPValue *, 4> StoredValues;
- if (auto *StoreR = dyn_cast<VPWidenStoreRecipe>(Start->getAsRecipe()))
- StoredValues.push_back(StoreR->getStoredValue());
- for (unsigned I = 1; I < IG->getFactor(); ++I) {
+ for (unsigned I = 0; I < IG->getFactor(); ++I) {
Instruction *MemberI = IG->getMember(I);
if (!MemberI)
continue;
- VPWidenMemoryRecipe *MemoryR = IRMemberToRecipe.lookup(MemberI);
- if (auto *StoreR = dyn_cast<VPWidenStoreRecipe>(MemoryR->getAsRecipe()))
- StoredValues.push_back(StoreR->getStoredValue());
- InterleaveMD.intersect(*MemoryR);
+ if (VPWidenMemoryRecipe *MemoryR = IRMemberToRecipe.lookup(MemberI)) {
+ if (auto *StoreR = dyn_cast<VPWidenStoreRecipe>(MemoryR->getAsRecipe()))
+ StoredValues.push_back(StoreR->getStoredValue());
+ InterleaveMD.intersect(*MemoryR);
+ } else {
+ InterleaveMD.intersect(VPIRMetadata(*MemberI));
----------------
lukel97 wrote:
Precommitted a test in 52ac228b834d6c9d4698bfd05935f2b9b029a35d, changes in a48c1736f9867fcf62f948ede66523aabc490681.
> If possible, I think it would be good to avoid using the metadata from the IR instruction
We could just also completely drop the metadata if there's a dead member. But its worth noting that `VPInterleaveRecipe::execute` already re-applies the IR instruction metadata:
```
applyMetadata(*NewLoad);
// TODO: Also manage existing metadata using VPIRMetadata.
Group->addMetadata(NewLoad);
```
So maybe it would be good to handle those in tandem in a separate change.
https://github.com/llvm/llvm-project/pull/208415
More information about the llvm-commits
mailing list