This is an archive of the discontinued LLVM Phabricator instance.

[ARM][LowOverheadLoops] Add checks for narrowing
ClosedPublic

Authored by samparker on Mar 16 2020, 10:14 AM.

Details

Summary

Modify ValidateLiveOuts to track 'FalseZeros' more precisely, including checks on specific operations that can generate non-zeros from zero values, e.g VMVN. We can then check that any instructions that retain some information in their output register (all narrowing instructions) that they only use and def registers that always have zeros in their falsely predicated bytes, whether or not tail predication happens.
Most of the logic remains the same, just the names of the data structures and helpers have been renamed to reflect the change in logic. The key change, apart from the opcode checkers, is that the FalseZeros set now strictly contains only instructions which will always generate zeros, and not instructions that could also have their false bytes masked away later.

Diff Detail

Event Timeline

samparker created this revision.Mar 16 2020, 10:14 AM
SjoerdMeijer added inline comments.Mar 18 2020, 1:54 AM
llvm/lib/Target/ARM/ARMLowOverheadLoops.cpp
521

This is becoming a very tricky pass (if it wasn't already that), for a bunch of different reason: the analysis, the transformations, etc. To keep things readable, I am now going to nitpick on comments. I believe there is one school of thought that code should be self-documenting, and comments will always be out of date or misleading, which I think I can mostly agree with. But here in this case, this function, that checks certain opcodes and returning true/false to a function named canGenerateNonZeros doesn't tell me much. So my request is here is if you can define what exactly canGenerateNonZeros mean, and why these opcodes.

538

Same request here: what is retainsPreviousValue, and why these opcodes?

583

Same here

588

Probably this comment describes the function's purpose, so can be moved up.

samparker marked 2 inline comments as done.Mar 19 2020, 2:20 AM
samparker added inline comments.
llvm/lib/Target/ARM/ARMLowOverheadLoops.cpp
521

Fair! Here, any MVE instruction that could generate a non-zero result given nothing but zero'd registers should be listed. This allows us to track zeros in means zeros out.

538

All these instructions operate upon half a lane of the source register, writing to the destination, but they also leave the other half of the destination register untouched. The reference manual uses this sentence: 'The other half of the destination vector element retains its previous value'.

SjoerdMeijer added inline comments.Mar 19 2020, 3:21 AM
llvm/lib/Target/ARM/ARMLowOverheadLoops.cpp
521

Thanks, makes sense. If you can later add this as comments, that would be much appreciated. I am now going to do a second pass over this patch, let things sink in, and continue the review.

I am now up to date with this, and don't have any questions about the logic, that looks good.
I would like to go over it once more when (some of) the nits have been addressed as I would like to get an overview how things read and look as this introduces quite a few new things and concepts.

llvm/lib/Target/ARM/ARMLowOverheadLoops.cpp
538

Thanks for pointing this out.

Just a nit/suggestion for the function name then:
retainsPreviousValue -> laneRetainsPreviousValue

A few questions about the list below. Is this list meant to be complete? From looking at the ArmARM a bit more for this behaviour, it looks like there are more, the first search result e.g. showed VQMOVN. Are we for example not interested in this one? Also curious if it would be worth describing this property in a different way, or if this switch will do.

583

nit: perhaps something along the lines of: alwaysZero -> laneAlwaysZero

617

nit: bytes -> lanes?

625

nit: KnownFalseZeros -> Predicated?

629

nit: perhaps something with "lane" in it:

  • AlwaysFalseLaneZero, or
  • FalseLaneZero, or
  • FalsePredLaneZero
samparker marked an inline comment as done.Mar 23 2020, 1:59 AM
samparker added inline comments.
llvm/lib/Target/ARM/ARMLowOverheadLoops.cpp
538

It is supposed to be complete, so thanks! Which also reminds me that there's no tests for any movn either!

samparker updated this revision to Diff 252044.Mar 23 2020, 8:03 AM
  • Added/moved some comments.
  • Renamed variables/functions.
  • Added/removed tests.
SjoerdMeijer accepted this revision.Mar 23 2020, 12:18 PM

Cheers, looks good to me.

llvm/lib/Target/ARM/ARMLowOverheadLoops.cpp
547

nit: retainsPreviousHalf -> retainsPreviousHalfElement

550

nit, just:

return Flags & ARMII::RetainsPreviousHalfElement;
This revision is now accepted and ready to land.Mar 23 2020, 12:18 PM
This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptMar 24 2020, 2:08 AM