[cfe-commits] r53866 - in /cfe/trunk: include/clang/AST/Builtins.def lib/CodeGen/CGBuiltin.cpp test/CodeGen/builtins-powi.c
Daniel Dunbar
daniel at zuster.org
Mon Jul 21 11:44:42 PDT 2008
Author: ddunbar
Date: Mon Jul 21 13:44:41 2008
New Revision: 53866
URL: http://llvm.org/viewvc/llvm-project?rev=53866&view=rev
Log:
Add __builtin_powi[fl] support
Added:
cfe/trunk/test/CodeGen/builtins-powi.c
Modified:
cfe/trunk/include/clang/AST/Builtins.def
cfe/trunk/lib/CodeGen/CGBuiltin.cpp
Modified: cfe/trunk/include/clang/AST/Builtins.def
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/Builtins.def?rev=53866&r1=53865&r2=53866&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/Builtins.def (original)
+++ cfe/trunk/include/clang/AST/Builtins.def Mon Jul 21 13:44:41 2008
@@ -70,6 +70,9 @@
BUILTIN(__builtin_copysign, "ddd", "ncF")
BUILTIN(__builtin_copysignf, "fff", "ncF")
BUILTIN(__builtin_copysignl, "LdLdLd", "ncF")
+BUILTIN(__builtin_powi , "ddi" , "nc")
+BUILTIN(__builtin_powif, "ffi" , "nc")
+BUILTIN(__builtin_powil, "LdLdi", "nc")
// FP Comparisons.
BUILTIN(__builtin_isgreater , "i.", "nc")
Modified: cfe/trunk/lib/CodeGen/CGBuiltin.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGBuiltin.cpp?rev=53866&r1=53865&r2=53866&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGBuiltin.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGBuiltin.cpp Mon Jul 21 13:44:41 2008
@@ -192,6 +192,7 @@
}
case Builtin::BI__builtin_expect:
+ // FIXME: pass expect through to LLVM
return RValue::get(EmitScalarExpr(E->getArg(0)));
case Builtin::BI__builtin_bswap32:
case Builtin::BI__builtin_bswap64: {
@@ -226,6 +227,19 @@
// Otherwise, call libm 'nan'.
break;
}
+ case Builtin::BI__builtin_powi:
+ case Builtin::BI__builtin_powif:
+ case Builtin::BI__builtin_powil: {
+ Value *Base = EmitScalarExpr(E->getArg(0));
+ Value *Exponent = EmitScalarExpr(E->getArg(1));
+
+ const llvm::Type *ArgType = Base->getType();
+ Value *F = CGM.getIntrinsic(Intrinsic::powi, &ArgType, 1);
+
+ const llvm::Type *ResultType = ConvertType(E->getType());
+ return RValue::get(Builder.CreateCall2(F, Base, Exponent, "tmp"));
+ }
+
case Builtin::BI__builtin_isgreater:
case Builtin::BI__builtin_isgreaterequal:
case Builtin::BI__builtin_isless:
Added: cfe/trunk/test/CodeGen/builtins-powi.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/builtins-powi.c?rev=53866&view=auto
==============================================================================
--- cfe/trunk/test/CodeGen/builtins-powi.c (added)
+++ cfe/trunk/test/CodeGen/builtins-powi.c Mon Jul 21 13:44:41 2008
@@ -0,0 +1,29 @@
+// RUN: clang -emit-llvm -o - %s > %t
+// RUN: ! grep "__builtin" %t
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <math.h>
+
+void test(long double a, int b) {
+ printf("%Lf**%d: %08x %08x %016Lx\n",
+ a, b,
+ __builtin_powi(a, b),
+ __builtin_powif(a, b),
+ __builtin_powil(a, b)
+ );
+}
+
+int main() {
+ int i;
+
+ test(-1,-1LL);
+ test(0,0);
+ test(1,1);
+
+ for (i=0; i<3; i++) {
+ test(random(), i);
+ }
+
+ return 0;
+}
More information about the cfe-commits
mailing list