<div dir="ltr"><div>Hello,</div><div><br></div><div>I see InstCombine makes assumptions on functions named with C math function names.</div><div><br></div><div>For example it will optimize the following code:</div><div><br></div><div><div style="color:rgb(0,0,0);background-color:rgb(255,255,254);font-family:"Consolas, ""><div><span style="color:rgb(0,0,255)">target</span> <span style="color:rgb(0,0,255)">datalayout</span> = <span style="color:rgb(163,21,21)">"e-m:e-i64:64-f80:128-n8:16:32:64-S128"</span></div><div><span style="color:rgb(0,0,255)">target</span> <span style="color:rgb(0,0,255)">triple</span> = <span style="color:rgb(163,21,21)">"x86_64-unknown-linux-gnu"</span></div><br><div><span style="color:rgb(0,0,255)">define</span> <span style="color:rgb(0,0,255)">dso_local</span> <span style="color:rgb(0,128,128)">double</span> <span style="color:rgb(0,17,136)">@fabs</span>(<span style="color:rgb(0,128,128)">double</span> <span style="color:rgb(0,17,136)">%x</span>) {</div><div>  <span style="color:rgb(0,17,136)">%res</span> = fmul <span style="color:rgb(0,128,128)">double</span> <span style="color:rgb(0,17,136)">%x</span>, <span style="color:rgb(0,17,136)">%x</span></div><div>  ret <span style="color:rgb(0,128,128)">double</span> <span style="color:rgb(0,17,136)">%res</span></div><div>}</div><br><div><span style="color:rgb(0,0,255)">define</span> <span style="color:rgb(0,0,255)">dso_local</span> <span style="color:rgb(0,128,128)">float</span> <span style="color:rgb(0,17,136)">@_Z3foof</span>(<span style="color:rgb(0,128,128)">float</span> <span style="color:rgb(0,17,136)">%x</span>) {</div><div><span style="color:rgb(128,0,0)">entry:</span></div><div>  <span style="color:rgb(0,17,136)">%conv</span> = fpext <span style="color:rgb(0,128,128)">float</span> <span style="color:rgb(0,17,136)">%x</span> <span style="color:rgb(0,0,255)">to</span> <span style="color:rgb(0,128,128)">double</span></div><div>  <span style="color:rgb(0,17,136)">%0</span> = call <span style="color:rgb(0,128,128)">double</span> <span style="color:rgb(0,17,136)">@fabs</span>(<span style="color:rgb(0,128,128)">double</span> <span style="color:rgb(0,17,136)">%conv</span>)</div><div>  <span style="color:rgb(0,17,136)">%conv1</span> = fptrunc <span style="color:rgb(0,128,128)">double</span> <span style="color:rgb(0,17,136)">%0</span> <span style="color:rgb(0,0,255)">to</span> <span style="color:rgb(0,128,128)">float</span></div><div>  ret <span style="color:rgb(0,128,128)">float</span> <span style="color:rgb(0,17,136)">%conv1</span></div><div>}</div></div></div><div><br></div><div>Into the following:</div><div><br></div><div><div style="color:rgb(0,0,0);background-color:rgb(255,255,254);font-family:"Consolas, ""><div><span style="color:rgb(0,128,128)">target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:</span><span style="color:rgb(205,49,49)">64-</span><span style="color:rgb(0,0,255)">S128</span><span style="color:rgb(163,21,21)">"</span></div><div><span style="color:rgb(0,128,128)">target triple =</span> <span style="color:rgb(205,49,49)">"</span><span style="color:rgb(0,0,255)">x86_64</span>-<span style="color:rgb(0,128,128)">unknown</span>-<span style="color:rgb(0,128,128)">linux</span>-<span style="color:rgb(0,128,128)">gnu</span><span style="color:rgb(163,21,21)">"</span></div><br><div><span style="color:rgb(0,0,255)">define</span> <span style="color:rgb(0,128,128)">dso_local</span> <span style="color:rgb(0,128,128)">float</span> <span style="color:rgb(0,128,128)">@_Z3foof</span>(<span style="color:rgb(0,128,128)">float</span> <span style="color:rgb(0,128,128)">%x</span>) {</div><div><span style="color:rgb(0,128,128)">entry:</span></div><div>  <span style="color:rgb(205,49,49)">%</span><span style="color:rgb(0,0,255)">conv1</span> <span style="color:rgb(205,49,49)">=</span> <span style="color:rgb(0,128,128)">call</span> <span style="color:rgb(0,128,128)">float</span> <span style="color:rgb(0,128,128)">@llvm.fabs.f32</span>(<span style="color:rgb(0,128,128)">float</span> <span style="color:rgb(0,128,128)">%x</span>)</div><div>  <span style="color:rgb(0,0,255)">ret</span> <span style="color:rgb(0,128,128)">float</span> <span style="color:rgb(0,128,128)">%conv1</span></div><div>}</div><br><div><span style="color:rgb(0,128,0)">; Function Attrs: nounwind readnone speculatable</span></div><div><span style="color:rgb(0,0,255)">declare</span> <span style="color:rgb(0,128,128)">double</span> <span style="color:rgb(0,128,128)">@llvm.fabs.f64</span>(<span style="color:rgb(0,128,128)">double</span>) <span style="color:rgb(9,134,88)">#0</span></div><br><div><span style="color:rgb(0,128,0)">; Function Attrs: nounwind readnone speculatable</span></div><div><span style="color:rgb(0,0,255)">declare</span> <span style="color:rgb(0,128,128)">float</span> <span style="color:rgb(0,128,128)">@llvm.fabs.f32</span>(<span style="color:rgb(0,128,128)">float</span>) <span style="color:rgb(9,134,88)">#0</span></div><br><div><span style="color:rgb(0,128,128)">attributes #0 =</span> { <span style="color:rgb(0,128,128)">nounwind</span> <span style="color:rgb(0,128,128)">readnone</span> <span style="color:rgb(0,128,128)">speculatable</span> }</div></div><div><br></div><div>It seems to have assumed my @fabs function was the @llvm.fabs.f64 intrinsic.</div><div><br></div><div>Is that correct behavior?</div><div><br></div>-- <br><div dir="ltr" class="gmail_signature" data-smartmail="gmail_signature"><div dir="ltr"><b>Alexandre Isoard</b><br></div></div></div></div>