This is an archive of the discontinued LLVM Phabricator instance.

[MLIR] Add affine.load fold hook on global constant memrefs
ClosedPublic

Authored by bondhugula on Feb 26 2022, 2:16 AM.

Details

Summary

Fold affine.load ops on global constant memrefs when indices are all
constant.

Diff Detail

Event Timeline

bondhugula created this revision.Feb 26 2022, 2:16 AM
bondhugula requested review of this revision.Feb 26 2022, 2:16 AM
nicolasvasilache requested changes to this revision.Feb 28 2022, 6:02 AM
nicolasvasilache added inline comments.
mlir/lib/Dialect/Affine/IR/AffineOps.cpp
2404

Plz invert some conditions and use early exit instead of applying 5-deep nesting.

2410

this would look better as a helper on memref::GlobalOp

This revision now requires changes to proceed.Feb 28 2022, 6:02 AM
bondhugula added inline comments.Mar 2 2022, 4:20 AM
mlir/lib/Dialect/Affine/IR/AffineOps.cpp
2404

I did think of inverting the checks (which would be the normal way); the reason I didn't is that this is a folding hook where the list of conditions may grow (further below this check). Inverting would lead to a reversal when the next folding rule is added.

And you can't invert the inner ones since there isn't a for loop here (there's no early exit).

Fine with inverting though but that would lead to a larger diff on the next change.

2410

Sure.

Herald added a project: Restricted Project. · View Herald TranscriptMar 2 2022, 4:20 AM
bondhugula updated this revision to Diff 412377.Mar 2 2022, 4:38 AM
bondhugula marked an inline comment as done.

Add helper.

bondhugula updated this revision to Diff 412380.Mar 2 2022, 4:50 AM

Adjust accessor and comments.

bondhugula updated this revision to Diff 412381.Mar 2 2022, 4:53 AM

Trim includes.

bondhugula marked an inline comment as done.Mar 2 2022, 4:54 AM
dcaballe added inline comments.Mar 2 2022, 10:10 AM
mlir/test/Dialect/Affine/canonicalize.mlir
1096–1097

Remove DAG? The order in the return should always be the same, right?

bondhugula updated this revision to Diff 412575.Mar 2 2022, 4:52 PM
bondhugula marked an inline comment as done.

Drop unnecessary -DAGs.

mlir/test/Dialect/Affine/canonicalize.mlir
1096–1097

Right. The second set of -DAGs aren't needed.

bondhugula updated this revision to Diff 412914.Mar 3 2022, 8:00 PM

Rebase. Ping @reviewers.

After the most recent rebase, your change to GlobalOp is lost. Please check.

bondhugula updated this revision to Diff 413181.Mar 4 2022, 6:11 PM

Put back lost change.

After the most recent rebase, your change to GlobalOp is lost. Please check.

Thanks very much for spotting that. Restored.

ayzhuang accepted this revision.Mar 7 2022, 10:00 AM

Looks great, thanks!

Rebase. Reduce nesting depth of conditionals - NFC.

This revision was not accepted when it landed; it landed in state Needs Review.Mar 17 2022, 10:59 AM
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.