<div dir="ltr">On Wed, Jul 3, 2013 at 2:08 PM, Rafael Espíndola <span dir="ltr"><<a href="mailto:rafael.espindola@gmail.com" target="_blank">rafael.espindola@gmail.com</a>></span> wrote:<br><div class="gmail_extra"><div class="gmail_quote">
<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">Out of curiosity, what is the problem with the intrinsic?<br>

<div class=""><div class="h5"><br></div></div></blockquote><div><br></div><div>Hi Rafael,</div><div><br></div><div>The way LLVM currently works, except for some very special cases this intrinsic gets lowered to a library call anyway. Since in PNaCl we ship the portable parts of the C library as bitcode embedded in the .pexe, we prefer the libcall to be resolved earlier without generating intrinsics that the code generator has to handle. This helps us decrease the surface of the stable ABI PNaCl has to support. See this thread for more details - <a href="http://lists.cs.uiuc.edu/pipermail/llvmdev/2013-June/063010.html">http://lists.cs.uiuc.edu/pipermail/llvmdev/2013-June/063010.html</a></div>
<div><br></div><div>Eli</div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex">
<div class=""><div class="h5">
On 3 July 2013 15:19, Eli Bendersky <<a href="mailto:eliben@google.com">eliben@google.com</a>> wrote:<br>
> Author: eliben<br>
> Date: Wed Jul  3 14:19:12 2013<br>
> New Revision: 185568<br>
><br>
> URL: <a href="http://llvm.org/viewvc/llvm-project?rev=185568&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=185568&view=rev</a><br>
> Log:<br>
> Add target hook CodeGen queries when generating builtin pow*.<br>
><br>
> Without fmath-errno, Clang currently generates calls to @llvm.pow.* intrinsics<br>
> when it sees pow*(). This may not be suitable for all targets (for<br>
> example le32/PNaCl), so the attached patch adds a target hook that CodeGen<br>
> queries. The target can state its preference for having or not having the<br>
> intrinsic generated. Non-PNaCl behavior remains unchanged;<br>
> PNaCl-specific test added.<br>
><br>
><br>
><br>
> Added:<br>
>     cfe/trunk/test/CodeGen/le32-libcall-pow.c<br>
> Modified:<br>
>     cfe/trunk/lib/CodeGen/CGBuiltin.cpp<br>
>     cfe/trunk/lib/CodeGen/TargetInfo.cpp<br>
>     cfe/trunk/lib/CodeGen/TargetInfo.h<br>
><br>
> Modified: cfe/trunk/lib/CodeGen/CGBuiltin.cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGBuiltin.cpp?rev=185568&r1=185567&r2=185568&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGBuiltin.cpp?rev=185568&r1=185567&r2=185568&view=diff</a><br>

