This is an archive of the discontinued LLVM Phabricator instance.

[ARM] Mark MVE loads/store as not having side effects
ClosedPublic

Authored by dmgreen on Jan 21 2020, 9:25 AM.

Details

Summary

The hasSideEffect parameter is usually automatically inferred from instruction patters. For some of our MVE instructions, we do not have patterns though, such as for the pre/post inc loads and stores. This instead specifies the flag manually on the base MVE_VLDRSTR_base tablegen class, making sure we get this correct.

This can help with scheduling multiple loads more optimally. Here I've added a unittest as a more direct form of testing.

Diff Detail

Event Timeline

dmgreen created this revision.Jan 21 2020, 9:25 AM
Herald added a project: Restricted Project. · View Herald TranscriptJan 21 2020, 9:25 AM

Why isn't this handled properly by the scheduling infrastructure instead? This sounds a bit like a hack...

Why isn't this handled properly by the scheduling infrastructure instead? This sounds a bit like a hack...

Sorry Dave, I misread the title! My post-coffee question is, why do we attach SideEffects to patterns and not instruction descriptions anyway?

why do we attach SideEffects to patterns and not instruction descriptions anyway?

I think the point is that a lot of patterns naturally come with information that indicates whether they have various kinds of side effect. If you write a pattern that describes what your instruction does in terms of standard LLVM IR (or rather SDNodes, but the principle's the same), then LLVM can work out for itself (based on its knowledge of those SDNodes' semantics) whether the instruction can load memory, store memory, or do anything else potentially weird, and therefore the Tablegen backend propagates that information from the pattern into the instruction to save you having to write it down again in the instruction definition.

So you only need to manually fill in flags like this if Tablegen can't work it out automatically – if your instruction is selected by C++ isel code, or generated from a target-specific SDNode that Tablegen doesn't know enough about, or inserted post-isel by some totally other phase, etc.

We've been gradually adding isel patterns for a lot of MVE instructions over the past few months, and one of the effects has been that the hasSideEffects flags have been turning from ? into well defined values.

Yep, what Simon said. For normal non-post/pre inc MVE loads we already get this correct. The load is marked as not having sideeffects as it is inferred from the pattern in the same way as any other instruction would be. But for Pre/Post inc loads, we do not have patterns as they have two outputs, so are lowered via dag2dag.

simon_tatham added a comment.EditedJan 22 2020, 1:49 AM

Anyway: should this not also apply to writeback gather/scatter instructions, like MVE_VLDRWU32_qi_pre? Those also have two outputs, so they're selected by C++ code, and as far as I can see their hasSideEffects flags are still stuck on ? at the moment.

dmgreen updated this revision to Diff 239534.Jan 22 2020, 3:54 AM

Yes... Gather loads should probably be in here too. I was just worried about exactly what the mayLoad would mean for an instruction that can load multiple chunks of data from around memory. I think it should be fine though. And, um, I might have accidentally added them without adding the testing. MVE_VLDRSTR_base is the base class of both.

I've included the interleaving loads too VLDn/VSTn, and added tests for all of them.

The other option would be to mark all MVE instructions as not having side effects at the top level, in MVE_MI (other than VCTP, which is specifically marked as having side effects). That's more of a change than I would like to make right here though.

simon_tatham accepted this revision.Jan 22 2020, 4:04 AM
This revision is now accepted and ready to land.Jan 22 2020, 4:04 AM
This revision was automatically updated to reflect the committed changes.