@@ -1185,6 +1185,31 @@ static Value vectorizeOperand(Value operand, VectorizationState &state) {
11851185 return nullptr ;
11861186}
11871187
1188+ // / Returns true if any vectorized loop IV drives more than one index.
1189+ static bool isIVMappedToMultipleIndices (
1190+ ArrayRef<Value> indices,
1191+ const DenseMap<Operation *, unsigned > &loopToVectorDim) {
1192+ for (auto &kvp : loopToVectorDim) {
1193+ AffineForOp forOp = cast<AffineForOp>(kvp.first );
1194+ // Find which indices are invariant w.r.t. this loop IV.
1195+ auto invariants =
1196+ affine::getInvariantAccesses (forOp.getInductionVar (), indices);
1197+ // Count how many vary (i.e. are not invariant).
1198+ unsigned nonInvariant = 0 ;
1199+ for (Value idx : indices)
1200+ if (!invariants.count (idx))
1201+ ++nonInvariant;
1202+ // Bail if more than one index varies for this single loop IV.
1203+ if (nonInvariant > 1 ) {
1204+ LLVM_DEBUG (dbgs () << " [early‑vect] Bail out: IV "
1205+ << forOp.getInductionVar () << " drives " << nonInvariant
1206+ << " indices\n " );
1207+ return true ;
1208+ }
1209+ }
1210+ return false ;
1211+ }
1212+
11881213// / Vectorizes an affine load with the vectorization strategy in 'state' by
11891214// / generating a 'vector.transfer_read' op with the proper permutation map
11901215// / inferred from the indices of the load. The new 'vector.transfer_read' is
@@ -1217,21 +1242,9 @@ static Operation *vectorizeAffineLoad(AffineLoadOp loadOp,
12171242 indices.append (mapOperands.begin (), mapOperands.end ());
12181243 }
12191244
1220- for (auto &kvp : state.vecLoopToVecDim ) {
1221- AffineForOp forOp = cast<AffineForOp>(kvp.first );
1222- auto invariants =
1223- affine::getInvariantAccesses (forOp.getInductionVar (), indices);
1224- unsigned nonInvariant = 0 ;
1225- for (Value idx : indices)
1226- if (!invariants.count (idx))
1227- ++nonInvariant;
1228- if (nonInvariant > 1 ) {
1229- LLVM_DEBUG (dbgs () << " \n [early-vect] Bail out: loop IV "
1230- << forOp.getInductionVar () << " drives " << nonInvariant
1231- << " indices (must be ≤1)\n " );
1232- return nullptr ;
1233- }
1234- }
1245+ if (isIVMappedToMultipleIndices (indices, state.vecLoopToVecDim ))
1246+ return nullptr ;
1247+
12351248 // Compute permutation map using the information of new vector loops.
12361249 auto permutationMap = makePermutationMap (state.builder .getInsertionBlock (),
12371250 indices, state.vecLoopToVecDim );
@@ -1277,21 +1290,9 @@ static Operation *vectorizeAffineStore(AffineStoreOp storeOp,
12771290 else
12781291 indices.append (mapOperands.begin (), mapOperands.end ());
12791292
1280- for (auto &kvp : state.vecLoopToVecDim ) {
1281- AffineForOp forOp = cast<AffineForOp>(kvp.first );
1282- auto invariants =
1283- affine::getInvariantAccesses (forOp.getInductionVar (), indices);
1284- unsigned nonInvariant = 0 ;
1285- for (Value idx : indices)
1286- if (!invariants.count (idx))
1287- ++nonInvariant;
1288- if (nonInvariant > 1 ) {
1289- LLVM_DEBUG (dbgs () << " \n [early-vect] Bail out: loop IV "
1290- << forOp.getInductionVar () << " drives " << nonInvariant
1291- << " indices (must be ≤1)\n " );
1292- return nullptr ;
1293- }
1294- }
1293+ if (isIVMappedToMultipleIndices (indices, state.vecLoopToVecDim ))
1294+ return nullptr ;
1295+
12951296 // Compute permutation map using the information of new vector loops.
12961297 auto permutationMap = makePermutationMap (state.builder .getInsertionBlock (),
12971298 indices, state.vecLoopToVecDim );
0 commit comments