This is an archive of the discontinued LLVM Phabricator instance.

MIR-Canon Idempotent Instruction Hoisting.
ClosedPublic

Authored by plotfi on Mar 11 2018, 10:38 AM.

Details

Summary

The following patch contains support for hoisting instructions such as:

%4353:gpr64 = MOVi64imm 4617315517961601024

to the top of the basic block.

These idempotent instructions are sorted alphabetically.

Diff Detail

Repository
rL LLVM

Event Timeline

plotfi created this revision.Mar 11 2018, 10:38 AM
bogner added inline comments.Mar 13 2018, 4:05 PM
lib/CodeGen/MIRCanonicalizerPass.cpp
143–144

Capitalize variable names please (Call them S and OS, maybe).

148–150

Probably easier to understand / slightly more efficient to explicitly flush the stream and just use S, rather than calling str() repeatedly.

211–214

More naming convention.

681

Unused?

682–683

These might need better names. It's very hard to scry what they're for.

686–687

Maybe we should hoist this out of the loop, so it's obvious to readers that it isn't loop dependent? It might make sense to put the whole loop in its own function while we're at it.

689–698

Some comments would make all of this easier to follow

plotfi updated this revision to Diff 138837.Mar 17 2018, 5:07 PM
plotfi marked 7 inline comments as done.
bogner added inline comments.Mar 21 2018, 9:39 AM
lib/CodeGen/MIRCanonicalizerPass.cpp
195–196

for (MachineOperand &MO : II->operands()) ?

670–674

What's the downside of doing this with less than two idempotent instructions? ISTM the simpler implementation of just doing it anyway would have some value.

678–679

I'd probably skip the "gap" variable so it's obvious it's only used once. A named argument comment adds the same clarity: SkipVRegs(/*VRegGapIndex=*/1, MRI, DummyRC)

681–685

It took me a minute to figure out that this was iterating over the first N instructions. Would it be clearer to use I as the loop variable here, like so?

auto MII = MBB.begin();
for (unsigned I = 0; I < PseudoIdempotentInstCount && MII != MBB.end(); ++I) {
  MachineInstr &MI = *MII++;

If you don't think that's better, at least move the initialization of I to right before the loop please.

plotfi updated this revision to Diff 140051.Mar 28 2018, 1:58 AM
plotfi marked an inline comment as done.
plotfi added inline comments.
lib/CodeGen/MIRCanonicalizerPass.cpp
195–196

I wanted to start at operand 1 not 0.

plotfi updated this revision to Diff 140501.Mar 30 2018, 3:34 PM
plotfi marked an inline comment as done.
plotfi marked 4 inline comments as done.
bogner accepted this revision.Mar 30 2018, 3:51 PM

LGTM. Thanks!

This revision is now accepted and ready to land.Mar 30 2018, 3:51 PM
plotfi closed this revision.Apr 9 2018, 9:48 AM