This is an archive of the discontinued LLVM Phabricator instance.

[mlir] Vectorize induction variables of loops not mapped to a vector dimension
ClosedPublic

Authored by ayzhuang on Oct 7 2021, 5:13 PM.

Details

Summary
  1. Add support to vectorize induction variables of loops that are not mapped to any vector dimension in SuperVectorize pass.
  2. Fix a bug in getForInductionVarOwner.

Diff Detail

Event Timeline

ayzhuang created this revision.Oct 7 2021, 5:13 PM
ayzhuang requested review of this revision.Oct 7 2021, 5:13 PM
dcaballe requested changes to this revision.Oct 7 2021, 6:09 PM

Thanks for adding support for this missing case, Amy! The implementation looks great! I only think we shouldn't use a special case for uniform IVs, they are just like any other uniform value. I would extend the uniform utilities to support this case instead of adding a new one. More details inline. Other than that, it looks great!

Thanks!
Diego

mlir/lib/Dialect/Affine/Transforms/SuperVectorize.cpp
261

Instead of adding a new bullet, I would extend the previous ones about "Uniform operands". Uniform IVs are just uniform values.

1105

I think this comment wouldn't be necessary. Uniform IVs are just uniform values so they would fall into #3. It just happen that some cases are missing in the uniform check, which is what you are adding here.

1123

I think the vectorizeIV utility shouldn't be needed. We should be able to use vectorizeUniform for this case.

1149

I think we should move this check into isUniformDefinition. There shouldn't be any difference between vectorizing a uniform IV and any other uniform value. Actually, if the IV is outside the vectorize loop(s), it should be hitting that case already (line 1161), right? This extra check would handle uniform IVs inside the vectorized loop(s). Am I missing something here?

mlir/test/Dialect/Affine/SuperVectorize/vectorize_1d.mlir
198

nit: we can drop %{{.*}} =

200

Since you are capturing the IVs, it would interesting to check that the transfer read is actually using the scalar version of the IVs

211–217

Since this is only testing the vectorization of IVs, could we simplify the test and remove all the ops not related to the IVs, including iter_args?

This revision now requires changes to proceed.Oct 7 2021, 6:09 PM
ayzhuang updated this revision to Diff 378332.Oct 8 2021, 12:12 PM
ayzhuang marked 7 inline comments as done.

Address review comments to extend the uniform utilities to support the induction variable vectorization.

mlir/lib/Dialect/Affine/Transforms/SuperVectorize.cpp
1149

Yes, you're right. I have moved this check into isUniformDefinition.

mlir/test/Dialect/Affine/SuperVectorize/vectorize_1d.mlir
200

This transfer read is using the result of affine.apply. I have added checks to see if affine.apply is using the scalar version of the IVs.

dcaballe accepted this revision.Oct 8 2021, 1:13 PM

Thanks, Amy! LGTM. Just a couple of nits. Please, fix them before landing.

mlir/lib/Dialect/Affine/Transforms/SuperVectorize.cpp
1073

nit: you could do loopToVectorDim.count(forOp) == 0

1088–1090

nit: spell out auto, please

This revision is now accepted and ready to land.Oct 8 2021, 1:13 PM
ayzhuang updated this revision to Diff 378351.Oct 8 2021, 2:01 PM
ayzhuang marked 2 inline comments as done.

Address review comments.

@dcaballe Thank you for the review. We'll merge it tomorrow if there are no more comments.

This revision was automatically updated to reflect the committed changes.