This is an archive of the discontinued LLVM Phabricator instance.

[MachineLICM] Let targets decide to hoist cheap instructions
Needs ReviewPublic

Authored by dmgreen on Mar 11 2020, 1:39 PM.

Details

Summary

MachineLICM can hoist instructions out of loop, but will chooses not to do so for Cheap instructions, including all COPY instructions. Under Cortex-M cpus, where there isn't really a big difference between a MOV and any other instruction, we should really hoist these out of loops, even if they increase the immediate register pressure. MachineLICM will still test if the register pressure limit has been reached, but this puts a shouldHoistCheapInsts target hook in for hoisting instructions that wouldn't otherwise be.

This is especially true for MVE code where we sink VDUP's into blocks attempting to fold them into register variants of vector instructions. Where this scalar is a float value we are left with a COPY from SPR to GPR which needs to be hoisted. Other than that this did not seem to cause a lot of changes.

Diff Detail

Event Timeline

dmgreen created this revision.Mar 11 2020, 1:39 PM
Herald added a project: Restricted Project. · View Herald TranscriptMar 11 2020, 1:39 PM

I'm not sure what, exactly, is specific to Cortex-M here. Copies between int and SIMD registers aren't really cheaper on other CPUs, relatively speaking. I don't really like adding a new target hook without a better justification for why Cortex-M is different from other targets; having target-specific codepaths is going to make it harder for anyone to make improvements here in the future.

Maybe we should revisit the assumption that copies are cheap, in MachineLICMBase::IsCheapInstruction? Or maybe we should revisit the assumption that we should avoid hoisting cheap instructions?

I'm not sure what, exactly, is specific to Cortex-M here. Copies between int and SIMD registers aren't really cheaper on other CPUs, relatively speaking. I don't really like adding a new target hook without a better justification for why Cortex-M is different from other targets; having target-specific codepaths is going to make it harder for anyone to make improvements here in the future.

Good point about cross copies. I was really thinking that _any_ instruction on Cortex-M isn't really much cheaper than any other (with some obvious exceptions for divisions and the like). That's different from many CPU's where movs become essentially free.

Maybe we should revisit the assumption that copies are cheap, in MachineLICMBase::IsCheapInstruction? Or maybe we should revisit the assumption that we should avoid hoisting cheap instructions?

I've tried some alternatives and put together D76135. Let me know what you think, or if anything else would be preferable.

asbirlea removed a subscriber: asbirlea.Mar 13 2020, 2:34 PM

The approach in D76135 makes more sense, I think.