diff options
-rw-r--r-- | lib/CodeGen/CGBuiltin.cpp | 15 | ||||
-rw-r--r-- | lib/CodeGen/TargetInfo.cpp | 4 | ||||
-rw-r--r-- | lib/CodeGen/TargetInfo.h | 4 | ||||
-rw-r--r-- | test/CodeGen/le32-libcall-pow.c | 21 | ||||
-rw-r--r-- | test/CodeGen/libcalls.c | 15 |
5 files changed, 47 insertions, 12 deletions
diff --git a/lib/CodeGen/CGBuiltin.cpp b/lib/CodeGen/CGBuiltin.cpp index 7f1709e10f..0d5be26a5e 100644 --- a/lib/CodeGen/CGBuiltin.cpp +++ b/lib/CodeGen/CGBuiltin.cpp @@ -1293,10 +1293,17 @@ RValue CodeGenFunction::EmitBuiltinExpr(const FunctionDecl *FD, case Builtin::BIpow: case Builtin::BIpowf: case Builtin::BIpowl: { - // LOCALMOD: For PNACl we don't want pow* calls to ever turn into - // intrinsics. We want them to be resolved vs. the newlib implementation - // within the pexe during bitcode linking. - // TODO(eliben): upstream this + // Transform a call to pow* into a @llvm.pow.* intrinsic call, but only + // if the target agrees. + if (getTargetHooks().emitIntrinsicForPow()) { + if (!FD->hasAttr<ConstAttr>()) + break; + Value *Base = EmitScalarExpr(E->getArg(0)); + Value *Exponent = EmitScalarExpr(E->getArg(1)); + llvm::Type *ArgType = Base->getType(); + Value *F = CGM.getIntrinsic(Intrinsic::pow, ArgType); + return RValue::get(Builder.CreateCall2(F, Base, Exponent)); + } break; } diff --git a/lib/CodeGen/TargetInfo.cpp b/lib/CodeGen/TargetInfo.cpp index b870ae9eb1..6ca2910d79 100644 --- a/lib/CodeGen/TargetInfo.cpp +++ b/lib/CodeGen/TargetInfo.cpp @@ -416,6 +416,10 @@ class PNaClTargetCodeGenInfo : public TargetCodeGenInfo { public: PNaClTargetCodeGenInfo(CodeGen::CodeGenTypes &CGT) : TargetCodeGenInfo(new PNaClABIInfo(CGT)) {} + + /// For PNaCl we don't want llvm.pow.* intrinsics to be emitted instead + /// of library function calls. + bool emitIntrinsicForPow() const { return false; } }; void PNaClABIInfo::computeInfo(CGFunctionInfo &FI) const { diff --git a/lib/CodeGen/TargetInfo.h b/lib/CodeGen/TargetInfo.h index bb50ce69e3..a682c183f0 100644 --- a/lib/CodeGen/TargetInfo.h +++ b/lib/CodeGen/TargetInfo.h @@ -73,6 +73,10 @@ namespace clang { /// through such registers. virtual bool extendPointerWithSExt() const { return false; } + /// Controls whether BIpow* emit an intrinsic call instead of a library + /// function call. + virtual bool emitIntrinsicForPow() const { return true; } + /// Determines the DWARF register number for the stack pointer, for /// exception-handling purposes. Implements __builtin_dwarf_sp_column. /// diff --git a/test/CodeGen/le32-libcall-pow.c b/test/CodeGen/le32-libcall-pow.c new file mode 100644 index 0000000000..c2f892c3ae --- /dev/null +++ b/test/CodeGen/le32-libcall-pow.c @@ -0,0 +1,21 @@ +// RUN: %clang_cc1 -fmath-errno -emit-llvm -o - %s -triple le32-unknown-nacl | FileCheck %s +// RUN: %clang_cc1 -emit-llvm -o - %s -triple le32-unknown-nacl | FileCheck %s + +// le32 (PNaCl) never generates intrinsics for pow calls, with or without errno + +// CHECK: define void @test_pow +void test_pow(float a0, double a1, long double a2) { + // CHECK: call float @powf + float l0 = powf(a0, a0); + + // CHECK: call double @pow + double l1 = pow(a1, a1); + + // CHECK: call double @powl + long double l2 = powl(a2, a2); +} + +// CHECK: declare float @powf(float, float) +// CHECK: declare double @pow(double, double) +// CHECK: declare double @powl(double, double) + diff --git a/test/CodeGen/libcalls.c b/test/CodeGen/libcalls.c index 87e0592337..8f8e18226a 100644 --- a/test/CodeGen/libcalls.c +++ b/test/CodeGen/libcalls.c @@ -31,27 +31,25 @@ void test_sqrt(float a0, double a1, long double a2) { // CHECK-YES: define void @test_pow // CHECK-NO: define void @test_pow void test_pow(float a0, double a1, long double a2) { - // LOCALMOD: for PNaCl we generate lib calls and not intrinsics, even without - // errno. For more details see the LOCALMOD in lib/CodeGen/CGBuiltin.cpp // CHECK-YES: call float @powf - // CHECK-NO: call float @powf + // CHECK-NO: call float @llvm.pow.f32 float l0 = powf(a0, a0); // CHECK-YES: call double @pow - // CHECK-NO: call double @pow + // CHECK-NO: call double @llvm.pow.f64 double l1 = pow(a1, a1); // CHECK-YES: call x86_fp80 @powl - // CHECK-NO: call x86_fp80 @powl + // CHECK-NO: call x86_fp80 @llvm.pow.f80 long double l2 = powl(a2, a2); } // CHECK-YES: declare float @powf(float, float) // CHECK-YES: declare double @pow(double, double) // CHECK-YES: declare x86_fp80 @powl(x86_fp80, x86_fp80) -// CHECK-NO: declare float @powf(float, float) -// CHECK-NO: declare double @pow(double, double) -// CHECK-NO: declare x86_fp80 @powl(x86_fp80, x86_fp80) +// CHECK-NO: declare float @llvm.pow.f32(float, float) [[NUW_RO:#[0-9]+]] +// CHECK-NO: declare double @llvm.pow.f64(double, double) [[NUW_RO]] +// CHECK-NO: declare x86_fp80 @llvm.pow.f80(x86_fp80, x86_fp80) [[NUW_RO]] // CHECK-YES: define void @test_fma // CHECK-NO: define void @test_fma @@ -124,3 +122,4 @@ void test_builtins(double d, float f, long double ld) { // CHECK-YES: attributes [[NUW_RN]] = { nounwind readnone } // CHECK-NO: attributes [[NUW_RN]] = { nounwind readnone{{.*}} } +// CHECK-NO: attributes [[NUW_RO]] = { nounwind readonly } |