<html>
  <head>
    <meta content="text/html; charset=ISO-8859-1"
      http-equiv="Content-Type">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    <div class="moz-cite-prefix">sin/cos on Intel is an x87 FPU
      instruction, but it looks like LLVM is generating SSE code
      instead, which relies on a library function for sin/cos/pow/etc.<br>
      <br>
      <pre class="moz-signature" cols="72">Richard Mitton
<a class="moz-txt-link-abbreviated" href="mailto:richard@codersnotes.com">richard@codersnotes.com</a></pre>
      On 09/19/2013 01:57 AM, Taco H. in den Bosch wrote:<br>
    </div>
    <blockquote cite="mid:40c93b0c$777fdb05$161358c4$@heddesit.nl"
      type="cite"><span style="font-family: Tahoma, Geneva, sans-serif;
        font-size: 10pt">Hi Andrew,
        <div><br>
        </div>
        <div>this sounded a plausible explanation, because the X86
          processor does not have an instruction to calculate the power
          function.</div>
        <div><br>
        </div>
        <div>So I tried the llvm.sin.f32 intrinsic, as the X86 processor
          family does have an instruction for that, but I still get the
          same problem. While you may still be right, there is at least
          something else going on as well.<br>
          <br>
          Thanks for your input, though.</div>
        <div><br>
        </div>
        <div>Taco.<br>
          <br>
          <span style="font-family: tahoma,arial,sans-serif; font-size:
            10pt;">
            <hr size="2" width="100%" align="center"><b>From</b>:
            "Andrew MacPherson" <a class="moz-txt-link-rfc2396E" href="mailto:andrew.macp@gmail.com"><andrew.macp@gmail.com></a><br>
            <b>Sent</b>: Thursday, September 19, 2013 10:36 AM<br>
            <b>To</b>: <a class="moz-txt-link-abbreviated" href="mailto:taco@heddesit.nl">taco@heddesit.nl</a><br>
            <b>Cc</b>: <a class="moz-txt-link-abbreviated" href="mailto:llvmdev@cs.uiuc.edu">llvmdev@cs.uiuc.edu</a><br>
            <b>Subject</b>: Re: [LLVMdev] JIT compiled intrinsics calls
            is call to null pointer</span><br>
          <br>
          <div dir="ltr">
            <div>
              <div>Hi Taco,<br>
                <br>
              </div>
              We had a similar issue where a math intrinsic was being
              converted to a call to null and it turned out to be
              because the system didn't support the CPU instructions for
              the operation so the intrinsic used a call to the library
              function (pow in your case). However because we weren't
              expecting this math function to be looked up by MCJIT in
              our JITMemoryManager::getPointerToNamedFunction() we
              weren't making it available and it was returning null.<br>
              <br>
            </div>
            Not sure if this is relevant to your case but maybe it'll
            help point you in the right direction.<br>
            <br>
            Cheers,<br>
            Andrew<br>
          </div>
          <div class="gmail_extra"><br>
            <br>
            <div class="gmail_quote">On Wed, Sep 18, 2013 at 8:32 AM,
              Taco H. in den Bosch <span dir="ltr"><<a
                  moz-do-not-send="true" href="mailto:taco@heddesit.nl"
                  target="_blank">taco@heddesit.nl</a>></span> wrote:<br>
              <blockquote class="gmail_quote" style="margin:0 0 0
                .8ex;border-left:1px #ccc solid;padding-left:1ex"><span
style="font-family:Tahoma,Geneva,sans-serif;font-size:10pt"><br>
                  <font face="Arial, Verdana">Hi everyone,</font>
                  <div
style="font-family:Arial,Verdana;font-size:10pt;font-style:normal;font-variant:normal;font-weight:normal;line-height:normal"></div>
                  <div
style="font-family:Arial,Verdana;font-size:10pt;font-style:normal;font-variant:normal;font-weight:normal;line-height:normal"><br>
                  </div>
                  <div
style="font-family:Arial,Verdana;font-size:10pt;font-style:normal;font-variant:normal;font-weight:normal;line-height:normal">I
                    am trying to call an LLVM intrinsic (llvm.pow.f32),
                    inserted with the following call:</div>
                  <div
style="font-family:Arial,Verdana;font-size:10pt;font-style:normal;font-variant:normal;font-weight:normal;line-height:normal"><br>
                  </div>
                  <div
