This is an archive of the discontinued LLVM Phabricator instance.

[MLIR] MathExtras: support dividing large numbers
AbandonedPublic

Authored by arjunp on Dec 20 2021, 5:09 AM.

Details

Summary

The current implementations of ceilDiv and floorDiv involve multiplying
the operands. This results in an overflow when the operands are large, whereas
one might assume that dividing numbers should not result in overflow unless the
divisor is -1.

Diff Detail

Event Timeline

arjunp created this revision.Dec 20 2021, 5:09 AM
arjunp requested review of this revision.Dec 20 2021, 5:09 AM
arjunp edited the summary of this revision. (Show Details)Dec 20 2021, 5:11 AM
bondhugula accepted this revision.Dec 21 2021, 10:16 AM
bondhugula added inline comments.
mlir/include/mlir/Support/MathExtras.h
27–28

You can double-check if parentheses around the disjunction are needed. Perhaps better with extra parentheses around?

PS: '||' does precede the ternary operator but they are pretty close!

This revision is now accepted and ready to land.Dec 21 2021, 10:16 AM
arjunp updated this revision to Diff 396195.Dec 25 2021, 7:03 AM

Add extra parentheses

arjunp added inline comments.Dec 25 2021, 7:12 AM
mlir/include/mlir/Support/MathExtras.h
27–28

Dropping the parentheses around the disjunction will produce warnings. I added extra parenthesis around the whole condition.

arjunp abandoned this revision.Dec 25 2021, 7:19 AM

Similar patch was already landed. (D116096)