Support IRgen of sqrt -> llvm.sqrt, pow -> llvm.pow.
- Define pow[lf]?, sqrt[lf]? as builtins.
- Add -fmath-errno option which binds to LangOptions.MathErrno
- Add new builtin flag Builtin::Context::isConstWithoutErrno for
functions which can be marked as const if errno isn't respected for
math functions. Sema automatically marks these functions as const
when they are defined, if MathErrno=0.
- IRgen uses const attribute on sqrt and pow library functions to
decide if it can use the llvm intrinsic.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@64689 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/test/CodeGen/libcalls.c b/test/CodeGen/libcalls.c
new file mode 100644
index 0000000..9224fe1
--- /dev/null
+++ b/test/CodeGen/libcalls.c
@@ -0,0 +1,22 @@
+// RUN: clang -fmath-errno=1 -emit-llvm -o %t %s &&
+// RUN: grep "declare " %t | count 6 &&
+// RUN: grep "declare " %t | grep "@llvm." | count 1 &&
+// RUN: clang -fmath-errno=0 -emit-llvm -o %t %s &&
+// RUN: grep "declare " %t | count 6 &&
+// RUN: grep "declare " %t | grep -v "@llvm." | count 0
+
+// IRgen only pays attention to const; it should always call llvm for
+// this.
+float sqrtf(float) __attribute__((const));
+
+void test_sqrt(float a0, double a1, long double a2) {
+ float l0 = sqrtf(a0);
+ double l1 = sqrt(a1);
+ long double l2 = sqrtl(a2);
+}
+
+void test_pow(float a0, double a1, long double a2) {
+ float l0 = powf(a0, a0);
+ double l1 = pow(a1, a1);
+ long double l2 = powl(a2, a2);
+}