编译cos.c
void func() {
double a = __builtin_cos(3.0);
}
使用
clang -S -emit-llvm -c cos.c
我有
define dso_local void @func() {
%1 = alloca double, align 8
%2 = call double @cos(double 3.000000e+00)
store double %2, double* %1, align 8
ret void
}
declare dso_local double @cos(double)
但是我想获取@llvm.fcos.f64
而不是cos
的llvm内部函数@cos
,即生成的代码应该像这样
...
%2 = call double @llvm.fcos.f64(double 3.000000e+00)
...
}
declare double @llvm.cos.f64(double)
如何强制clang
这样做?也许我应该使用另一个函数而不是__builtin_cos
?
答案 0 :(得分:2)
使用-ffast-math
(表示-fno-math-errno
),c -O3
会将__builtin_cos
内联到@llvm.cos.f64
double func(double in) {
double a = __builtin_cos(in);
return a;
}
clang -O3 -ffast-math -emit-llvm
on Godbolt(已删除调试内容)
define dso_local double @_Z4funcd(double) local_unnamed_addr #0 !dbg !7 {
%2 = tail call fast double @llvm.cos.f64(double %0), !dbg !15
ret double %2, !dbg !17
}