This is an archive of the discontinued LLVM Phabricator instance.

Support non-constant divisors in affine mod, floordiv, ceildiv lowerings.
ClosedPublic

Authored by Benoit on Dec 14 2022, 6:03 PM.

Details

Summary

The requirement that divisor>0 is not enforced here outside of the
constant case, but how to enforce it? If I understand correctly, it is
UB and while it is nice to be able to deterministically intercept UB,
that isn't always feasible. Hopefully, keeping the existing
enforcement in the constant case is enough.

Earlier in https://reviews.llvm.org/D140043 I thought "hey why is the lowering of affine floordiv missing out on opportunity to generate arith.floordivsi". Now I understand why --- arith.floordivsi being more general (supports RHS<0) and expanding in populateCeilFloorDivExpandOpsPatterns to 2 arith.divsi is a solid reason to keep a custom lowering of affine floordiv directly to arith.divsi.

Diff Detail

Event Timeline

Benoit created this revision.Dec 14 2022, 6:03 PM
Benoit requested review of this revision.Dec 14 2022, 6:03 PM
Benoit retitled this revision from Allow non-constant divisors in affine floordiv, ceildiv. to Support non-constant divisors in affine floordiv, ceildiv lowerings..Dec 14 2022, 6:05 PM
Benoit edited the summary of this revision. (Show Details)Dec 14 2022, 6:09 PM

The changes in general LGTM but I'm worried that some affine analyses/transformations may rely on the assumption that the affine maps are not semi-affine and something else has to be protected/extended. I think having some feedback from @bondhugula in this regard would be great.

Earlier in https://reviews.llvm.org/D140043 I thought "hey why is the lowering of affine floordiv missing out on opportunity to generate arith.floordivsi". Now I understand why --- arith.floordivsi being more general (supports RHS<0) and expanding in populateCeilFloorDivExpandOpsPatterns to 2 arith.divsi is a solid reason to keep a custom lowering of affine floordiv directly to arith.divsi.

If would be great if you could add a quick comment about this rationale to the logic that you modified in D140043 so that we don't try to do the same again in the future :)

Benoit updated this revision to Diff 483593.Dec 16 2022, 10:43 AM
Benoit edited the summary of this revision. (Show Details)

Added mod

Benoit retitled this revision from Support non-constant divisors in affine floordiv, ceildiv lowerings. to Support non-constant divisors in affine mod, floordiv, ceildiv lowerings..Dec 16 2022, 10:44 AM
Benoit updated this revision to Diff 483599.Dec 16 2022, 10:50 AM

added comment

If would be great if you could add a quick comment about this rationale to the logic that you modified in D140043 so that we don't try to do the same again in the future :)

Done.

I've also added the same for mod, as I have needed that one too.

To be clear, I don't believe that this Review is really extending semantics -- semi-affine were in an intermediate state where they were technically legal, just this lowering was generating an error on them... With this diff, I have some end-to-end workloads running happily, so this is useful to me at least.

dcaballe accepted this revision.Dec 16 2022, 2:17 PM

I had a quick look and some utilities are actually checking for this condition as well so I think we are good.

This revision is now accepted and ready to land.Dec 16 2022, 2:17 PM