This is an archive of the discontinued LLVM Phabricator instance.

[MLIR] Fix negative gcd in `normalizeDivisionByGCD` function.
ClosedPublic

Authored by pashu123 on Jan 21 2022, 10:25 AM.

Details

Summary

When the coefficients of dividend are negative, the gcd may be negative
which will change the sign of dividend and overflow denominator.

Diff Detail

Event Timeline

pashu123 created this revision.Jan 21 2022, 10:25 AM
pashu123 requested review of this revision.Jan 21 2022, 10:25 AM
Groverkss added inline comments.Jan 21 2022, 10:13 PM
mlir/lib/Analysis/Presburger/Utils.cpp
40–46

I would prefer taking absolute of dividend[i] here.

Also, this change still does not cover everything properly. gcd inside the loop can be -1 and will not take the return condition when it should have. Taking absolute of dividend[i] should also fix this.

pashu123 updated this revision to Diff 402177.Jan 21 2022, 10:56 PM

Addressing Groverkss comments.

pashu123 marked an inline comment as done.Jan 21 2022, 10:58 PM
pashu123 added inline comments.
mlir/lib/Analysis/Presburger/Utils.cpp
40–46

I see, thanks. I have made the necessary changes.

pashu123 marked an inline comment as done.Jan 21 2022, 10:58 PM
Groverkss accepted this revision.Jan 21 2022, 11:19 PM

LGTM. Thank you for this fix!

This revision is now accepted and ready to land.Jan 21 2022, 11:19 PM