This is an archive of the discontinued LLVM Phabricator instance.

[Scheduling][ARM] Consistently enable PostRA Machine scheduling
ClosedPublic

Authored by dmgreen on Nov 3 2019, 12:59 PM.

Details

Summary

In the ARM backend, for historical reasons we have only some targets using Machine Scheduling. The rest use the old list scheduler as they are using itinaries and the list scheduler seems to produce better code (and not crash running out of register on v6m codes). So whether to use the MIScheduler or not is checked at runtime from the subtarget features.

This is fine, except for post-ra scheduling. Whether to use the old post-ra list scheduler or the post-ra machine schedule is decided as the pass manager is set up, in arms case from a newly constructed subtarget. Under some situations, like LTO, this won't include the correct cpu so can pick the wrong option. This can have a surprising effect on performance.

To fix that, this patch overrides targetSchedulesPostRAScheduling and addPreSched2 in the ARM backend, adding _both_ post-ra schedulers and picking at runtime which to execute. To pick between the two I've had to add a enablePostRAMachineScheduler() method that normally returns enableMachineScheduler() && enablePostRAScheduler(), which can be overridden to enable just one of PostRAMachineScheduler vs PostRAScheduler.

Diff Detail

Event Timeline

dmgreen created this revision.Nov 3 2019, 12:59 PM
samparker added inline comments.Nov 4 2019, 2:49 AM
llvm/lib/Target/ARM/ARMSubtarget.cpp
389

I know this is the existing logic, but what are we trying to do here with respect to IT blocks? If we're worried about IT blocks, like the comment suggests, shouldn't we be returning isThumb1Only()? Also, if we're in arm mode then we won't have them, but are we still concerned about predicated instructions (I assume not)?

dmgreen marked an inline comment as done.Nov 4 2019, 2:55 AM
dmgreen added inline comments.
llvm/lib/Target/ARM/ARMSubtarget.cpp
389

I think the comment should really say something like "Thumb1 cores are too simple to benefit from scheduling". I'm not sure what it means by IT blocks.

I will change that. I don't think it would be particularly bad thing to do post-ra scheduling on thumb1 cores, it just won't benefit from it either, so we might as well save the compile time.

dmgreen updated this revision to Diff 227680.Nov 4 2019, 3:08 AM

Updated comment

samparker added inline comments.Nov 4 2019, 3:20 AM
llvm/lib/Target/ARM/ARMTargetMachine.cpp
520

nit: opportunity

522

Should we instead still skip this at -O0?

dmgreen updated this revision to Diff 227686.Nov 4 2019, 3:31 AM

Only enable when getOptLevel() != CodeGenOpt::None

This revision is now accepted and ready to land.Nov 4 2019, 3:38 AM
This revision was automatically updated to reflect the committed changes.