> ==============================================================================<br>
> --- cfe/trunk/lib/CodeGen/CGBuiltin.cpp (original)<br>
> +++ cfe/trunk/lib/CodeGen/CGBuiltin.cpp Wed Jul  3 14:19:12 2013<br>
> @@ -1293,13 +1293,18 @@ RValue CodeGenFunction::EmitBuiltinExpr(<br>
>    case Builtin::BIpow:<br>
>    case Builtin::BIpowf:<br>
>    case Builtin::BIpowl: {<br>
> -    if (!FD->hasAttr<ConstAttr>())<br>
> -      break;<br>
> -    Value *Base = EmitScalarExpr(E->getArg(0));<br>
> -    Value *Exponent = EmitScalarExpr(E->getArg(1));<br>
> -    llvm::Type *ArgType = Base->getType();<br>
> -    Value *F = CGM.getIntrinsic(Intrinsic::pow, ArgType);<br>
> -    return RValue::get(Builder.CreateCall2(F, Base, Exponent));<br>
> +    // Transform a call to pow* into a @llvm.pow.* intrinsic call, but only<br>
> +    // if the target agrees.<br>
> +    if (getTargetHooks().emitIntrinsicForPow()) {<br>
> +      if (!FD->hasAttr<ConstAttr>())<br>
> +        break;<br>
> +      Value *Base = EmitScalarExpr(E->getArg(0));<br>
> +      Value *Exponent = EmitScalarExpr(E->getArg(1));<br>
> +      llvm::Type *ArgType = Base->getType();<br>
> +      Value *F = CGM.getIntrinsic(Intrinsic::pow, ArgType);<br>
> +      return RValue::get(Builder.CreateCall2(F, Base, Exponent));<br>
> +    }<br>
> +    break;<br>
>    }<br>
><br>
>    case Builtin::BIfma:<br>
><br>
> Modified: cfe/trunk/lib/CodeGen/TargetInfo.cpp<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/TargetInfo.cpp?rev=185568&r1=185567&r2=185568&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/TargetInfo.cpp?rev=185568&r1=185567&r2=185568&view=diff</a><br>

> ==============================================================================<br>
> --- cfe/trunk/lib/CodeGen/TargetInfo.cpp (original)<br>
> +++ cfe/trunk/lib/CodeGen/TargetInfo.cpp Wed Jul  3 14:19:12 2013<br>
> @@ -443,6 +443,10 @@ class PNaClTargetCodeGenInfo : public Ta<br>
>   public:<br>
>    PNaClTargetCodeGenInfo(CodeGen::CodeGenTypes &CGT)<br>
>      : TargetCodeGenInfo(new PNaClABIInfo(CGT)) {}<br>
> +<br>
> +  /// For PNaCl we don't want llvm.pow.* intrinsics to be emitted instead<br>
> +  /// of library function calls.<br>
> +  bool emitIntrinsicForPow() const { return false; }<br>
>  };<br>
><br>
>  void PNaClABIInfo::computeInfo(CGFunctionInfo &FI) const {<br>
><br>
> Modified: cfe/trunk/lib/CodeGen/TargetInfo.h<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/TargetInfo.h?rev=185568&r1=185567&r2=185568&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/TargetInfo.h?rev=185568&r1=185567&r2=185568&view=diff</a><br>

> ==============================================================================<br>
> --- cfe/trunk/lib/CodeGen/TargetInfo.h (original)<br>
> +++ cfe/trunk/lib/CodeGen/TargetInfo.h Wed Jul  3 14:19:12 2013<br>
> @@ -74,6 +74,10 @@ namespace clang {<br>
>      ///     through such registers.<br>
>      virtual bool extendPointerWithSExt() const { return false; }<br>
><br>
> +    /// Controls whether BIpow* emit an intrinsic call instead of a library<br>
> +    /// function call.<br>
> +    virtual bool emitIntrinsicForPow() const { return true; }<br>
> +<br>
>      /// Determines the DWARF register number for the stack pointer, for<br>
>      /// exception-handling purposes.  Implements __builtin_dwarf_sp_column.<br>
>      ///<br>
><br>
> Added: cfe/trunk/test/CodeGen/le32-libcall-pow.c<br>
> URL: <a href="http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/le32-libcall-pow.c?rev=185568&view=auto" target="_blank">http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/le32-libcall-pow.c?rev=185568&view=auto</a><br>

> ==============================================================================<br>
> --- cfe/trunk/test/CodeGen/le32-libcall-pow.c (added)<br>
> +++ cfe/trunk/test/CodeGen/le32-libcall-pow.c Wed Jul  3 14:19:12 2013<br>
> @@ -0,0 +1,21 @@<br>
> +// RUN: %clang_cc1 -fmath-errno -emit-llvm -o - %s -triple le32-unknown-nacl | FileCheck %s<br>
> +// RUN: %clang_cc1 -emit-llvm -o - %s -triple le32-unknown-nacl | FileCheck %s<br>
> +<br>
> +// le32 (PNaCl) never generates intrinsics for pow calls, with or without errno<br>
> +<br>
> +// CHECK: define void @test_pow<br>
> +void test_pow(float a0, double a1, long double a2) {<br>
> +  // CHECK: call float @powf<br>
> +  float l0 = powf(a0, a0);<br>
> +<br>
> +  // CHECK: call double @pow<br>
> +  double l1 = pow(a1, a1);<br>
> +<br>
> +  // CHECK: call double @powl<br>
> +  long double l2 = powl(a2, a2);<br>
> +}<br>
> +<br>
> +// CHECK: declare float @powf(float, float)<br>
> +// CHECK: declare double @pow(double, double)<br>
> +// CHECK: declare double @powl(double, double)<br>
> +<br>
><br>
><br>
> _______________________________________________<br>
> cfe-commits mailing list<br>
> <a href="mailto:cfe-commits@cs.uiuc.edu">cfe-commits@cs.uiuc.edu</a><br>
> <a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits</a><br>
</div></div></blockquote></div><br></div></div>