[llvm-branch-commits] [llvm-branch] r93502 - /llvm/branches/Apple/Zoidberg/lib/Analysis/InlineCost.cpp

Eric Christopher echristo at apple.com
Thu Jan 14 18:35:39 PST 2010


Author: echristo
Date: Thu Jan 14 20:35:39 2010
New Revision: 93502

URL: http://llvm.org/viewvc/llvm-project?rev=93502&view=rev
Log:
Merge mine and Evan's inline cost patches from mainline.

Merging revisions: 93448 and 93453.

Modified:
    llvm/branches/Apple/Zoidberg/lib/Analysis/InlineCost.cpp

Modified: llvm/branches/Apple/Zoidberg/lib/Analysis/InlineCost.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/branches/Apple/Zoidberg/lib/Analysis/InlineCost.cpp?rev=93502&r1=93501&r2=93502&view=diff

==============================================================================
--- llvm/branches/Apple/Zoidberg/lib/Analysis/InlineCost.cpp (original)
+++ llvm/branches/Apple/Zoidberg/lib/Analysis/InlineCost.cpp Thu Jan 14 20:35:39 2010
@@ -102,6 +102,32 @@
   return Reduction;
 }
 
+// callIsSmall - If a call will lower to a single selection DAG node, or
+// is otherwise deemed small return true.
+// TODO: Perhaps calls like memcpy, strcpy, etc?
+static bool callIsSmall(const Function *F) {
+  if (F && !F->hasLocalLinkage() && F->hasName()) {
+    StringRef Name = F->getName();
+    
+    // These will all likely lower to a single selection DAG node.
+    if (Name == "copysign" || Name == "copysignf" ||
+        Name == "fabs" || Name == "fabsf" || Name == "fabsl" ||
+        Name == "sin" || Name == "sinf" || Name == "sinl" ||
+        Name == "cos" || Name == "cosf" || Name == "cosl" ||
+        Name == "sqrt" || Name == "sqrtf" || Name == "sqrtl" )
+      return true;
+    
+    // These are all likely to be optimized into something smaller.
+    if (Name == "pow" || Name == "powf" || Name == "powl" ||
+        Name == "exp2" || Name == "exp2l" || Name == "exp2f" ||
+        Name == "floor" || Name == "floorf" || Name == "ceil" ||
+        Name == "round" || Name == "ffs" || Name == "ffsl" ||
+        Name == "abs" || Name == "labs" || Name == "llabs")
+      return true;
+  }
+  return false;
+}
+
 /// analyzeBasicBlock - Fill in the current structure with information gleaned
 /// from the specified block.
 void CodeMetrics::analyzeBasicBlock(const BasicBlock *BB) {
@@ -129,7 +155,7 @@
 
       // Calls often compile into many machine instructions.  Bump up their
       // cost to reflect this.
-      if (!isa<IntrinsicInst>(II))
+      if (!isa<IntrinsicInst>(II) && !callIsSmall(CS.getCalledFunction()))
         NumInsts += InlineConstants::CallPenalty;
     }
     
@@ -141,11 +167,16 @@
     if (isa<ExtractElementInst>(II) || isa<VectorType>(II->getType()))
       ++NumVectorInsts; 
     
-    // Noop casts, including ptr <-> int,  don't count.
     if (const CastInst *CI = dyn_cast<CastInst>(II)) {
+      // Noop casts, including ptr <-> int,  don't count.
       if (CI->isLosslessCast() || isa<IntToPtrInst>(CI) || 
           isa<PtrToIntInst>(CI))
         continue;
+      // Result of a cmp instruction is often extended (to be used by other
+      // cmp instructions, logical or return instructions). These are usually
+      // nop on most sane targets.
+      if (isa<CmpInst>(CI->getOperand(0)))
+        continue;
     } else if (const GetElementPtrInst *GEPI = dyn_cast<GetElementPtrInst>(II)){
       // If a GEP has all constant indices, it will probably be folded with
       // a load/store.





More information about the llvm-branch-commits mailing list