<div dir="ltr">Do we use the context instruction to extract fast math flags elsewhere?<div><br></div><div>I wouldn't expect that to be reliably at all. Nothing *requires* the context instruction to be the one governing the semantics.</div><div><br></div><div>I think we need to pass the fast math flags directly into SimplifyBinOp for this to work.</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Jan 29, 2015 at 4:12 PM, Michael Zolotukhin <span dir="ltr"><<a href="mailto:mzolotukhin@apple.com" target="_blank">mzolotukhin@apple.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi,<br>
<br>
Currently InlineCost pass fails to use fast-math flags when analyzing profitability of inlining. Here is a small example to demonstrate that:<br>
<br>
float foo(float *a, float b) {<br>
  float r;<br>
  if (a[1] * b)<br>
    r = a[1]+a[2]/a[3]-a[4]*a[5]+a[6]-a[7]+a[8]*a[9]+<br>
            a[11]+a[12]/a[13]-a[14]*a[15]+a[16]-a[17]+a[18]*a[19]+<br>
            a[21]+a[22]/a[23]-a[24]*a[25]+a[26]-a[27]+a[28]*a[29]+<br>
            a[31]+a[32]/a[33]-a[34]*a[35]+a[36]-a[37]+a[38]*a[39]+<br>
            a[41]+a[42]/a[43]-a[44]*a[45]+a[46]-a[47]+a[48]*a[49]+<br>
            a[51]+a[52]/a[53]-a[54]*a[55]+a[56]-a[57]+a[58]*a[59]+<br>
            a[61]+a[62]/a[63]-a[64]*a[65]+a[66]-a[67]+a[68]*a[69]+<br>
            a[0]*a[0]+b;<br>
  else<br>
    r = 1;<br>
  return r;<br>
}<br>
float boo(float *a) {<br>
  return foo(a, 0.0);<br>
}<br>
<br>
Here inliner can’t figure out that a[1]*b can be folded to 0 if the call is inlined, and decides not to inline.<br>
<br>
That happens because inliner drops fast-math flags in SimplifyBinOp. The attached patch fixes it by looking into the instruction math flags. Does it look good?<br>
<br>
Without patch:<br>
> clang inline.c -O3 -S -Rpass=inline -ffast-math<br>
// Empty output<br>
<br>
With patch:<br>
> clang inline.c -O3 -S -Rpass=inline -ffast-math<br>
inline.c:17:10: remark: foo inlined into boo [-Rpass=inline]<br>
  return foo(a, 0.0);<br>
         ^<br>
<br>
<br><br>
<br>
Thanks,<br>
Michael<br>_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@cs.uiuc.edu">llvm-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br>
<br></blockquote></div><br></div>