diff options
author | Chris Lattner <sabre@nondot.org> | 2010-05-06 05:50:07 +0000 |
---|---|---|
committer | Chris Lattner <sabre@nondot.org> | 2010-05-06 05:50:07 +0000 |
commit | 81368fbfd6d57150f66c993dc9041d62a7a32c4f (patch) | |
tree | ace8fae6a03f19ba4e034f4c53677f419473beaf | |
parent | 420b11850d3f4557421f43f519b59d528329c668 (diff) |
optimize builtin_isnan/isinf to not do an extraneous extension from
float -> double (which happens because they are modelled as int(...)
functions), and add a testcase for isinf.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@103167 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r-- | lib/Sema/SemaChecking.cpp | 15 | ||||
-rw-r--r-- | test/CodeGen/builtins.c | 18 |
2 files changed, 32 insertions, 1 deletions
diff --git a/lib/Sema/SemaChecking.cpp b/lib/Sema/SemaChecking.cpp index 7029711d44..e60dfd3452 100644 --- a/lib/Sema/SemaChecking.cpp +++ b/lib/Sema/SemaChecking.cpp @@ -607,12 +607,25 @@ bool Sema::SemaBuiltinFPClassification(CallExpr *TheCall, unsigned NumArgs) { if (OrigArg->isTypeDependent()) return false; - // This operation requires a floating-point number + // This operation requires a non-_Complex floating-point number. if (!OrigArg->getType()->isRealFloatingType()) return Diag(OrigArg->getLocStart(), diag::err_typecheck_call_invalid_unary_fp) << OrigArg->getType() << OrigArg->getSourceRange(); + // If this is an implicit conversion from float -> double, remove it. + if (ImplicitCastExpr *Cast = dyn_cast<ImplicitCastExpr>(OrigArg)) { + Expr *CastArg = Cast->getSubExpr(); + if (CastArg->getType()->isSpecificBuiltinType(BuiltinType::Float)) { + assert(Cast->getType()->isSpecificBuiltinType(BuiltinType::Double) && + "promotion from float to double is the only expected cast here"); + Cast->setSubExpr(0); + Cast->Destroy(Context); + TheCall->setArg(NumArgs-1, CastArg); + OrigArg = CastArg; + } + } + return false; } diff --git a/test/CodeGen/builtins.c b/test/CodeGen/builtins.c index a4424d7742..e604fbe318 100644 --- a/test/CodeGen/builtins.c +++ b/test/CodeGen/builtins.c @@ -163,3 +163,21 @@ void bar() { } // CHECK: } + + +// CHECK: define void @test_inff +void test_inff(float F, double D, long double LD) { + volatile int res; + res = __builtin_isinf(F); + // CHECK: call float @fabsf(float + // CHECK: fcmp oeq float {{.*}}, 0x7FF0000000000000 + + res = __builtin_isinf(D); + // CHECK: call double @fabs(double + // CHECK: fcmp oeq double {{.*}}, 0x7FF0000000000000 + + res = __builtin_isinf(LD); + // CHECK: call x86_fp80 @fabsl(x86_fp80 + // CHECK: fcmp oeq x86_fp80 {{.*}}, 0xK7FFF8000000000000000 +} + |