]> granicus.if.org Git - clang/commitdiff
always try to fold a builtin before emitting it. In the future
authorChris Lattner <sabre@nondot.org>
Mon, 6 Oct 2008 06:56:41 +0000 (06:56 +0000)
committerChris Lattner <sabre@nondot.org>
Mon, 6 Oct 2008 06:56:41 +0000 (06:56 +0000)
it is possible that a builtin could sometimes be folded (e.g. __builtin_clz)
if it's operand is a constant.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@57161 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CGBuiltin.cpp

index 99a3463a22197ad56c3e36167b3e802e7cfdf7da..fc7cc027104654808a63a1478a6f89f08270fa6d 100644 (file)
@@ -37,30 +37,17 @@ static RValue EmitBinaryAtomic(CodeGenFunction& CFG,
 }
 
 RValue CodeGenFunction::EmitBuiltinExpr(unsigned BuiltinID, const CallExpr *E) {
-  switch (BuiltinID) {
-  default: break;  // Handle intrinsics and libm functions below.
-      
-  case Builtin::BI__builtin_huge_val:
-  case Builtin::BI__builtin_huge_valf:
-  case Builtin::BI__builtin_huge_vall:
-  case Builtin::BI__builtin_inf:
-  case Builtin::BI__builtin_inff:
-  case Builtin::BI__builtin_infl:
-  case Builtin::BI__builtin_nan:
-  case Builtin::BI__builtin_nanf:
-  case Builtin::BI__builtin_nanl:
-  case Builtin::BI__builtin_classify_type:
-  case Builtin::BI__builtin_constant_p: {
-    APValue Result;
-    if (!E->tryEvaluate(Result, CGM.getContext()))
-      break;  // Not a constant, expand below.
-    
+  // See if we can constant fold this builtin.  If so, don't emit it at all.
+  APValue Result;
+  if (E->tryEvaluate(Result, CGM.getContext())) {
     if (Result.isInt())
       return RValue::get(llvm::ConstantInt::get(Result.getInt()));
     assert(Result.isFloat() && "Unsupported constant type");
     return RValue::get(llvm::ConstantFP::get(Result.getFloat()));
   }
       
+  switch (BuiltinID) {
+  default: break;  // Handle intrinsics and libm functions below.
   case Builtin::BI__builtin___CFStringMakeConstantString: {
     const Expr *Arg = E->getArg(0);