[llvm-dev] DAGCombiner question

Bagel via llvm-dev llvm-dev at lists.llvm.org
Tue May 11 13:40:23 PDT 2021


On 5/8/21 2:10 PM, Craig Topper wrote:
> You should be able do it in the custom emitter. I think you can ask 
> MachineRegisterInfo if the virtual register has any uses.
> 
Yes, that does work.  Thanks.
The problem with the custom emitter approach is that one ends up with
a lot of BuildMI calls that, in a sense, replace what could be done with normal 
patterns.

What I really need, I think, is to be able to put a predicate on the *result* 
register of a pattern that checks if the result is used.  If it isn't used then 
the pattern doesn't match. E.g.:
	[(set GRegs:$div, UsedGRegs:$rem, (sdivrem GRegs:$lhs, GRegs:$rhs))]>;
where UsedGRegs is a predicate that is true if it is a GRegs and it is 
subsequently used.

I supposed no one else has even needed that so either tablegen doesn't deal 
with it or I can't find an example of how to do it.

Thanks again, brian


> On Sat, May 8, 2021 at 11:24 AM Bagel <bagel99 at gmail.com 
> <mailto:bagel99 at gmail.com>> wrote:
> 
>     Thanks.  I had tried the trick of saying I only support DIVREM.  And then I
>     tried doing a custom emitter for them after matching the pattern.  But I
>     couldn't figure out how, in a customer emitter, to check if a MachineInstr
>     Operand is subsequently used:
>     static MachineBasicBlock *emitDIVREM(MachineInstr &MI,
>                                              MachineBasicBlock *BB, unsigned
>     inst) {
>         unsigned DIV = MI.getOperand(0).getReg();
>         unsigned REM = MI.getOperand(1).getReg(); <== how to test if this is used?
> 
>     So what you are saying is that's too late, and I must have the code in the
>     ISelDAGToDAG phase where I can check for REM usage?
> 
>     brian


More information about the llvm-dev mailing list