<div dir="ltr"><div>Hello clang devs,<br><br>I'm implementing libm for a toolchain based on LLVM. There is instruction level support for some libm functions that I'd like to target via clang. The IR to machine code part is working so I think the next step is writing C that generates calls to the llvm intrinsics.<br><br></div>For example:<br><div>double sin(double x) { return __builtin_sin(x); }<br><br></div><div>I expected this to compile to:<br>define double @sin(double %x)  {<br>  %res = call double @llvm.sin.f64(double %x)<br></div><div>  ret double %res<br>}<br><br></div><div>Our back end recognises llvm.sin.f64 so this would compile into sensible instructions.<br><br></div><div>However, at -O0 clang generates a call to sin.<br><br>define double @sin(double %x) {<br>  %x.addr = alloca double, align 8<br>  store double %x, double* %x.addr, align 8<br>  %0 = load double, double* %x.addr, align 8<br>  %call = call double @sin(double %0)<br>  ret double %call<br>}<br><br></div><div>At higher optimisations, this recursive call is detected and optimised into:<br>define double @sin(double %x) {<br>entry:<br>  ret double undef<br>}<br><br></div><div>How can I write C that generates a call to the llvm.sin.f64 intrinsic?<br><br></div><div>Cheers,<br><br></div><div>Jon<br></div></div>