This is an archive of the discontinued LLVM Phabricator instance.

[mlir][affine] SuperVectorizer only widen ops with valid result types
ClosedPublic

Authored by caojoshua on Apr 5 2023, 9:55 PM.

Diff Detail

Event Timeline

caojoshua created this revision.Apr 5 2023, 9:55 PM
caojoshua added a reviewer: dcaballe.
caojoshua published this revision for review.Apr 5 2023, 9:58 PM
dcaballe requested changes to this revision.Apr 6 2023, 11:20 AM

Thanks for the fix! This sounds like we need a vectorization pre-condition to check that the input loop only has the supported types (e.g., no vector types). I think we should introduce that check before we go into the vectorizeLoopNest/vectorizeLoop methods, because if we bail out and we have already modified part of the input code, we may leave the IR inconsistent. Would you mind moving that check to the runOnOperation method? Thanks!

This revision now requires changes to proceed.Apr 6 2023, 11:20 AM
caojoshua updated this revision to Diff 511861.Apr 8 2023, 1:20 AM

Move checks to isVectorizableLoopBodyWithOpCond()

Thanks for the fix! This sounds like we need a vectorization pre-condition to check that the input loop only has the supported types (e.g., no vector types). I think we should introduce that check before we go into the vectorizeLoopNest/vectorizeLoop methods, because if we bail out and we have already modified part of the input code, we may leave the IR inconsistent. Would you mind moving that check to the runOnOperation method? Thanks!

Yep, get your point. I instead moved the check to isVectorizableLoopBodyWithOpCond(), which seems most appropriate.

ayzhuang added inline comments.Apr 10 2023, 5:19 PM
mlir/lib/Dialect/Affine/Analysis/LoopAnalysis.cpp
282 ↗(On Diff #511861)

Please also check operand types. Could be a vector_store storing some value defined outside of the loop.

caojoshua marked an inline comment as done.Apr 10 2023, 8:48 PM
caojoshua added inline comments.
mlir/lib/Dialect/Affine/Analysis/LoopAnalysis.cpp
282 ↗(On Diff #511861)

Does not look like we can do this, fails a bunch of SuperVectorizer tests. I think what we have here is correct, because we only want to result type to be a valid element type.

For example, in vectorize_1d.mlir, we want to vectorize this load into a vector.transfer_read. Its result type is f32, which is valid vector element type. But its first operand, a memref, is not a valid vector type.

ayzhuang added inline comments.Apr 11 2023, 8:24 AM
mlir/lib/Dialect/Affine/Analysis/LoopAnalysis.cpp
282 ↗(On Diff #511861)

You can do something similar to line 263 for memref type. But if you think the current check is enough, that's fine.

caojoshua marked an inline comment as done.

Verify ops have valid vector types

caojoshua marked an inline comment as done.Apr 11 2023, 11:54 PM
caojoshua added inline comments.
mlir/lib/Dialect/Affine/Analysis/LoopAnalysis.cpp
282 ↗(On Diff #511861)

Thanks, yeah. This caught an issue a new case, where the operands have invalid type but the result is valid. For example, I added a test involving a vector.reduce, where the operand is an invalid type of vector, and the result is a valid type of float.

I think it would be good to have a case where we have:

  • operand of memref with invalid vector type
  • valid result type

I can't think of a scenario. I can add any recommended tests if there are any.

ayzhuang accepted this revision.Apr 12 2023, 9:45 AM

LGTM, thanks!

This revision was not accepted when it landed; it landed in state Needs Review.Apr 12 2023, 10:00 PM
This revision was automatically updated to reflect the committed changes.
caojoshua marked an inline comment as done.