<div dir="auto">You should be able do it in the custom emitter. I think you can ask MachineRegisterInfo if the virtual register has any uses.</div><div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sat, May 8, 2021 at 11:24 AM Bagel <<a href="mailto:bagel99@gmail.com">bagel99@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;padding-left:1ex;border-left-color:rgb(204,204,204)">Thanks.  I had tried the trick of saying I only support DIVREM.  And then I <br>
tried doing a custom emitter for them after matching the pattern.  But I <br>
couldn't figure out how, in a customer emitter, to check if a MachineInstr <br>
Operand is subsequently used:<br>
static MachineBasicBlock *emitDIVREM(MachineInstr &MI,<br>
                                        MachineBasicBlock *BB, unsigned inst) {<br>
   unsigned DIV = MI.getOperand(0).getReg();<br>
   unsigned REM = MI.getOperand(1).getReg(); <== how to test if this is used?<br>
<br>
So what you are saying is that's too late, and I must have the code in the <br>
ISelDAGToDAG phase where I can check for REM usage?<br>
<br>
brian<br>
<br>
On 5/7/21 5:40 PM, Craig Topper wrote:<br>
> Unless I'm mistaken, the code at the bottom of useDivRem will always create a <br>
> DIVREM node regardless of whether both results are needed. That's different <br>
> then what the comment above the function says. All those checks are trying to <br>
> prevent it from doing that when it would be a bad idea. I think the code might <br>
> assume that either DIV/REM is supported or DIVREM is supported but not both.<br>
> <br>
> I think the normal expansion it refers to is to use REM if only remainder is <br>
> needed. Or DIV if only quotient is needed. Or if both results are needed use a <br>
> div and a mul+sub to calculate the remainder from the quotient.<br>
> <br>
> One thought I had is that you might lie to lowering and DAG combine and say <br>
> that you only support DIVREM. Then during isel select your DIV or MOD <br>
> instruction if only one of the results of the DIVREM is used. You can't do that <br>
> with an isel pattern though and would need to implement custom code in your <br>
> ISelDAGToDAG file.<br>
> <br>
> ~Craig<br>
> <br>
> <br>
> On Fri, May 7, 2021 at 2:01 PM Bagel via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a> <br>
> <mailto:<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>>> wrote:<br>
> <br>
>     I have a target for which UDIV/SDIV is legal, UMOD/SMOD requires an<br>
>     instruction prefix to a divide instruction, and UDIVMOD/SDIVMOD is the same as<br>
>     UMOD/SMOD.<br>
> <br>
>     In DAGCombiner::useDivRem there is this code:<br>
> <br>
>          // If div is legal, it's better to do the normal expansion<br>
>          unsigned OtherOpcode = 0;<br>
>          if ((Opcode == ISD::SDIV) || (Opcode == ISD::UDIV)) {<br>
>            OtherOpcode = isSigned ? ISD::SREM : ISD::UREM;<br>
>            if (TLI.isOperationLegalOrCustom(Opcode, VT))<br>
>              return SDValue();<br>
>          } else {<br>
>            OtherOpcode = isSigned ? ISD::SDIV : ISD::UDIV;<br>
>            if (TLI.isOperationLegalOrCustom(OtherOpcode, VT))<br>
>              return SDValue();<br>
>          }<br>
> <br>
>     This prevents generation of UDIVMOD/SDIVMOD because UDIV/SDIV is legal.<br>
>     Why is this check made?  An what does "it's better to do the normal expansion"<br>
>     mean?<br>
> <br>
>     Thanks,<br>
>     brian<br>
> <br>
>     _______________________________________________<br>
>     LLVM Developers mailing list<br>
>     <a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a> <mailto:<a href="mailto:llvm-dev@lists.llvm.org" target="_blank">llvm-dev@lists.llvm.org</a>><br>
>     <a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a><br>
>     <<a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev" rel="noreferrer" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev</a>><br>
> <br>
<br>
</blockquote></div></div>-- <br><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature">~Craig</div>