style="font-family:Arial,Verdana;font-size:10pt;font-style:normal;font-variant:normal;font-weight:normal;line-height:normal">
                    <div>std::vector<llvm::Type *> arg_types;</div>
                    <div>arg_types.push_back(llvm::Type::getFloatTy(context));</div>
                    <div><span style="font-size:10pt">auto
                        function=llvm::Intrinsic::getDeclaration(module,
                        llvm::Intrinsic::pow, arg_types);</span></div>
                  </div>
                  <div><font face="Arial, Verdana">auto
                      result=ir_builder->CreateCall(function, args);</font></div>
                  <div><font face="Arial, Verdana"><br>
                    </font></div>
                  <div><font face="Arial, Verdana">When I try to execute
                      the code generated by the JIT compiler, I see that
                      the intrinsic is not compiled into a math
                      coprocessor instruction, but in a call to a null
                      address:</font></div>
                  <div><font face="Arial, Verdana"><br>
                    </font></div>
                  <div><font face="Arial, Verdana">002300B8  sub        
                      esp,8 </font></div>
                  <div><font face="Arial, Verdana">
                      <div>002300BB  movss       xmm0,dword ptr
                        ds:[2300B0h]  </div>
                      <div>
                        002300C3  movss       dword ptr [esp+4],xmm0  </div>
                      <div>002300C9  movss       xmm0,dword ptr
                        ds:[2300B4h]  </div>
                      <div>002300D1  movss       dword ptr [esp],xmm0  </div>
                      <div>002300D6  <span
                          style="background-color:rgb(255,255,0)">call  
                               00000000</span>  </div>
                      <div>002300DB  add         esp,8  </div>
                      <div>002300DE  ret </div>
                    </font></div>
                  <div><font face="Arial, Verdana"><br>
                    </font></div>
                  <div><font face="Arial, Verdana">Is there anything
                      special that I need to do in order to be able to
                      call intrinsics, either in general or when
                      JITting? I am either doing something wrong, or
                      forgetting to do something, but I don't know what.</font></div>
                  <div><font face="Arial, Verdana"><br>
                    </font></div>
                  <div><font face="Arial, Verdana">I am working with a
                      Visual Studio compiled version on Windows (x86).</font></div>
                  <div><font face="Arial, Verdana"><br>
                    </font></div>
                  <div><span
                      style="font-family:Arial,Verdana;font-size:small">All
                      hints will be appreciated, with kind regards,</span></div>
                  <div><span
                      style="font-family:Arial,Verdana;font-size:small"><br>
                    </span></div>
                  <div><span
                      style="font-family:Arial,Verdana;font-size:small">Taco
                      H. in den Bosch.</span></div>
                  <div><span
                      style="font-family:Arial,Verdana;font-size:small"><br>
                    </span></div>
                  <div
style="font-family:Arial,Verdana;font-size:10pt;font-style:normal;font-variant:normal;font-weight:normal;line-height:normal"><br>
                  </div>
                  <div
style="font-family:Arial,Verdana;font-size:10pt;font-style:normal;font-variant:normal;font-weight:normal;line-height:normal"><br>
                  </div>
                  <div
style="font-family:Arial,Verdana;font-size:10pt;font-style:normal;font-variant:normal;font-weight:normal;line-height:normal"><br>
                  </div>
                </span>
                <br>
                _______________________________________________<br>
                LLVM Developers mailing list<br>
                <a moz-do-not-send="true"
                  href="mailto:LLVMdev@cs.uiuc.edu">LLVMdev@cs.uiuc.edu</a>
                        <a moz-do-not-send="true"
                  href="http://llvm.cs.uiuc.edu" target="_blank">http://llvm.cs.uiuc.edu</a><br>
                <a moz-do-not-send="true"
                  href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev"
                  target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a><br>
                <br>
              </blockquote>
            </div>
            <br>
          </div>
          <br>
        </div>
      </span>
      <br>
      <fieldset class="mimeAttachmentHeader"></fieldset>
      <br>
      <pre wrap="">_______________________________________________
LLVM Developers mailing list
<a class="moz-txt-link-abbreviated" href="mailto:LLVMdev@cs.uiuc.edu">LLVMdev@cs.uiuc.edu</a>         <a class="moz-txt-link-freetext" href="http://llvm.cs.uiuc.edu">http://llvm.cs.uiuc.edu</a>
<a class="moz-txt-link-freetext" href="http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev">http://lists.cs.uiuc.edu/mailman/listinfo/llvmdev</a>
</pre>
    </blockquote>
    <br>
  </body>
</html>