Miguel Iñigo J. Mañalac via llvm-dev
2020-Mar-27 00:56 UTC
[llvm-dev] Instruction selection phase
Hello LLVM-Dev, Attached are: · The DAG after being built · The DAG before the legalization phase The DAG illustrated performs a signed division for type i32. As can be seen, the SDIV node was converted to a series of other nodes (which includes a MULHS node). In the target lowering class of our target, the SDIV has an operation action of custom. Does anybody know where in between the SelectionDAGBuilder and the Legalization phases the SDIV node got converted? I need the SDIV node to stay as an SDIV node until legalization phase (where it will be lowered into a library call). How can this behavior be accomplished? Does the converted series of nodes still perform the expected operation? Thank you very much in advance for your help! Sincerely, Miguel Inigo J. Manalac (1852) JAPANESE: ???????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????????? ENGLISH: This e-mail is intended for the person(s) to which it is addressed. If you have received it by mistake, please notify the sender and delete the received email. In addition, our company shall not assume any responsibility even if it causes any inconvenience, such as loss of mail, inconsistencies, delays, etc., due to the inclusion of computer viruses. -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20200327/7bc9722e/attachment-0001.html> -------------- next part -------------- A non-text attachment was scrubbed... Name: legalize-dags.pdf Type: application/pdf Size: 46606 bytes Desc: legalize-dags.pdf URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20200327/7bc9722e/attachment-0002.pdf> -------------- next part -------------- A non-text attachment was scrubbed... Name: dag-combine1.pdf Type: application/pdf Size: 45602 bytes Desc: dag-combine1.pdf URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20200327/7bc9722e/attachment-0003.pdf>
This transform is done by visitSDIV in DAGCombiner.cpp. Its using a trick to optimize division by constant. The basic idea is to replace it by a multiply by constant and a shift right with a few extra instructions needed to handle signedness correctly. Since division is usually a slow operation turning it into multiplies, shifts, adds, etc. are usually a better option. I believe you can disable this behavior by returning true in an override of TargetLowering::isIntDivCheap in your target. ~Craig On Thu, Mar 26, 2020 at 6:26 PM Miguel Iñigo J. Mañalac via llvm-dev < llvm-dev at lists.llvm.org> wrote:> Hello LLVM-Dev, > > > > Attached are: > > · The DAG after being built > > · The DAG before the legalization phase > > > > The DAG illustrated performs a signed division for type i32. As can be > seen, the SDIV node was converted to a series of other nodes (which > includes a MULHS node). In the target lowering class of our target, the > SDIV has an operation action of custom. Does anybody know where in between > the SelectionDAGBuilder and the Legalization phases the SDIV node got > converted? I need the SDIV node to stay as an SDIV node until legalization > phase (where it will be lowered into a library call). How can this behavior > be accomplished? Does the converted series of nodes still perform the > expected operation? > > > > Thank you very much in advance for your help! > > > > Sincerely, > > Miguel Inigo J. Manalac (1852) > > > JAPANESE: > このメールは、宛先に書かれている方のみに送信することを意図しております。誤ってそれ以外の方に送信された場合は、申し訳ございませんが、送信者までお知らせいただき、受信されたメールを削除していただきますようお願いいたします。また、コンピュータ・ウィルスの混入等によってメールの欠落・不整合・遅滞等が発生し、何らのご不便をおかけすることが生じても弊社はその責任を負いません。 > ENGLISH: This e-mail is intended for the person(s) to which it is > addressed. If you have received it by mistake, please notify the sender and > delete the received email. In addition, our company shall not assume any > responsibility even if it causes any inconvenience, such as loss of mail, > inconsistencies, delays, etc., due to the inclusion of computer viruses. > _______________________________________________ > LLVM Developers mailing list > llvm-dev at lists.llvm.org > https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev >-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20200326/2511b77f/attachment.html>
Miguel Iñigo J. Mañalac via llvm-dev
2020-Mar-27 03:56 UTC
[llvm-dev] Instruction selection phase
Hi Craig, Thank you very much for the help and suggestion! We were able to produce the desired behavior by setting the operation action for SMUL_LOHI and UMUL_LOHI for all integer types to expand (in target lowering class) as these nodes/instructions are not supported by our target. Again, thank you very much for your help!! Cheers, Miguel From: Craig Topper [mailto:craig.topper at gmail.com] Sent: March 27, 2020 9:57 AM To: Miguel Iñigo J. Mañalac Cc: llvm-dev Subject: Re: [llvm-dev] Instruction selection phase This transform is done by visitSDIV in DAGCombiner.cpp. Its using a trick to optimize division by constant. The basic idea is to replace it by a multiply by constant and a shift right with a few extra instructions needed to handle signedness correctly. Since division is usually a slow operation turning it into multiplies, shifts, adds, etc. are usually a better option. I believe you can disable this behavior by returning true in an override of TargetLowering::isIntDivCheap in your target. ~Craig On Thu, Mar 26, 2020 at 6:26 PM Miguel Iñigo J. Mañalac via llvm-dev <llvm-dev at lists.llvm.org<mailto:llvm-dev at lists.llvm.org>> wrote: Hello LLVM-Dev, Attached are: • The DAG after being built • The DAG before the legalization phase The DAG illustrated performs a signed division for type i32. As can be seen, the SDIV node was converted to a series of other nodes (which includes a MULHS node). In the target lowering class of our target, the SDIV has an operation action of custom. Does anybody know where in between the SelectionDAGBuilder and the Legalization phases the SDIV node got converted? I need the SDIV node to stay as an SDIV node until legalization phase (where it will be lowered into a library call). How can this behavior be accomplished? Does the converted series of nodes still perform the expected operation? Thank you very much in advance for your help! Sincerely, Miguel Inigo J. Manalac (1852) JAPANESE: このメールは、宛先に書かれている方のみに送信することを意図しております。誤ってそれ以外の方に送信された場合は、申し訳ございませんが、送信者までお知らせいただき、受信されたメールを削除していただきますようお願いいたします。また、コンピュータ・ウィルスの混入等によってメールの欠落・不整合・遅滞等が発生し、何らのご不便をおかけすることが生じても弊社はその責任を負いません。 ENGLISH: This e-mail is intended for the person(s) to which it is addressed. If you have received it by mistake, please notify the sender and delete the received email. In addition, our company shall not assume any responsibility even if it causes any inconvenience, such as loss of mail, inconsistencies, delays, etc., due to the inclusion of computer viruses. _______________________________________________ LLVM Developers mailing list llvm-dev at lists.llvm.org<mailto:llvm-dev at lists.llvm.org> https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-dev JAPANESE: このメールは、宛先に書かれている方のみに送信することを意図しております。誤ってそれ以外の方に送信された場合は、申し訳ございませんが、送信者までお知らせいただき、受信されたメールを削除していただきますようお願いいたします。また、コンピュータ・ウィルスの混入等によってメールの欠落・不整合・遅滞等が発生し、何らのご不便をおかけすることが生じても弊社はその責任を負いません。 ENGLISH: This e-mail is intended for the person(s) to which it is addressed. If you have received it by mistake, please notify the sender and delete the received email. In addition, our company shall not assume any responsibility even if it causes any inconvenience, such as loss of mail, inconsistencies, delays, etc., due to the inclusion of computer viruses. -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20200327/ba888b08/attachment.html>