This is an archive of the discontinued LLVM Phabricator instance.

Affine expr simplification for add of const multiple of same expression
ClosedPublic

Authored by bondhugula on Mar 16 2020, 8:53 AM.

Details

Summary
  • Detect "c_1 * expr + c_2 * expr" as (c_1 + c_2) * expr
  • subsumes things like 'expr - expr' and "expr * -1 + expr" as 0.
  • add default null init ctor for AffineConstantExpr

Signed-off-by: Uday Bondhugula <uday@polymagelabs.com>

Diff Detail

Event Timeline

bondhugula created this revision.Mar 16 2020, 8:53 AM
Herald added a project: Restricted Project. · View Herald Transcript

Remove debug code

Harbormaster completed remote builds in B49324: Diff 250578.

LGTM

See: https://github.com/llvm/llvm-project/blob/master/mlir/lib/Dialect/SDBM/SDBMExpr.cpp#L31 in case you like something from there to write such expressions more idiomatically and wish to lift it up.
I am not claiming it is in a final state but you might find it useful.

rriddle accepted this revision.Mar 16 2020, 11:53 AM
rriddle added inline comments.
mlir/include/mlir/IR/AffineExpr.h
191

Can you just add = nullptr to the other constructor?

This revision is now accepted and ready to land.Mar 16 2020, 11:53 AM
bondhugula marked an inline comment as done.Mar 16 2020, 7:31 PM

Thanks for the review.

mlir/include/mlir/IR/AffineExpr.h
191

Sure, done.

Address review comment - AffineConstantExpr ctor

LGTM

See: https://github.com/llvm/llvm-project/blob/master/mlir/lib/Dialect/SDBM/SDBMExpr.cpp#L31 in case you like something from there to write such expressions more idiomatically and wish to lift it up.
I am not claiming it is in a final state but you might find it useful.

Looks good and useful. You may also want to add the operator '/' for floordiv. This would be in general useful to implement some detection at least from under Analysis/. You could just consider moving it to lib/Analysis/Utils so that it's not a dependence on the SDBM dialect. One use case could have been to simplify (x - x floordiv d) as x mod d, but we have this by construction in lib/IR/AffineExpr.cpp. Also, it may be useful to have a way to constrain an AffineExprMatcher to positive constants for example. But this is all meant for "post construction" matching as opposed to simplifying before / by construction itself, right?

This revision was automatically updated to reflect the committed changes.