This is an archive of the discontinued LLVM Phabricator instance.

[BOLT] Provide generic implementations for isLoad/isStore
ClosedPublic

Authored by jobnoorman on Aug 31 2023, 4:02 AM.

Details

Summary

MCInstrDesc provides the mayLoad and mayStore flags that seem
appropriate to use as a target-independent way to implement isLoad and
isStore.

I believe this is currently good enough to use for the RISC-V target as
well. I've provided a test for this that checks the generated dyno
stats (which seems to be the only thing both isLoad and isStore are
used for).

Diff Detail

Event Timeline

jobnoorman created this revision.Aug 31 2023, 4:02 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 31 2023, 4:02 AM
jobnoorman requested review of this revision.Aug 31 2023, 4:02 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 31 2023, 4:02 AM
yota9 added inline comments.Aug 31 2023, 4:19 AM
bolt/include/bolt/Core/MCPlusBuilder.h
617

I'm not completely sure, but shouldn't we check here that we may not store here? E.g. atomic instructions seems would return both true for store and load and the current logic is designed here to handle load-only instructions. What do you think?

jobnoorman added inline comments.Aug 31 2023, 4:52 AM
bolt/include/bolt/Core/MCPlusBuilder.h
617

Good question. As far as I can tell, this is only used for dyno stats so it should be fine to count these atomics as both loads and stores? This would already happen for the X86 target.

yota9 added inline comments.Aug 31 2023, 5:12 AM
bolt/include/bolt/Core/MCPlusBuilder.h
617

Probably you're right. Also since internal implementations used inside MIB would still do what they intended to do, probably for now it is not a problem. Although I'm not completely sure do we need this extra check for the future or not :) Probably meta team would decide, but in other aspects LGTM, thanks!

maksfb accepted this revision.Aug 31 2023, 10:34 AM
maksfb added inline comments.
bolt/include/bolt/Core/MCPlusBuilder.h
617

The current implementation captures the original intent, i.e. if the instruction modifies the value in memory it should pass both isLoad() and isStore() conditions. However, when we consider predicated instructions, it is not possible to statically tell if the instruction actually loads/stores. I.e. mayLoad/mayStore is a better naming. Please feel free to change.

bolt/test/RISCV/load-store.s
3

nit:

This revision is now accepted and ready to land.Aug 31 2023, 10:34 AM

Use double dashes for llvm-bolt arguments

yota9 added inline comments.Sep 1 2023, 12:11 AM
bolt/include/bolt/Core/MCPlusBuilder.h
617

+1 , I agree that "may" semantics looks much better in this situation :)

This revision was landed with ongoing or failed builds.Sep 1 2023, 12:36 AM
This revision was automatically updated to reflect the committed changes.
jobnoorman added inline comments.Sep 1 2023, 12:37 AM
bolt/include/bolt/Core/MCPlusBuilder.h
617

Agreed, committed the renaming separately in eafe4ee2e8447d7daf4aaeabcfaf8f8854dd9575.