This is an archive of the discontinued LLVM Phabricator instance.

[MLIR] Enhance folding capability of spirv::CompositeExtractOp::fold
ClosedPublic

Authored by nbpatel on May 25 2023, 11:48 PM.

Details

Summary

This PR improves the spirv::CompositeExtractOp::fold function by adding a backtracking mechanism.
The updated function can now traverse a chain of CompositeInsertOps to find a match.

Diff Detail

Event Timeline

nbpatel created this revision.May 25 2023, 11:48 PM
Herald added a project: Restricted Project. · View Herald Transcript
nbpatel requested review of this revision.May 25 2023, 11:48 PM
kuhar requested changes to this revision.May 26 2023, 7:40 AM
kuhar added a subscriber: kuhar.

This looks fine but could you add a LIT test demonstrating how it works?

This revision now requires changes to proceed.May 26 2023, 7:40 AM
nbpatel updated this revision to Diff 526106.May 26 2023, 10:04 AM

Added a test case

kuhar added inline comments.May 26 2023, 10:18 AM
mlir/lib/Dialect/SPIRV/IR/SPIRVCanonicalization.cpp
146–147

nit: since insertOp is not used outside of the loop, you should be able to reduce the scope like so:

while (auto insertOp = compositeOp.getDefiningOp<spirv::CompositeInsertOp>()) {
   if (getIndices() == insertOp.getIndices())
     return insertOp.getObject();
   compositeOp = insertOp.getComposite();
}
153–154

Would we look through insertions and then look through composite constructs? I think we should be able to resume from compositeOp updated in the loop above.

153–154

*Should

mlir/test/Dialect/SPIRV/Transforms/canonicalize.mlir
199

nit: I think CHECK-NEXT: return .... would work here and we would not have to use CHECK-NOT.

nbpatel updated this revision to Diff 526146.May 26 2023, 11:45 AM

Address Feedback

nbpatel marked 2 inline comments as done.May 26 2023, 11:47 AM
nbpatel added inline comments.
mlir/lib/Dialect/SPIRV/IR/SPIRVCanonicalization.cpp
153–154

not exactly sure what you mean here

kuhar added inline comments.May 26 2023, 11:59 AM
mlir/lib/Dialect/SPIRV/IR/SPIRVCanonicalization.cpp
151

We shouldn't need this since insertOp gets reassigned in the loop condition

153–154

I mean supporting sequences like this:

%a = spirv.CompositeConstruct %0, %1, %2
%b = spirv.CompositeInsert %3, %a[1]
%c = spirv.CompositeInsert %4, %b[2]
%val = spirv.CompositeExtract %c[0]
return %val

==>

return %0
nbpatel updated this revision to Diff 526200.May 26 2023, 2:33 PM

clean up and enchance pattern

nbpatel marked an inline comment as done.May 26 2023, 2:34 PM
nbpatel added inline comments.
mlir/lib/Dialect/SPIRV/IR/SPIRVCanonicalization.cpp
151

ah sorry, my bad, missed to remove that line

153–154

added the changes and a test case

nbpatel marked an inline comment as done.May 26 2023, 2:34 PM
nbpatel marked an inline comment as done.May 26 2023, 2:42 PM

@kuhar not sure why it shows patch application failed. Should I create a revision again?

kuhar accepted this revision.May 26 2023, 3:00 PM

Awesome, thanks for the fixes!

@kuhar not sure why it shows patch application failed. Should I create a revision again?

Can you share some more context? What did you do and where did you see this message? In general, phabricator doesn't require creating new revisions when things go out of sync -- you should be able to rebase and upload an updated diff based on that.

This revision is now accepted and ready to land.May 26 2023, 3:00 PM
nbpatel added a comment.EditedMay 26 2023, 3:32 PM

in the diff details it shows this
"Diff Detail
Build Status
Buildable 234970
Build 363444: pre-merge checks patch application failed"

Do I have to rebase on latest master? I used the gui for creating the PR and revisions, it worked fine until the last revision
Also, can you help merge the patch for me since I dont think I have permission nor do I know how to merge it in upstream llvm repo

kuhar added a comment.May 26 2023, 3:52 PM

in the diff details it shows this
"Diff Detail
Build Status
Buildable 234970
Build 363444: pre-merge checks patch application failed"

Do I have to rebase on latest master? I used the gui for creating the PR and revisions, it worked fine until the last revision
Also, can you help merge the patch for me since I dont think I have permission nor do I know how to merge it in upstream llvm repo

I think it could be that the patch is too far behind for the CI to pick up, and then the fix would be to rebase and upload a new diff.

Sure, I can commit it for you. What name and email would you like to use?

Name : Nishant Patel
Email: nishant.b.patel@intel.com

Thanks @kuhar

kuhar updated this revision to Diff 526218.May 26 2023, 4:19 PM

Rebase.

This revision was landed with ongoing or failed builds.May 26 2023, 4:23 PM
This revision was automatically updated to reflect the committed changes.