This is an archive of the discontinued LLVM Phabricator instance.

[ARM] Limit v6m unrolling with multiple live outs
ClosedPublic

Authored by dmgreen on Jun 21 2021, 11:12 AM.

Details

Summary

v6m cores only have a limited number of registers available. Unrolling can mean we spend more on stack spills and reloads than we save from the unrolling. This patch adds an extra heuristic to puts a limit on unroll count for loops with multiple live out values, as measured from the LCSSA phi nodes.

Diff Detail

Event Timeline

dmgreen created this revision.Jun 21 2021, 11:12 AM
dmgreen requested review of this revision.Jun 21 2021, 11:12 AM
Herald added a project: Restricted Project. · View Herald TranscriptJun 21 2021, 11:12 AM
SjoerdMeijer added inline comments.Jun 22 2021, 3:19 AM
llvm/lib/Target/ARM/ARMTargetTransformInfo.cpp
2195–2196

In the long run, all of this should be being learnt by a machine.

:-)

2209

I was wondering if this is right. I.e., we are not e.g. accumulating the exit values, or taking a maximum, or something like that, if I am not mistaken.

dmgreen added inline comments.Jun 22 2021, 6:37 AM
llvm/lib/Target/ARM/ARMTargetTransformInfo.cpp
2209

I would expect that most loops have a single exit, but the code above does allow (at most) 2 exit.

From those I took the maximum of the number of liveouts as a rough heuristic, as I would expect the liveouts to be the same in many cases for multi-exit loops, and it probably doesn't want to count them twice.

SjoerdMeijer added inline comments.Jun 22 2021, 6:52 AM
llvm/lib/Target/ARM/ARMTargetTransformInfo.cpp
2209

Ah yes, I now see:

if (ExitingBlocks.size() > 2)
  return;

above and also that the maximum is taken, thanks.

llvm/test/Transforms/LoopUnroll/ARM/v6munroll.ll
53

One nit/question about the test case then, would it be useful to have a test and loop with 2 exit blocks?

dmgreen updated this revision to Diff 353718.Jun 22 2021, 11:09 AM

Added a test with multiple exits (which was a bit hard to get past other profitability checks).

SjoerdMeijer accepted this revision.Jun 23 2021, 6:28 AM

Thanks! And this heuristic looks sensible to me, so LGTM.

This revision is now accepted and ready to land.Jun 23 2021, 6:28 AM
This revision was automatically updated to reflect the committed changes.