Nemanja Ivanovic via llvm-dev
2017-Dec-15 14:51 UTC
[llvm-dev] MachineInstr - different treatment of subregs for checking mods and reads
MachineInstr::modifiesRegister() and MachineInstr::readsRegister() seem to disagree on whether to check only the super-reg (reads) or any overlapping register (modifies). I suppose this makes some sense, but I find it confusing and kind of limiting. I would like to implement something along the lines of `MachineInstr::readsAnyOverlappingRegister()` that would have the same semantics other than it would check whether the instruction reads the register, it's super-register or some sub-register. Basically, I would just replace `TRI->isSubRegister(MOReg, Reg)` in a version of `findRegisterUseOperandIdx()`, with `TRI->regsOverlap(MOReg, Reg)`. I think this would accomplish what I'm after. The reason I would find this useful is that I have a pre-emit pass that finds the instruction that defines a register and under certain conditions, I'd be able to remove the defining instruction. But I can't remove it if there's another use of any portion of the register between the def and the use I am considering. -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20171215/6b08a579/attachment.html>
Matthias Braun via llvm-dev
2017-Dec-15 19:48 UTC
[llvm-dev] MachineInstr - different treatment of subregs for checking mods and reads
> On Dec 15, 2017, at 6:51 AM, Nemanja Ivanovic via llvm-dev <llvm-dev at lists.llvm.org> wrote: > > MachineInstr::modifiesRegister() and MachineInstr::readsRegister() seem to disagree on whether to check only the super-reg (reads) or any overlapping register (modifies). > > I suppose this makes some sense, but I find it confusing and kind of limiting. I would like to implement something along the lines of `MachineInstr::readsAnyOverlappingRegister()` that would have the same semantics other than it would check whether the instruction reads the register, it's super-register or some sub-register. > Basically, I would just replace `TRI->isSubRegister(MOReg, Reg)` in a version of `findRegisterUseOperandIdx()`, with `TRI->regsOverlap(MOReg, Reg)`. I think this would accomplish what I'm after. > > The reason I would find this useful is that I have a pre-emit pass that finds the instruction that defines a register and under certain conditions, I'd be able to remove the defining instruction. But I can't remove it if there's another use of any portion of the register between the def and the use I am considering.1) Just write that function as part of your pass. If it turns out to be useful for more than 1 pass, we can move it to MachineInstr. 2) I'm not 100% sure I understand your motivation, but to me it sounds a bit like you are re-implementing some form of liveness check so why not use LiveRegUnits/LivePhysRegs instead? - Matthias