<div dir="ltr">Unless I'm mistaken, the code at the bottom of useDivRem will always create a DIVREM node regardless of whether both results are needed. That's different then what the comment above the function says. All those checks are trying to prevent it from doing that when it would be a bad idea. I think the code might assume that either DIV/REM is supported or DIVREM is supported but not both.<div><div><br></div><div>I think the normal expansion it refers to is to use REM if only remainder is needed. Or DIV if only quotient is needed. Or if both results are needed use a div and a mul+sub to calculate the remainder from the quotient.</div><div><br></div><div>One thought I had is that you might lie to lowering and DAG combine and say that you only support DIVREM. Then during isel select your DIV or MOD instruction if only one of the results of the DIVREM is used. You can't do that with an isel pattern though and would need to implement custom code in your ISelDAGToDAG file.</div><div><br clear="all"><div><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature">~Craig</div></div><br></div></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Fri, May 7, 2021 at 2:01 PM Bagel via llvm-dev <<a href="mailto:llvm-dev@lists.llvm.org">llvm-dev@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">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><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>
</blockquote></div>