llvm-reduce for MIR

Has anyone thought about extending llvm-reduce to also be able to do reduction on MIR?

The current tool itself seems quite modular and nicely structured with the delta-algorithm separated from the actual IR specific reductions.

When reducing IR instructions (ReduceInstructions.cpp) it just does RAUW undef and then eraseFromParent so in theory it seems it would be possible to do a similar thing for MIR. At least while on SSA form one could either RAUW $noreg or perhaps a dominating definition of the same register class. So maybe it would not be too much work to add a set of MIR specific reducers (at least for MBB and MI) and generalize the remaining part of the tool (module import and verification) to able to handle both IR and MIR.

At least for me manually reducing MIR is quite slow an painful so any automation here would be appreciated.

Of course in general MIR is more constrained that IR so it may be “a bit” more complicated than outlined here, but still seems worth a try.

Any thoughts on this?

-Markus

Hi Markus,

Has anyone thought about extending llvm-reduce to also be able to do reduction on MIR?

Thought about it, yes, doing anything about it, no :).

The current tool itself seems quite modular and nicely structured with the delta-algorithm separated from the actual IR specific reductions.
When reducing IR instructions (ReduceInstructions.cpp) it just does RAUW undef and then eraseFromParent so in theory it seems it would be possible to do a similar thing for MIR. At least while on SSA form one could either RAUW $noreg or perhaps a dominating definition of the same register class. So maybe it would not be too much work to add a set of MIR specific reducers (at least for MBB and MI) and generalize the remaining part of the tool (module import and verification) to able to handle both IR and MIR.

At least for me manually reducing MIR is quite slow an painful so any automation here would be appreciated.

Of course in general MIR is more constrained that IR so it may be “a bit” more complicated than outlined here, but still seems worth a try.

Any thoughts on this?

Having such tool would be super useful!

On a somewhat related note, I built a tool to extract a basic block from MIR (i.e., like llvm-extract but on MIR). I’ve never bothered cleaning it up and open sourcing it, but if there is interest for that I could certainly push that out.

Cheers,
-Quentin

+1, this would be a cool addition to llvm-reduce.

So to report back to this thread.

I went ahead and did something https://reviews.llvm.org/D110527

If anyone is interested feel free to add yourselves as reviewer.

-Markus