<div dir="ltr">On 6 February 2013 14:43, Owen Anderson <span dir="ltr"><<a href="mailto:resistor@mac.com" target="_blank">resistor@mac.com</a>></span> wrote:<br><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

Author: resistor<br>
Date: Wed Feb  6 16:43:31 2013<br>
New Revision: 174555<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=174555&view=rev" target="_blank">http://llvm.org/viewvc/llvm-project?rev=174555&view=rev</a><br>
Log:<br>
Signficantly generalize our ability to constant fold floating point intrinsics, including ones on half types.<br>
<br>
Added:<br>
    llvm/trunk/test/Transforms/ConstProp/half.ll<br>
Modified:<br>
    llvm/trunk/lib/Analysis/ConstantFolding.cpp<br>
<br>
Modified: llvm/trunk/lib/Analysis/ConstantFolding.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/ConstantFolding.cpp?rev=174555&r1=174554&r2=174555&view=diff" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/ConstantFolding.cpp?rev=174555&r1=174554&r2=174555&view=diff</a><br>


==============================================================================<br>
--- llvm/trunk/lib/Analysis/ConstantFolding.cpp (original)<br>
+++ llvm/trunk/lib/Analysis/ConstantFolding.cpp Wed Feb  6 16:43:31 2013<br>[...]</blockquote><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">@@ -1241,8 +1266,36 @@ llvm::ConstantFoldCall(Function *F, Arra<br>


       /// the host native double versions.  Float versions are not called<br>
       /// directly but for all these it is true (float)(f((double)arg)) ==<br>
       /// f(arg).  Long double not supported yet.<br>
-      double V = Ty->isFloatTy() ? (double)Op->getValueAPF().convertToFloat() :<br>
-                                     Op->getValueAPF().convertToDouble();<br>
+      double V;<br>
+      if (Ty->isFloatTy())<br>
+        V = Op->getValueAPF().convertToFloat();<br>
+      else if (Ty->isDoubleTy())<br>
+        V = Op->getValueAPF().convertToDouble();<br>
+      else {<br>
+        bool unused;<br>
+        APFloat APF = Op->getValueAPF();<br>
+        APF.convert(APFloat::IEEEdouble, APFloat::rmNearestTiesToEven, &unused);<br>
+        V = APF.convertToDouble();<br>
+      }<br>
+<br>
+      switch (F->getIntrinsicID()) {<br>
+        default: break;<br>
+        case Intrinsic::fabs:<br>
+          return ConstantFoldFP(fabs, V, Ty);<br>
+        case Intrinsic::log2:<br>
+          return ConstantFoldFP(log2, V, Ty);<br>
+        case Intrinsic::log:<br>
+          return ConstantFoldFP(log, V, Ty);<br>
+        case Intrinsic::log10:<br>
+          return ConstantFoldFP(log10, V, Ty);<br>
+        case Intrinsic::exp:<br>
+          return ConstantFoldFP(exp, V, Ty);<br>
+        case Intrinsic::exp2:<br>
+          return ConstantFoldFP(exp2, V, Ty);<br>
+        case Intrinsic::floor:<br>
+          return ConstantFoldFP(floor, V, Ty);<br>
+      }<br></blockquote><div><br></div><div style>Owen, could we instead trend in the direction of reducing our dependence on the native system's libm calls? I don't want things which can cause different IR on different host systems. I didn't realize we were even doing this.</div>

<div style><br></div><div style>Nick</div><div style><br></div></div></div></div>