This is an archive of the discontinued LLVM Phabricator instance.

[ARM] Remove copies from low overhead phi inductions.
ClosedPublic

Authored by dmgreen on Nov 11 2020, 7:52 AM.

Details

Summary

The phi created in a low overhead loop gets created with a default register class it seems. There are then copied inserted between the low overhead loop pseudo instructions (which produce/consume GPRlr instructions) and the phi holding the induction. This patch removes those as a step towards attempting to make t2LoopDec and t2LoopEnd a single instruction, and appears useful in it's own right as shown in the tests.

Diff Detail

Event Timeline

dmgreen created this revision.Nov 11 2020, 7:52 AM
dmgreen requested review of this revision.Nov 11 2020, 7:52 AM

Getting phis to use the right register class sounds like a good generic change to make. If creating them like that is a pain, how about just moving most of this logic into OptimizePhis?

Yeah this might look a little strange. This was really written for a following patch (D91358), where it was more about trying to create the new instructions without copies, than trying to specifically remove them. We do still need to remove those before the phi, but it seems to make sense to do that all together as we are already needing to check here. I was trying to get as much stuff out of the way as I could beforehand that other patch to simplify it.

I'm not sure about doing it in general. We are replacing a phi that accepts many registers with one that only accepts 1. We are being very careful here that it is OK to do that, but in general that might not always be true.

SjoerdMeijer added inline comments.Dec 7 2020, 4:04 AM
llvm/lib/Target/ARM/MVETPAndVPTOptimisationsPass.cpp
161

How about splitting this up in 2 separate functions: RevertLoopWithCall, and MergeLoopEnd? The latter is not really descriptive anymore if it still revert loops.

183

I do need to ramp up on this again, but it wasn't immediately clear what problem we are solving here.
First, a bit more details here in the comments would help I guess. Second, I am wondering if MIR tests would have been helpful, or if that doesn't add much in addition to the tests that needed changing.

189

nit: perhaps a more descriptive name than OK.

dmgreen updated this revision to Diff 309915.Dec 7 2020, 7:40 AM
dmgreen added inline comments.
llvm/lib/Target/ARM/MVETPAndVPTOptimisationsPass.cpp
161

This is one of those cases where splitting up the patch has caused more trouble than it has helped! I was trying to make the later patch simpler but it has made these ones more confusing as a result.

We don't really need to revert calls here _unless_ we are converting to a t2LoopEndDec. If we do convert, we need to ensure that there is nothing else using LR (so no calls), and that there is no other uses of the induction variable, so all the copies are removed. They are really just parts of converting to a t2LoopEndDec that I was trying to make work on their own, so split them into separate patches.

I've added a comment to the start of the function to explain this (which isn't true quite yet, but will be once the other patches are in). Hopefully that makes it OK? We can still split it out if you think that's better, but there is at least some method to this madness.

SjoerdMeijer accepted this revision.Dec 8 2020, 6:06 AM

Looks like a good change to me, and this looked reasonable:

I'm not sure about doing it in general. We are replacing a phi that accepts many registers with one that only accepts 1. We are being very careful here that it is OK to do that, but in general that might not always be true.

But perhaps wait a day with committing in case @samparker has more ideas/comments about this:

llvm/lib/Target/ARM/MVETPAndVPTOptimisationsPass.cpp
161

Thanks, this makes it a lot better!

llvm/test/CodeGen/Thumb2/LowOverheadLoops/count_dominates_start.mir
128 ↗(On Diff #309915)

Ah, sorry, must have overlooked this MIR test in my first review.

This revision is now accepted and ready to land.Dec 8 2020, 6:06 AM
dmgreen added inline comments.Dec 8 2020, 6:16 AM
llvm/test/CodeGen/Thumb2/LowOverheadLoops/count_dominates_start.mir
128 ↗(On Diff #309915)

This was a new one that serendipitously came in with the rebase.

Thanks for the review.

This revision was automatically updated to reflect the committed changes.