This is an archive of the discontinued LLVM Phabricator instance.

[MLIR] Generalize detecting mods during slice computing
ClosedPublic

Authored by vinayaka-polymage on Jun 20 2021, 8:53 PM.

Details

Summary

During slice computation of affine loop fusion, detect one id as the mod
of another id w.r.t a constant in a more generic way. Restrictions on
co-efficients of the ids is removed. Also, information from the
previously calculated ids is used for simplification of affine
expressions, e.g.,

If id1 = id2,

`id_n - divisor * id_q - id_r + id1 - id2 = 0`, is simplified to:
`id_n - divisor * id_q - id_r = 0`.

If c is a non-zero integer,

`c*id_n - c*divisor * id_q - c*id_r = 0`, is simplified to:
`id_n - divisor * id_q - id_r = 0`.

Diff Detail

Event Timeline

vinayaka-polymage requested review of this revision.Jun 20 2021, 8:53 PM
Herald added a project: Restricted Project. · View Herald TranscriptJun 20 2021, 8:53 PM
bondhugula accepted this revision.Jun 21 2021, 6:31 PM

LGTM - nice improvement and covers a useful case.

This revision is now accepted and ready to land.Jun 21 2021, 6:31 PM

We can wait till tomorrow morning IST for any new comments.

ayzhuang accepted this revision.Jun 22 2021, 1:03 PM

Looks great! Thanks.

This revision was automatically updated to reflect the committed changes.
sgrechanik added inline comments.
mlir/lib/Analysis/AffineStructures.cpp
1538

@vinayaka-polymage There is probably a bug here: dimExpr.getPosition() can't be used to index into positions of the original constraints because it has the range [offset; offset + num) removed in getSliceBounds. I think quotientPosition should be used instead (and I guess this needs quotiontCount == 1 to work).
Also I think we need to check the lower bound as well (that it is >= 0).

mlir/lib/Analysis/AffineStructures.cpp
1538

Thanks for pointing this out @sgrechanik . Sorry, for a long delay in reply here.

I might have incorrectly used getPosition() as you mentioned - I will check these in detail and make the necessary fixes.