This is an archive of the discontinued LLVM Phabricator instance.

[flang][fir] Added load-store elimination to fir.store
AbandonedPublic

Authored by shraiysh on May 30 2022, 5:16 AM.

Details

Summary

This patch adds canonicalization for fir.store - the store operation is
eliminated when it is right next to a load from the same address.

Diff Detail

Event Timeline

shraiysh created this revision.May 30 2022, 5:16 AM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptMay 30 2022, 5:16 AM
Herald added a subscriber: mehdi_amini. · View Herald Transcript
shraiysh requested review of this revision.May 30 2022, 5:16 AM

Please wait for a review from the FIR team.

I will just make a note in passing that there is a fir-memref-datflow-opt that does some load to store forwarding and store removal in flang/lib/Optimizer/Transforms/MemRefDataFlowOpt.cpp. But that pass is probably not handling the cases here.

Please wait for a review from the FIR team.

Sure. It would be great if you could add some relevant reviewers as I am not aware who should review this except the already added ones.

there is a fir-memref-datflow-opt that does some load to store forwarding and store removal in flang/lib/Optimizer/Transforms/MemRefDataFlowOpt.cpp. But that pass is probably not handling the cases here.

I do not know about them. I will check out what they do, but with the current HEAD, these stores were not getting eliminated - that is correct.

Please wait for a review from the FIR team.

Sure. It would be great if you could add some relevant reviewers as I am not aware who should review this except the already added ones.

Apologies, just saw that you already did! :)

schweitz added a comment.EditedJun 6 2022, 8:42 AM

Kiran makes a good point that there is a strong desire to perform a true mem-to-reg translation on FIR which would eliminate dead stores and register promote memory traffic to stack slots, etc.

It's not clear to me that there is a lot of IR that is simply the back-to-back Op pattern of:

%1 = fir.load %addr
fir.store %1 to %addr
flang/lib/Optimizer/Dialect/FIROps.cpp
3035

This seems like an extremely narrow application of dead-store removal. Does it actually fire all that much?

there is a strong desire to perform a true mem-to-reg translation on FIR

Now that I think about it, this elimination is too special and it would be covered more effectively in a mem2reg kind of pass. Would make more sense to improve that instead of adding it separately. I will abandon this change and maybe work on that later.

shraiysh abandoned this revision.Jun 6 2022, 9:27 AM