[cfe-commits] r103167 - in /cfe/trunk: lib/Sema/SemaChecking.cpp test/CodeGen/builtins.c

Chris Lattner sabre at nondot.org
Wed May 5 22:50:07 PDT 2010


Author: lattner
Date: Thu May  6 00:50:07 2010
New Revision: 103167

URL: http://llvm.org/viewvc/llvm-project?rev=103167&view=rev
Log:
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.

Modified:
    cfe/trunk/lib/Sema/SemaChecking.cpp
    cfe/trunk/test/CodeGen/builtins.c

Modified: cfe/trunk/lib/Sema/SemaChecking.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaChecking.cpp?rev=103167&r1=103166&r2=103167&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaChecking.cpp (original)
+++ cfe/trunk/lib/Sema/SemaChecking.cpp Thu May  6 00:50:07 2010
@@ -607,12 +607,25 @@
   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;
 }
 

Modified: cfe/trunk/test/CodeGen/builtins.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CodeGen/builtins.c?rev=103167&r1=103166&r2=103167&view=diff
==============================================================================
--- cfe/trunk/test/CodeGen/builtins.c (original)
+++ cfe/trunk/test/CodeGen/builtins.c Thu May  6 00:50:07 2010
@@ -163,3 +163,21 @@
 
 }
 // 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
+}
+





More information about the cfe-commits mailing list