mlir icon indicating copy to clipboard operation
mlir copied to clipboard

Consider trip count in loop invariant code motion

Open sherhut opened this issue 6 years ago • 4 comments

The current loop-invariant code motion pass does not consider trip counts when optimizing loops. This should be added to avoid hoisting code out of loops that actually never execute and hence adding additional computation.

The loop-like interface should probably grow a method to query whether a loop has a statically known trip count. For AffineFor, this can be answered using the mlir::getConstantTripCount(AffineForOp forOp) helper.

sherhut avatar Oct 17 '19 13:10 sherhut

I'll be happy to take this. @River707 @joker-eph Could you please assign to me?

bondhugula avatar Oct 17 '19 15:10 bondhugula

Why would we even need to worry about loops that would never execute? Shouldn't these just be DCE'd?

River707 avatar Oct 17 '19 23:10 River707

Why would we even need to worry about loops that would never execute? Shouldn't these just be DCE'd?

Because:

  1. at compile time, it may not be known whether they execute at least once;
  2. at the time LICM is run, it may not be known whether they execute at least once, i.e., the fact that they are dead may arise only after further transformations.

As such, we can't hoist unless the lower bound on the trip count is known to be at least one.

bondhugula avatar Oct 18 '19 03:10 bondhugula

Yep, thanks. I was thinking of something completely different.

On Thu, Oct 17, 2019 at 8:47 PM Uday Bondhugula [email protected] wrote:

Why would we even need to worry about loops that would never execute? Shouldn't these just be DCE'd?

Because:

  1. at compile time, it may not be known whether they execute at least once;
  2. at the time LICM is run, it may not be known whether they execute at least once, i.e., the fact that they are dead may arise only after further transformations.

As such, we can't hoist unless the lower bound on the trip count is known to be at least one.

— You are receiving this because you were mentioned.

Reply to this email directly, view it on GitHub https://github.com/tensorflow/mlir/issues/194?email_source=notifications&email_token=AG37JDLT6FTQZWUZ5XETDTDQPEWVBA5CNFSM4JB2CF62YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEBSN43Y#issuecomment-543481455, or unsubscribe https://github.com/notifications/unsubscribe-auth/AG37JDLEFGERJTAGIRRIBTTQPEWVBANCNFSM4JB2CF6Q .

River707 avatar Oct 18 '19 04:10 River707