@@ -3131,6 +3131,9 @@ static bool isConsecutiveInterleaveGroup(VPInterleaveRecipe *InterleaveR,
3131
3131
GroupSize == VectorRegWidth;
3132
3132
}
3133
3133
3134
+ // / Returns true if \p VPValue is a narrow VPValue.
3135
+ static bool isAlreadyNarrow (VPValue *VPV) { return VPV->isLiveIn (); }
3136
+
3134
3137
void VPlanTransforms::narrowInterleaveGroups (VPlan &Plan, ElementCount VF,
3135
3138
unsigned VectorRegWidth) {
3136
3139
using namespace llvm ::VPlanPatternMatch;
@@ -3182,6 +3185,16 @@ void VPlanTransforms::narrowInterleaveGroups(VPlan &Plan, ElementCount VF,
3182
3185
if (InterleaveR->getStoredValues ().empty ())
3183
3186
continue ;
3184
3187
3188
+ // Narrow interleave groups, if all operands are already matching narrow
3189
+ // ops.
3190
+ auto *Member0 = InterleaveR->getStoredValues ()[0 ];
3191
+ if (isAlreadyNarrow (Member0) &&
3192
+ all_of (InterleaveR->getStoredValues (),
3193
+ [Member0](VPValue *VPV) { return Member0 == VPV; })) {
3194
+ StoreGroups.push_back (InterleaveR);
3195
+ continue ;
3196
+ }
3197
+
3185
3198
// For now, we only support full interleave groups storing load interleave
3186
3199
// groups.
3187
3200
if (all_of (enumerate(InterleaveR->getStoredValues ()), [](auto Op) {
@@ -3252,13 +3265,16 @@ void VPlanTransforms::narrowInterleaveGroups(VPlan &Plan, ElementCount VF,
3252
3265
// Narrow operation tree rooted at store groups.
3253
3266
for (auto *StoreGroup : StoreGroups) {
3254
3267
VPValue *Res = nullptr ;
3255
- if (auto *WideMember0 = dyn_cast<VPWidenRecipe>(
3256
- StoreGroup->getStoredValues ()[0 ]->getDefiningRecipe ())) {
3268
+ VPValue *Member0 = StoreGroup->getStoredValues ()[0 ];
3269
+ if (isAlreadyNarrow (Member0)) {
3270
+ Res = Member0;
3271
+ } else if (auto *WideMember0 =
3272
+ dyn_cast<VPWidenRecipe>(Member0->getDefiningRecipe ())) {
3257
3273
for (unsigned Idx = 0 , E = WideMember0->getNumOperands (); Idx != E; ++Idx)
3258
3274
WideMember0->setOperand (Idx, NarrowOp (WideMember0->getOperand (Idx)));
3259
3275
Res = WideMember0;
3260
3276
} else {
3261
- Res = NarrowOp (StoreGroup-> getStoredValues ()[ 0 ] );
3277
+ Res = NarrowOp (Member0 );
3262
3278
}
3263
3279
3264
3280
auto *S = new VPWidenStoreRecipe (
0 commit comments